Back in 2011, we here at The Motley Fool put out a special free report called "The Death of Wal-Mart." The report detailed how two upstart players were challenging the dominant worldwide retailer. Those two are our focus today: Amazon.com (AMZN 1.30%) and Costco (COST 1.01%).

It wouldn't be an exaggeration to say that we nailed it with this report. Here's how the stocks of all three have fared since January of that year.

Stock chart showing returns for the three companies.

Image source: Google Finance

But we aren't talking today about Wal-Mart. We're focusing on whether Costco or Amazon is the better buy at today's prices. While we can't answer that question with 100% certainty, we can look at it through three different lenses. That may give us a clearer picture into what we're really buying and help a winner emerge.

Sustainable competitive advantages

In my opinion, this is the most important of the three sections we'll cover. Often referred to as a "moat" in investing circles, a company's sustainable competitive advantage is what separates it from everyone else. It is what keeps customers coming back year after year and keeps the competition at bay for decades.

Costco's key moat is in the form of its scale. Believe it or not, if we look at the company's profit over the past five years, we'd see that more than all of it has been profit has come from membership dues.  Everything else the company simply sells at an operating loss.

It's All About the Membership Dues
Create column charts

The brilliance of this business model can't be overemphasized. By lowering margin into potentially negative territory, Costco is just about guaranteed to have the lowest prices on bulk items. That draws more and more customers into the company's membership roster.

The more members at Costco, the higher the sales, and the better the deals the company can procure from the vendors selling to the company -- thereby lowering prices even more. It's a virtuous cycle.

An aerial view of a Costco location.

Image source: Costco

Amazon, on the other hand, relies on two major forces to provide its moat. The first also has to do with scale. Amazon has a network of 102 fulfillment centers in the United States, and 393 total. That means no customer is ever that far from a fulfillment center, meaning orders can be delivered faster than with any other global company.

It would be prohibitively expensive for anyone to even challenge this moat. It would require hundreds of billions of infrastructure costs, and the competitor would still have to deal with Amazon at the end of the day.

The second major moat is one of the most powerful forces in business today: the network effect. As Amazon Prime rosters have continued to swell -- exact numbers aren't available, but many estimate that it's north of 60 million stateside  -- third-party vendors have realized that by listing on Amazon's platform and paying for its fulfillment services, they get access to far more customers. That gives more people incentive to sign up for Amazon Prime, which leads to even more vendors. This, too, is a virtuous cycle.

I have to give this category to Amazon. While Costco's moat is formidable, Amazon's momentum shows that it clearly has the upper hand in retail and is becoming the de facto platform for e-commerce.

Winner: Amazon.

Financial fortitude

Both of these companies are uniquely attuned to macroeconomic trends. That means that when difficult economic times hit, they'll probably experience a notable drop in business.

For that reason, cash on hand is important. While it's not as sexy as paying a dividend or reinvesting in growth initiatives, having a robust war chest is vital. Companies that enter difficult economic times with cash have options: buy back shares at a discount, acquire rivals, or -- conversely -- spend them into oblivion by grabbing market share.

Those with lots of debt are in the opposite boat: They have few, if any, options.

Remembering that Amazon is valued at almost six times the size of Costco, here's how these two stack up.

Company

Cash

Debt

Net Income

Free Cash Flow

Amazon

$26 billion

$8 billion

$2.6 billion

$10.2 billion

Costco

$4.7 billion

$4.1 billion

$2.4 billion

$2.5 billion

Data sources: SEC filings, Yahoo! Finance.

On a net income and free cash flow basis, Costco has the stronger financials -- after adjusting for size. But much of that is because of Amazon's relentless pursuit of long-term dominance and reinvestment.

The important thing is that both companies are solidly profitable. After that, I give the nod to the company with the stronger balance sheet. And on that respect -- with over three times more cash than debt -- Amazon is the clear winner.

Winner: Amazon. 

Valuation

Finally, we have valuation. While we don't have a one-size-fits-all metric to compare any two companies, we can use multiple data points to make an informed analysis.

Company

P/E

P/FCF

PEG Ratio

Dividend Yield

FCF Payout

Amazon

178

44

5.0

-

-

Costco

33

31

3.2

1.1%

31%

Data sources: SEC filings, Yahoo! Finance.

I believe that Costco is quite expensive relative to its growth prospects. But context matters, and in this context, Costco is going up against one of the most expensive stocks on the market. Indeed, it has a more favorable valuation on every metric -- and it offers a dividend.

Winner: Costco.

Our winner is...

So there you have it: while Costco is the cheaper stock, Amazon has both a wider moat around the business and a stronger balance sheet. While it may never be a good time to back up the truck on an investment in the company, I suggest investors strongly consider taking a position in the e-commerce juggernaut if they haven't already.

And my money is firmly where my mouth is, as shares of Amazon account for 20% of my real-life holdings.