How Walmart Is Bolstering Its Grocery Business Ahead of the Amazon-Whole Foods Marriage

Walmart (WMT) served up some especially good news on Thursday with its second-quarter results: Its grocery business is thriving again.

The retailer—the largest grocer in the United States by far with annual sales of about $170 billion—said comparable sales of food and other grocery items rose by a low single digit percentage in the May to July quarter, notching its best performance in the key category in five years, with produce and meat as standouts.

The strong performance comes at a crucial time for Walmart as it gears up Amazon’s pending acquisition of upscale food store chain Whole Foods Market, and girds for growing price pressure from German deep food discounted Lidl as it establishes itself in the United States, and Aldi, a similar German retailer that is expanding its fleet and overhauling many stores. It even faces the prospect of a reinvigorated food business at Target (TGT), where grocery sales have at last stopped falling though they’re hardly thriving. Walmart gets 56% of annual sales from grocery, making the category vital for its well being.

Walmart, a division of Wal-Mart Stores which also operates Sam’s Club, has been spending billions and sacrificing a ton of profit, on improving its grocery areas and using tech to smoother operations for store workers and equip hundreds of stores to handle curbside delivery.

“It’s an important driver of our strategy,” Walmart U.S. CEO Greg Foran told Fortune on a media conference call. The efforts have also gone beyond tech and included basic retailing: overhauling the layout of the food section at thousands of stores, placing fresh vegetables close to the entrance of the store and grouping like-colored produce together to create a visual pop. Walmart has even started using plastic crates that look like wood rather than black ones.

Walmart has been using tech on a number of fronts to boost its grocery business. For example, Wal-Mart Stores CEO Doug McMillon recently boasted how a one grocery department manager has been using a made-by-Walmart app that helps ensure products are in-stock. The retailer used to have a major problem keeping track of inventory and too frequently, many items found themselves on shelves much closer to their sell-by date than necessary, leading to lost sales.

The thrust of those efforts of course has been to equip stores to handle drive-in grocery delivery of orders placed online, something Walmart executives called out as a major contributor to the strong second-quarter results. Now, some 900 Walmart locations offer that service, a number that will rise to 1,100 by year end with more to follow next year. And Walmart has been training people on how to pick food for orders that will be picked up, knowing how finicky some people are about things like banana bruises and dents in apples. “Then you’ve got a personal shopper picking someone’s order you better make sure your cilantro is really good or that your French bread is great,” Foran said.

The chain is also testing out delivery of grocery in 12 stores in Denver and San José, Calif., as well as with Phoenix where it is conducting a test with Uber. What’s more, fresh and frozen groceries are also available for delivery through Jet.com on the East Coast and some markets in the Midwest.

All this equips Walmart well to handle Amazon’s ever faster delivery firepower and that of other retailers: Aldi recently said it was teaming up with tech startup Instacart to test grocery delivery in Dallas, while Target this week announced it was buying a logistics firm to build up its same-day delivery capability, a potential challenge down the line for its grocery rivals.

“We have the assets in place to do that last mile delivery of grocery,” said Marc Lore, the head of Walmart U.S,’ e-commerce division and the entrepreneur who last year sold jet.com to Walmart.

Still, Walmart executives recognized how brutally competitive the grocery market will remain, saying that Amazon as well as Aldi and Lidl and other rivals for that matter, keep the pressure on. “I still think we’ve got room to do better,” said Foran.