Selection is one of Amazon.com's (NASDAQ:AMZN) key advantages in the e-commerce business. The company has relentlessly expanded its assortment of products over the years, with its third-party marketplace helping the cause. Amazon offered around 560 million unique products at the start of this year, according to ScrapeHero.

As recently as a few years ago, Walmart's (NYSE:WMT) online selection was woefully lagging. The retailer offered just 7 million unique products online in 2015, up from a scant 700,000 a few years earlier. Every time a customer turns to Amazon for a product because Walmart doesn't carry it, the retailer loses a sale.

A man holding two Walmart boxes and opening a door.

Image source: Walmart.

Closing the gap

One of Walmart's priorities is to grow its online business. It's accomplishing that with a variety of initiatives, including online grocery pickup and free two-day shipping. The strategy is working, with U.S. online sales expanding 40% year over year in the latest quarter.

But free shipping doesn't mean much if customers can't find what they're looking for. On top of those initiatives, Walmart has greatly expanded the number of items it carries online. Walmart.com sold 75 million unique items at the end of the first quarter, which is up by more than a factor of 10 in less than three years.

Some of this growth is coming from Walmart's own third-party marketplace. The company is much more selective than Amazon when it comes to adding merchants to its platform. Instead of an all-comers approach like Amazon, Walmart requires merchants to be pre-approved and only adds a few hundred new merchants each month. Walmart.com now sports about 18,000 third-party sellers, compared to roughly 2 million on Amazon.

Walmart is betting that having a smaller number of quality merchants is a better strategy than opening the floodgates Amazon-style. This will likely prevent Walmart from ever fully catching up with Amazon in terms of product selection, but the selection gap between the two companies becomes less meaningful as the numbers get bigger. If online sales follow the 80/20 rule -- where 80% of sales come from 20% of products -- Walmart can have a much smaller selection than Amazon but still be competitive as long as it covers the high-volume products.

In other words, Walmart offering just 15% of Amazon's selection doesn't mean it's leaving 85% of potential sales on the table. It depends on what those products are.

Still a long way to go

Walmart's online business has improved dramatically over the past few years, going from an also-ran to a significant threat to Amazon's dominance. Still, the retailer's online sales remain small compared to the e-commerce king. Walmart managed around $11.5 billion of online sales in the U.S. last year, and a 40% growth rate would bring that total to roughly $16 billion this year.

Amazon's first-party e-commerce business generated $27.2 billion of revenue in the second quarter alone. Revenue from Amazon's third-party seller services tacked on nearly $10 billion of additional revenue. That third-party revenue includes only the fees Amazon collects, not the total third-party sales volume. Needless to say, Walmart is far behind.

But if Walmart can keep growing online sales by 40% annually, the numbers will get big fast. Five more years at that growth rate would bring Walmart's online sales to $86 billion. If Amazon's first-party business continues to decelerate -- it grew by just 12% year over year in the second quarter, down from 18% growth in the prior-year period -- Walmart could close the gap considerably over the next 5 to 10 years, even if its own growth rate slows.

Of course, whether Walmart can maintain its impressive online growth rate is unclear. It would need to win market share from somewhere, and the biggest somewhere is Amazon. An added problem for Walmart is the potential for its online business to cannibalize its store business. That hasn't happened yet, but it could as the online business grows.

Amazon still has a product selection advantage, but that advantage is shrinking as Walmart expands its assortment of online products. One thing is for sure: The battle between these two megaretailers is just getting started.

John Mackey, CEO of Whole Foods Market, an Amazon subsidiary, is a member of The Motley Fool's board of directors. Timothy Green has no position in any of the stocks mentioned. The Motley Fool owns shares of and recommends Amazon. The Motley Fool has a disclosure policy.