Walmart's (NYSE:WMT) better-than-expected second-quarter results were headlined by 2.8% comparable-store sales growth in the United States. Half of that growth was driven by Walmart's surging e-commerce business, which climbed 37% year over year for the second straight quarter.

Walmart's efforts to take on Amazon (NASDAQ:AMZN) in e-commerce continue to pay off in sales growth, although it's worth noting it's been a drag on gross profit margin. Walmart U.S. successfully offset that margin pressure by exhibiting operating leverage last quarter, but continued growth may require more up-front investments in what drove its success over the past three months.

A Walmart associate loads groceries into the back of a car.

Image source: Walmart.

Online grocery is the biggest driver

Walmart's lead in online grocery continues to grow as it adds more pickup locations and expands its delivery footprint. The retailer ended the quarter with 2,700 stores offering curbside pickup and delivery from 1,100 stores. Management says it's on pace to reach its goal of 3,100 and 1,600 pickup and delivery locations, respectively, by the end of the year. That would make Walmart's grocery platform accessible to at least 80% of the population.

While Walmart's online grocery efforts may cannibalize some of its existing sales -- it's the largest grocery retailer in the U.S. -- it's worth pointing out that the company is also drawing in new customers to its platform. And online grocery shoppers are adding more high-margin products like health and wellness items to their shopping carts, which can drive both comparable sales and profit margin. So while the bulk of Walmart's online sales growth came from grocery, it was still able to fuel comparable-store sales. In other words, buyers didn't simply switch from buying in stores to buying online at

Walmart's rapid expansion and investment in marketing its online grocery platform has led to good growth, but the competition will catch up sooner or later. Amazon has been slow to expand its Prime Now delivery service from Whole Foods, but it's considering an entire chain of stores designed with online ordering in mind. Amazon has been hovering around the space for a long time, and Walmart will need to keep investing to stave off its deep-pocketed competitor.

One-day shipping works even when you already have stores

The verdict is in: Shoppers love one-day shipping.

Walmart launched its NextDay shipping program in May as an answer to Amazon's plans to offer one-day shipping for Prime members. The company said it expected to cover 75% of the population by the end of the year, but management announced it reached that milestone already. All management had to say beyond that is "customers are responding well."

The homepage highlighting its NextDay delivery program.

Image source: Walmart.

Amazon pointed to the expansion of one-day shipping as a catalyst behind its sales growth in the second quarter. It invested $800 million in Q2 on top of its usual fulfillment investments in order to support one-day shipping for some 10 million items available on its marketplace. CFO Brian Olsavsky expects the investments to increase in the short term as it ramps up one-day shipping eligible product selection as we head into the holiday shopping season.

Walmart, on the other hand, says NextDay actually produces better economics since it requires customers to order items from a single nearby location. That cuts down on shipping expenses because it has fewer packages traveling shorter distances. That said, Walmart will need to invest more money into placing more inventory into multiple fulfillment centers if it wants to expand product selection.

Expanding the third-party marketplace

It's been a while since Walmart highlighted the growth of third-party merchants on its online marketplace. Management last told investors it had 75 million unique items for sale on its website about a year and a half ago. That was up from about 10 million at the start of 2016 and driven almost entirely by the expansion of third-party sellers on its marketplace.

But CEO Doug McMillon's comments suggest growth of the marketplace business might not be forgotten. "We've quickly grown this piece of the business in recent years, and I know we can do even more as we look ahead," he said in management's commentary accompanying the second-quarter results.

Third-party merchants account for the majority of gross merchandise volume on Amazon and that share continues to climb year after year. That said, Walmart has historically been able to attract merchants to its platform as Amazon's marketplace becomes more of a pay-to-play business now that Amazon's pushing its advertising products.

Amazon is currently facing regulatory scrutiny around its third-party merchant services, which could open the door a crack for Walmart to step in. That said, it'll need to invest heavily to attract the bulk of Amazon's merchants, which often rely on the online retailer's infrastructure to support their businesses.

Walmart's online sales growth has been great over the past couple years. Investors should realize, however, that Amazon is still calling the shots. If Walmart wants to continue competing, it needs to keep its foot on the gas pedal, and probably push down a little harder in order to stay ahead.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.