Walmart (WMT -0.65%) was once considered the "Death Star" of the retail market, as its superstores crushed smaller retailers with lower prices. But today, that title belongs to Amazon (AMZN -1.14%), which disrupted both smaller and larger retailers with its massive online marketplace.

Conventional wisdom suggests that despite recent improvements to its e-commerce ecosystem, Walmart remains stuck in the past, and Amazon represents the future. Walmart's stock advanced about 40% over the past decade, but Amazon's skyrocketed nearly 2,200%. Therefore it may seem obvious that Amazon is a better long-term investment than Walmart.

A man checks his smartphone while shopping.

Image source: Getty Images.

However, past returns don't guarantee future gains, and investors should always evaluate the contrarian argument. Let's examine these two retail giants and see which stock is the better buy.

How do Walmart and Amazon make money?

Walmart operates 11,718 stores in 28 countries under 65 banners. Its namesake stores in the U.S. generated 64% of its revenue last year, its international stores generated 24%, and its Sam's Club stores accounted for the remaining 12%. To counter the rise of dollar stores in the U.S., Walmart launched smaller-format Neighborhood Markets in recent years.

Walmart's e-commerce ecosystem generated $4.8 billion in sales last quarter, but that only accounted for 4% of its top line. Walmart has been expanding that ecosystem with its acquisition of American e-commerce site Jet.com, its investment in Chinese e-tailer JD.com, and its recent takeover of Indian e-commerce giant Flipkart.

Amazon owns the largest e-commerce marketplace in the world. It operates retail marketplaces in over a dozen countries, and exports products to additional countries. Amazon locks customers into its ecosystem with Prime, its premium membership program. Amazon Prime offers discounts, free shipping, streaming media, and other perks for $119 per year or $13 per month.

In April, Amazon stated that it had over 100 million Prime members worldwide. It's currently integrating Prime benefits into over 470 Whole Foods stores in the U.S. and U.K. It also recently entered the online prescription drug market with its acquisition of PillPack.

Amazon generates most of its revenue from its marketplaces, but most of its operating profit comes from Amazon Web Services (AWS), the largest cloud infrastructure platform in the world. That higher-margin business, which serves massive customers like Netflix and NASA, allows its marketplace business to operate at lower margins or take losses (via hardware products like Echo or its cashier-less Amazon Go stores) to expand.

An Amazon Go store.

Image source: Amazon.

Which company is growing faster?

Walmart's revenue rose 3% to $500.3 billion last year, and its adjusted EPS rose 2% to $4.42 per share. The company's domestic sales rose 3.5%, its international sales climbed 1.7%, and its e-commerce revenue rose 44%. For the current year, Wall Street expects its revenue to grow another 3% and EPS to rise 9%.

But those estimates could be too high, since Walmart slashed its earnings forecast after announcing its $16 billion takeover of Flipkart in May. Walmart expects that deal to reduce its EPS by $0.25 to $0.30 this year, and $0.60 next year. Based on those revisions, Walmart's earnings should grow about 4% this year and just 2% next year.

That's an unimpressive growth rate for a stock that trades at 18 times earnings. However, Walmart pays a decent dividend with a forward yield of 2.5%, and it's hiked its dividend annually for over four decades. Amazon has never paid a dividend.

Amazon's revenue rose 31% to $177.9 billion last year, buoyed by 33% growth in its North American marketplace, 23% growth in its international marketplaces, and 43% growth in AWS. Amazon's net income rose 28% to $3.03 billion, or $6.15 per diluted share.

Analysts expect Amazon's revenue growth to accelerate to 34% this year, supported by the growth of its marketplaces and a sales boost from Whole Foods. Meanwhile, its earnings are expected to more than double on the ongoing growth of AWS. Amazon is clearly growing faster than Walmart, but its stock is also much pricier at 144 times this year's earnings.

The winner: Amazon

I've owned Amazon since the low $600s, and I don't plan to sell my shares for a long time. The stock has always been considered expensive, but Amazon's market-leading position in e-commerce, the stickiness of its Prime ecosystem, its ability to disrupt multiple markets, and the bottom-line support of AWS make it an essential long-term investment.

Walmart isn't a bad stock, but there are many other stocks that offer higher growth and dividends at lower multiples. Walmart needs to keep spending money to counter Amazon's blows, but it can't fall back on a higher-margin business like AWS. Therefore, Amazon is clearly a better buy at these prices.