Shares of megaretailer Wal-Mart Stores (NYSE:WMT) soared on Thursday, thanks to a third-quarter report that soundly beat expectations. Comparable sales in both the U.S. and international markets were up, and the e-commerce business continued to produce incredible growth.

With another strong report, Wal-Mart is disproving two narratives roiling the retail industry: first, that brick-and-mortar retail is dead, killed by (NASDAQ:AMZN) and other online retailers; and second, that Amazon's e-commerce success can't be matched. One look at Wal-Mart's results shows that neither is entirely true.

Wal-Mart still has a long road ahead of it as it aims to catch up with Amazon. But so far, the company's strategy is working perfectly.

Two Wal-Mart boxes stacked in front of a door.

Image source: Wal-Mart.

Investing in the stores

In early 2015, Wal-Mart CEO Doug McMillon announced a move that put investors on edge. The company planned to increase wages for its employees, eventually bringing the minimum to $10 an hour. Other changes included more predictable scheduling and new training programs.

Shares of Wal-Mart tanked in 2015, as the profit hit from these initiatives overshadowed the promised benefits. But it's now clear that the plan is working. Comparable sales in the U.S. have increased for 13 consecutive quarters, despite a tough retail environment. During the third quarter, U.S. comparable sales jumped 2.7%, driven by a 1.5% rise in traffic and a 1.2% rise in average transaction size.

Instead of following the typical playbook of slashing costs and under-investing in its stores when times get tough, Wal-Mart is doing the exact opposite. The company remodeled 208 stores during the third quarter, while opening just two new supercenters. The focus is on improving the existing store base through both direct investments in the stores and higher wages and better training for employees. Based on Wal-Mart's results, it's clearly the right move.

The stores also provide the infrastructure for some of Wal-Mart's e-commerce initiatives, giving it a key advantage in its battle with Amazon.

Betting big on e-commerce

Wal-Mart's U.S. e-commerce sales rose by 50% year over year during the third quarter, a faster growth rate than Amazon managed during its latest quarter, albeit from a smaller base. Wal-Mart has launched a handful of initiatives this year that are driving this growth, and many of them utilize the company's base of stores.

The most important e-commerce initiative from Wal-Mart was the rollout of its free shipping offer in February. The company had been testing an Amazon Prime-like subscription, but it scrapped that in favor of something much simpler. Online orders of $35 receive free two-day shipping, no strings attached -- no membership program or annual subscription required.

Online grocery is another important initiative. Wal-Mart's online grocery service allows customers to order online and pick up at one of its stores, with no fee for this service. It's available at more than 1,000 locations as of September, and Wal-Mart is even testing out a convenience store concept centered around online grocery pickup. With the grocery industry in the throes of disruption, Wal-Mart is staying one step ahead of the competition.

A reserved parking for online grocery pickup sign at a Walmart store.

Image source: Wal-Mart.

Pickup discounts is another initiative that uses the store base to drive the e-commerce business. For certain items, Wal-Mart offers a discount if a customer opts to pick up the item in a store instead of having it shipped to them. It's much cheaper for Wal-Mart to get an item to one of its stores than to ship it to your doorstep, and now it passes some of those savings along to the customer.

More initiatives are coming. Wal-Mart plans to implement's smart-cart technology on, offering customers discounts for purchasing more items, opting out of free returns, and using a debit card instead of a credit card. Wal-Mart paid $3.3 billion for last year, putting CEO Marc Lore in charge of its entire e-commerce operation. Lore has wasted no time making the changes necessary to effectively compete with Amazon.

Profits still need to catch up

One downside to these heavy investments is the effect they have on the bottom line. Wal-Mart expects to produce adjusted earnings per share between $4.38 and $4.46 in fiscal 2018, which ends in January. That's down from $5.07 in fiscal 2015, despite billions of dollars of share buybacks in the past few years.

The next step in Wal-Mart's transformation into an e-commerce powerhouse is showing that the online business can produce decent margin. Amazon's online business doesn't even come close -- the company's operating margin in North America through the first nine months of the year was just 1.66%. Even if Wal-Mart catches up to Amazon in terms of sales, the e-commerce business may never be as profitable as the stores.

Wal-Mart has a tough task ahead of it. It needs to find a way to be solidly profitable in an industry where the dominant leader is anything but. Sales are moving in the right direction, but the bottom line will need to eventually catch up for the stock to hold onto its gains.