Costco (NASDAQ:COST) has held its own against Amazon (NASDAQ:AMZN). The warehouse club has taken a slow and steady approach to competing with the online giant, and that has worked very well.

Unlike many traditional retailers, Costco has a loyal customer base that pays for the privilege of accessing its clubs. The chain closed its second quarter with 92.2 million cardholders -- less than the 100 million Prime members Amazon CEO Jeff Bezos admits to having -- but still a sizable amount.

In fact, Costco may be the retailer best set to compete with Amazon for the long term. However, that's not the only factor to consider when deciding whether to buy stock in the company.

A Costco store with a crowded parking lot.

Costco has done a good job in competing with Amazon. Image source: Costco.

The case for Costco

Destination and low-price shopping have proven to be resistant to losing customers to Amazon. Costco offers both. The warehouse club built its business on offering low prices. Customers also visit its stores in part because it's an experience. You never know what you might find on its shelves, and there's a sense of fun with the free samples as well as the low-cost food court.

That has been a formula for success. In its most recent quarter, Costco's net sales rose 10.8%, while sales for the first two quarters of the year were up 12%. In addition, same-store sales were up 8.4% in the second quarter and 5.4% for the first six months of the year. The company also posted a 28.5% gain in e-commerce sales in Q2, delivering earnings per share (EPS) of 1.59, an improvement over $1.17 in the year-ago period.

Perhaps most importantly, Costco continues to add to its membership base. CFO Richard Galanti explained those numbers in detail during the company's second-quarter earnings call:

In terms of members at Q2 end, we had 39.6 million Gold Star Members, up from 39.3 million 12 weeks earlier. Primary businesses were 7.5 million at both quarter's ends. Business add-ons, which was 3.2 million at Q1 end, at Q2 end was 3.3. So total member households, 49.9 million at Q1 end, up to 50.4 million at Q2 end. Total cardholders at 92.2 million at the end of the quarter, up from 91.5 million 12 weeks earlier.

Costco isn't a dynamic company. It's a smart one that plods ahead slowly, sticking with what works and modifying as needed after careful consideration.

The case for Amazon

Costco is a solid stock buy for investors looking for limited risk, steady growth, and solid management. Amazon, however, is a better buy because it offers not only a growing retail business, but also the company's web services business and all sorts of innovation.

Amazon has been willing to trade short-term profits for long-term gains. That was not the case in the first quarter, when the online leader saw net sales rise by 43% to $51 billion with net income coming in at $1.6 billion in the first quarter, or $3.27 per diluted share, compared with net income of $724 million, or $1.48 per diluted share in the year-ago quarter.

The biggest difference between Amazon and Costco, though, is Amazon Web Services (AWS). That business segment had $5.4 billion in Q1 sales, up from $3.4 billion during Q1 2017. In addition, AWS profits rose from $890 million in Q1 2017 to $1.4 billion in 2018. That's the majority of Amazon's profits.

"AWS had the unusual advantage of a seven-year head start before facing like-minded competition, and the team has never slowed down," said Bezos in the earnings release.

Why Amazon is the better buy

On the retail level, both Amazon and Costco are very similar. Both operate on margins and leverage their customer bases in other ways to make a profit. Costco does that by selling memberships. In fact, about 75% of its profits come from selling memberships.

Amazon makes similarly slim profits from its retail operation, but AWS's growth gives the company a second dimension that's very profitable. That, plus the company's ability to further diversify, makes it a better stock -- albeit slightly riskier -- than Costco.

Both brands are solid buys as retailers. Amazon just has more upside as its ability to grow in retail, and with AWS, it widely outpaces Costco's ability to add new stores and customers.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.