In the decade since the Great Recession, the growth of e-commerce has dominated the retail scene. Led by Amazon.com (AMZN -1.64%), the digital-sales paradigm shift has left a trail of broken companies that have either filed for bankruptcy -- or soon could

One of traditional retail stalwarts that has not only survived, but thrived, in this new environment is Costco (COST 0.17%). The bulk-goods membership store has provided what customers want: a pleasant experience with deals that cannot be beat -- whether online or in person.

Person checking their smartphone while shopping

Image source: Getty Images

But between these two stocks -- the warehouse leader and the e-commerce leader -- which would be the better buy today?  By comparing them on these three facets, we should be able to get a pretty good idea.

Financial fortitude

The first thing we want to investigate is how these companies would fare if there were a huge recession tomorrow. Believe it or not, companies with lots of cash, little debt, and strong cash flows can actually benefit from a broad economic downturn.

Sure, the stock price might fall temporarily. But in the real world, such a company's competitive situation can improve dramatically as weaker players are pushed out of the market. A strong balance sheet also puts a company in position to acquire start-ups, and even if no appealing acquisition opportunities exist, a company can buy back its own shares on the cheap.

Keeping in mind that Amazon's market cap is almost eight times the size of Costco, here's how they compare:

Company Cash Debt  Free Cash Flow
Amazon $38 billion $42 billion $21 billion
Costco $8 billion $5 billion $3 billion

Data source: Yahoo! Finance. Cash includes long and short-term investments. Free cash flow presented on trailing twelve-month basis. All figures rounded to nearest whole number.

Here we have a mixed bag. Costco has a positive net cash (cash minus debt) position, while Amazon's is negative. On the other hand, Amazon has much stronger cash flows -- though they're proportional to Amazon's larger market cap.

If tough times were to hit, Amazon CEO Jeff Bezos could easily tap  the brakes on reinvestment, and free cash flow could surge even higher. That being said, I'm a sucker for a company that has a positive cash position and reliable cash flow.

Winner = Costco.

Valuation

If there were one single metric that could define whether a stock was "cheap" or "expensive", it would be much easier to measure valuation. But there are many, and companies with higher price ratios often appear more expensive for the good reason that they are executing on their business plans and growing rapidly.

As such, I weigh a number of metrics to decide how well priced a stock is.

Company P/E P/FCF  PEG Ratio
Amazon 82 47 1.2
Costco 34 47 3.5

Data source: Yahoo! Finance. 

If you're a value investor, this might sound blasphemous, but I think Amazon is a better value today. Sure, its price-to-earnings ratio is much higher than Costco's. But when it comes to the price-to-free-cash-flow ratio, the two companies are even.

Factor in their growth prospects (via the price/earnings-to-growth ratio), and Amazon is trading at a significant discount. This shouldn't be too surprising: Costco essentially only grows when it adds new members -- its annual membership fees account for virtually of its all profits. Amazon can and does grow by adding clients to Amazon Web Services, subscribers to Prime, random online shoppers, people visiting Whole Foods -- and the list goes on.

Bottom line: Neither of these stocks is "cheap", but relative to their growth prospects, Amazon is a better value today.

Winner = Amazon

Sustainable competitive advantages

Finally, we have what I consider to be the most important factor: a company's sustainable competitive advantages, i.e., its moat. A company with a wide moat can hold the competition at bay for years and let compounding growth work its magic. One that lacks a moat risks being swallowed up or overtaken by rivals.

Costco has two major moats. The first is its brand power. Forbes pegs it as the 82nd most-valuable brand in the world, worth $8.8 billion.The wider moat, however, is provided by it low-cost production and sales model. Costco sells virtually all its goods at a zero profit margin. That's because the warehouse chain -- as mentioned above -- relies on membership fees for its profits. This model allows it to sell goods for less than just about any other retailer could afford.

Amazon, too, benefits from multiple moats:

  • Forbes ranks Amazon as the fourth-most valuable brand worldwide, worth $97 billion.
  • Because of Amazon's vast fulfillment center network, it benefits from low-cost production, too. With Amazon, that "product" is one- or two-day delivery. Because much of the U.S. -- and, increasingly, global -- population lives close to a fulfillment center, Amazon can delivery packages for a lower internal cost than rivals.
  • The network effect is making third-party fulfillment an increasingly lucrative business: Other sellers list their wares on Amazon because so many people visit the site. As more merchants join, more customers are incentivized to visit. It's a virtuous cycle.

Additional moats come into play when it comes to the high-profit-margin Amazon Web Services business -- such as high switching costs. For clients of the service, transitioning cloud operations away from AWS to another provider is costly, and can cause lots of headaches. That fact makes it fairly sticky.

Put all of this together, and Amazon clearly has a much wider moat today than Costco.

Winner = Amazon

And my winner is...

So there you have it: While Costco might have a slight edge when it comes to financial fortitude, Amazon has a wider moat and -- I can't believe I'm saying this -- a more favorable valuation. That gives it the edge -- and makes it the better buy at today's prices.