There's no greater rivalry in retail than Amazon (AMZN 2.99%) and Walmart (WMT -0.25%). They are the two biggest companies by revenue in the country, and both are on track to top $500 billion in revenue this year.

As most investors know, Amazon has been gaining market share on Walmart for years, and it's also been the much better stock to own over the last decade. But that could be changing.

In its recent guidance, the e-commerce giant called for revenue to be just 2% to 8% higher in the fourth quarter, uncharacteristically slow for the growth stock. Adjusting for currency headwinds, the company expects a 6.6% to 12.6% revenue increase, but that still marks a significant slowdown from the 15% growth it posted in the third quarter. The stock tumbled on the news.

On the earnings call, CFO Brian Olsavsky explained the headwinds the company is facing, saying, "The continuing impacts of broad-scale inflation, heightened fuel prices, and rising energy costs have impacted our sales growth as consumers assess their purchasing power."

Consumers are cutting back to afford essentials. What Olsavsky is implicitly acknowledging here is that discretionary items make up the vast majority of Amazon's sales. Most of its sales come from third-party marketplace sellers, which tend to skew even more toward discretionary items than products that Amazon itself sells. 

With interest rates rising and the chances of a recession increasing, consumers are responding by cutting back their spending on Amazon.

Walmart's hidden advantage

Unlike Amazon, Walmart does most of its business selling consumer staples, not discretionary items. Groceries account for a majority of U.S. sales, and the store's reputation for low prices makes it a draw for customers looking to save money in tough times. Its strength in groceries helps encourage visits to its stores, where consumers are likely to purchase other items they need. 

Walmart hasn't reported third-quarter earnings yet. However, while the company has struggled with elevated inventory levels this year and higher costs, it's a good bet that it won't experience the kind of drop-off in sales growth plaguing Amazon. 

Management has said that the company sees recessions as an opportunity to pick up market share and that they play to Walmart's strengths as a low-cost leader.

Even with Amazon's dialed-down growth, it's still likely to show bigger increases in the fourth quarter because it has high-growth businesses like cloud computing and advertising that Walmart lacks.

But stocks are priced relative to expectations, and Walmart seems much better prepared for a holiday season during a downturn.

What it means for Amazon

In preparation for slowing sales growth, Amazon is implementing a number of cost-cutting measures. That includes a hiring freeze for its corporate, retail, and AWS segments. It also means closing warehouses, canceling projects, and shuttering unprofitable businesses like Amazon Care.

The stock has fallen nearly 50% from its peak last year as growth has slowed and profits have fallen. Though the business is likely to struggle over the next few quarters and the stock could get hit by a recession, the sell-off is a good, long-term buying opportunity for a company that can return to profitable growth.

However, with Walmart's focus on consumer staples like groceries and its reputation for low prices, the company looks set to be the winner through the holiday season and into next year if a recession hits.