Amazon (AMZN 0.70%) and Walmart (WMT -0.03%) are the two biggest U.S. companies by sales. They have a lot in common, and a lot that sets them apart. They've both split their shares over the past few years, with Walmart's latest split taking place just last month, and their stocks are both on the rise. So which one is the better buy today? Let's see.

The case for Amazon: More diverse revenue streams

Amazon ranks right behind Walmart as the second-largest U.S. company with $575 billion of net sales in 2023. However, its e-commerce business is way ahead of Walmart's, with 37.6% of all U.S. e-commerce sales vs. Walmart's distant second place with 6.4%. Since e-commerce is increasing as a percentage of retail sales, that's helping Amazon catch up to Walmart's overall lead in retail sales.

But Amazon's business is a lot more than e-commerce. E-commerce sales, including Amazon's online stores sales and third-party sales, together accounted for 67% of Amazon's total fourth-quarter revenue, and they're growing faster than Walmart's sales. But Amazon also operates Amazon Web Services (AWS), its cloud computing business, which accounted for 14% of total sales in the quarter. It's many smaller segments each represent high-growth opportunities.

Advertising is its fastest-growing segment, increasing 27% year over year in the fourth quarter, and this is already turning into Amazon's next large business. Amazon doesn't break out its other businesses, but it has a competitive streaming business that it upgraded with its acquisition of MGM Studios last year, and a growing healthcare business.

Overall, Amazon is growing faster than Walmart, with a 14% year-over-year revenue increase in 2023, and outside of pressure it experienced in 2022, it also usually reports a higher operating margin.

WMT Operating Margin (Quarterly) Chart

WMT Operating Margin (Quarterly) data by YCharts

Amazon has tailwinds from its many businesses, in particular from its investment in artificial intelligence (AI). It has launched a broad array of generative AI tools that could be game-changers for its clients, and it's attracting a list of high-profile customers that's likely to keep growing. It has years of continued potential.

The case for Walmart: A lead too large to lose?

Amazon is growing faster than Walmart, but Walmart's revenue increased 5.7% year over year in its fiscal 2024 (ended Jan.31). That's on top of a larger base -- and while Amazon grew faster for a long time, it can't seem to quite catch up.

WMT Revenue (TTM) Chart

WMT Revenue (TTM) data by YCharts

Walmart operates 10,500 stores worldwide and more than 4,600 in the U.S. alone. If that seems like saturation, Walmart is planning to open 150 supercenters over the next five years. It's also planning to open 30 new Sam's Club stores, and remodel close to 300 U.S. stores.

Whatever happens with e-commerce, Walmart has an unbeatable store network that shoppers love for its discount prices. That's part of why Walmart's operating margin stays low; its model is generating sales volume, and grocery is a low-margin business.

Walmart's businesses don't quite cover the same ground as Amazon's, and it sticks to its retail roots. But it does have other ways to generate higher sales. It recently announced that it's acquiring streaming platform Vizio. That gives it exposure to an advertising medium where it can compete with Amazon for eyeballs and leverage its advertising business.

Finally, Walmart pays a dividend, an attractive feature for passive income investors that Amazon doesn't offer.

Better buy: The verdict

These are both winning stocks that have provided years of shareholder value. Each offers something attractive for investors; growth-oriented investors might want to buy Amazon stock, while risk-averse or dividend investors might prefer Walmart.

However, if I had to pick one, it would be Amazon. It has enough of a proven track record that it doesn't come with high risk, even though it's a growth stock, and it's reliably profitable. It has incredible potential in many areas, and it's leading with AI. It's a forever stock that could have a place in most portfolios.