Many stocks took a hit along with the broader market in September, but Costco Wholesale (COST 1.01%) shareholders eluded that fate. The warehouse retailer's stock is up 22% compared to the 12% increase in the S&P 500 so far this year.

On one hand, that rally has pushed Costco's shares further into premium-valuation territory, potentially limiting investors' returns from here. On the other hand, the stock's jump reflects the company's recession-resistant business and its formidable competitive advantages. The value of these assets becomes clearer when worries are spiking about slowing consumer-spending trends.

Investors considering Costco stock right now have to weigh those opposing factors against each other when determining whether to add the successful retailer to their portfolios.

Positive growth trends

There's certainly a lot of good news to consider on Costco's operating and financial momentum. Sales trends improved in the most recent quarter, and they looked even stronger in the company's latest monthly-sales update. Comparable-store sales in September accelerated to a 3% increase in the core U.S. market (from flat) and to 4.5% overall (from 1.1 %).

Costco has enjoyed strong customer traffic through the latest consumer-spending slowdown, partly thanks to its focus on selling essential products like groceries. Yet that success is offset by the chain's exposure to consumer-discretionary products.

Its e-commerce segment, which sells a high proportion of items like home furnishings and consumer electronics, grew at a 4% rate in September compared to a 1% decline in the prior full quarter. The stock's rally in recent weeks can be attributed at least in part to this improving growth profile.

Safety through the storm

Costco stock is also appealing for its relative safety. Sure, no retailer would be immune from the negative impacts of a recession should one develop over the next few quarters. But this warehouse giant gets most of its earnings from subscription fees rather than merchandise sales. A record 93% of subscribers are renewing those memberships, indicating excellent customer loyalty.

And earnings should be pushed higher by the next round of membership-fee increases that's due sometime soon. It has been over six years since the last fee hike, and those tend to occur about every five or six years. Management said in a recent conference call that it is simply a matter of timing as to when the next fee boost will occur.

The price check

The biggest risk in purchasing this high-performing business is paying too high of a price. That's certainly a valid concern for prospective investors. Costco stock is valued at 39 times earnings compared to Walmart's price-to-earings ratio of 30.

There's a similar premium reflected in the price-to-sales ratio. Costco stock costs 1 times annual revenue, while you could own Walmart for 0.67 times sales.

Some of that premium is well-deserved, reflecting Costco's stable sales and earnings prospects at a volatile time in the retailing industry. But there's no question that the retailer is expensive compared to many national retailing peers.

Whether you find that premium worthwhile will depend on if you prefer lower risk that you might see with a traditional retailer. Costco could outperform rivals in a downturn and has a good shot at leading the industry through the inevitable cyclical rebound that follows. That competitive strength, plus the prospect of increasing cash returns over time, makes Costco an excellent retailing stock to consider even at the current elevated valuation.