Retailers generally suffer at times of rising inflation. Like other companies, they face higher costs for things like electricity or running an office or warehouse. But even worse, higher inflation weighs on their customers' buying power.

So you may wonder whether now is really the right time to buy shares of Costco (COST 1.15%). The warehouse retail giant has outperformed the S&P 500 this year -- but the stock still has lost about 13%. And the most recent sales report showed a slowdown. Let's take a closer look before deciding whether to go for this stock right now.

Profit from membership fees

First, a bit about Costco's business model. Costco doesn't make most of its profit by selling items in its warehouses. It actually relies on selling memberships. To shop at Costco, you have to sign up for a membership that will cost you either $60 for the basic version or $120 for the executive level. So, Costco is guaranteed a certain level of income before you even make a single shopping trip.

Now you might wonder why someone would pay to shop -- especially during difficult economic times. That's because Costco's dirt cheap prices on everything from food to gasoline make the annual fee worthwhile. Costco generally sells in bulk, so it can price items low.

During times of rising inflation, shoppers' wallets may be hurting, but they still need to buy the basics. This means tough economic times actually could be a time when people favor shopping at Costco.

Of course, Costco still may see a slowdown in revenue growth due to sluggishness in sales of discretionary items. In the October report, net sales increased 7.7%. That's down from double-digit increases in the previous months.

It's possible the upcoming holiday season will offer Costco a lift. People probably will be looking for value when they shop for holiday dinner necessities and gifts -- and they'll find it at Costco.

All of this means Costco is well positioned to successfully navigate today's tough times, even if the company doesn't maintain a double-digit growth rate.

Costco's track record

Now, let's look at the long-term picture. Even in better economic times, shoppers love bargains. And Costco's track record reflects that. Over time, the company has increased earnings, return on invested capital, and free cash flow.

COST Revenue (Annual) Chart

COST Revenue (Annual) data by YCharts

In the most recent earnings report, Costco spoke about an important point: membership renewal rates. Worldwide renewal rates at the end of the 2022 fiscal year topped 90%. And executive memberships account for more than 44% of members and nearly 72% of Costco's global sales.

This means people keep coming back to Costco, they're willing to go for a higher-level membership, and these high-level memberships are driving sales. These points are reason to be confident about Costco's growth prospects into the future.

So it looks like Costco is a great stock to buy no matter what the economy is doing. But what about valuation? Today, the stock is trading at 33 times forward earnings estimates. That's down from more than 45 earlier this year.

Costco trades at a premium compared to retailers like Walmart or Target. But Costco's membership model, member retention rate, and track record make it worth the price. That's why right now is a great time to buy this retailer -- and hold on for the long term.