Perhaps you've heard: E-commerce is eating retail. One walk around your -- probably vacant -- megamall should be all the evidence you need. Or maybe a glance at the cardboard boxes piling up on your neighborhood's front stoops will convince you of the trend.

But as big as e-commerce has gotten, here's the scary part: it still accounts for 9.5% of all retail purchases in the United States. That means that there's still tons of room for growth. And the two companies facing off today are at the forefront of that movement: Amazon (NASDAQ:AMZN) and Shopify (NYSE:SHOP).

Mini orange shopping basket on a smart device and a laptop with boxes

Image source: Getty Images.

While one company (Amazon) has created an Everything Store for people to shop at and created a fulfillment network to deliver all those packages, the other (Shopify) has created a platform that allows anyone to start a business with an online presence -- including on Amazon itself.

Which is the better buy at today's prices? Let's evaluate the question looking through three different lenses.

Financial fortitude

The first thing we want to do is check and see how safe our investment would be if tough economic times hit unexpectedly. Companies with large war chests and healthy cash flows not only survive such downturns but can actually grow stronger as a result. Those that are in heavy debt are in the opposite boat -- forced to narrow their ambitions to just stay afloat.

Remembering that Amazon is a $900 billion behemoth while Shopify is valued at "just" $16 billion, here's how the two stack up.

Company Cash Debt Free Cash Flow
Amazon $28 billion $25 billion $8 billion
Shopify $1.6 billion $0 ($20 million)

Data source: Yahoo! Finance. Cash includes short- and long-term investments. Free cash flow presented on trailing 12-month basis.

On the one hand, Shopify is in a very healthy position given its secondary offering was recently successful and it has absolutely no long-term debt. Until recently, Amazon was in a similar position, but the company shelled out billions to acquire Whole Foods.

That being said, I still believe Amazon is in the superior position. Not only does it have far superior cash flows, but if tough economic times hit, CEO Jeff Bezos could take his foot off of the reinvestment pedal and I believe free cash flow could explode -- albeit at the expense of long-term opportunities.

Shopify might be able to do the same, but because the company's Merchant Solutions division would likely suffer in a downturn as well, I'm not sure the effect would be as positive for the company's balance sheet.

Winner = Amazon

Valuation

Next we have valuation. And I'll spill the beans from the outset: neither one of these companies is anywhere near "cheap" based on traditional metrics. In fact, they're downright expensive -- insanely expensive if you ask conservative investors.

Company Trailing P/E Forward P/E P/FCF PEG Ratio
Amazon 172 93 117 2.3
Shopify 562 485 N/A 7.6

Data source: Yahoo! Finance, E*Trade. P/E calculated using actual and estimated non-GAAP earnings where applicable.

The task, then, is to simply ask: Which stock is less insanely expensive? Based on every metric above, that is clearly Amazon. 

It's not every day you'll see Amazon being viewed as the "cheaper" stock, but when lined up against Shopify, it earns the designation.

Winner = Amazon

Sustainable competitive advantages

Finally, we have sustainable competitive advantages. Because both of these companies have multiple moats, we'll evaluate how they stack up in terms of the four major sustainable competitive advantages.

The first moat can come from intangible assets -- in this case, the strength of a company's brand. Within the industry for creating an e-commerce platform for small to medium-sized businesses, Shopify has an excellent brand name. When compared to Amazon -- whose brand Forbes ranks as the world's fifth-most valuable at $71 billion -- however, Shopify has the short end of the stick.

The next major moat comes from high switching costs. This is right in Shopify's wheelhouse. Once a company begins using Shopify to meet its e-commerce needs, the pain associated with switching to another provider is enormous. Not only are there migration and coding costs, but businesses suffer downtime and have to retrain their entire workforce on a new operating system. That's what has helped Shopify keep revenue retention above 100% for every year it's been a public company. One could make an argument that switching away from Amazon Prime offers the company a moat -- but there are no real metrics to track this, and Shopify's lead on this front is significant.

Low-cost production is the next major moat, and here is where Amazon is the clear winner. Because the company has spent decades and billions of dollars building out its network of fulfillment centers, it can afford to guarantee two-day delivery at a fraction of the internal costs competitors would have to fork over. Shopify has no such meaningful advantages.

Finally, there's the network effect. This moat comes into play when each additional user of a service makes the service more valuable. Both Amazon and Shopify benefit. For Amazon, the site has become such a popular destination for shoppers that third-party merchants are incentivized to list their wares on the site and use Fulfillment by Amazon for shipping. Revenue for third-party services grew 36% last quarter.

Shopify's network effect comes from the fact that third-party app developers look at Shopify's 600,000 merchants as a huge pool of potential customers. As more apps are developed for Shopify's platform, the tools attract ever more merchants -- a virtuous cycle.

Put it all together and you can see that while both companies have strong moats, Amazon comes out ahead.

Winner = Amazon

And my winner is...

So there you have it: Amazon is cheaper, has a better balance sheet, and has a wider moat than Shopify. Don't let that stop you, however, from considering Shopify as well for your portfolio. I already have outperform ratings for both companies on my CAPS profile, and together, they account for 29% of my real-life holdings. While I clearly think Amazon is a better bet, they both deserve your consideration.

John Mackey, CEO of Whole Foods Market, an Amazon subsidiary, is a member of The Motley Fool's board of directors. Brian Stoffel owns shares of Amazon and Shopify. The Motley Fool owns shares of and recommends Amazon and Shopify. The Motley Fool has a disclosure policy.