Shares of Wal-Mart (WMT -0.02%) have rallied 20% since the beginning of the year, thanks to a return to positive revenue growth, higher U.S. comps growth, and stronger cash flows from lower inventories last quarter.

Image source: Wal-Mart.

That was an impressive rebound from last year, when the stock plunged to multi-year lows on doubts that Doug McMillon -- who became the company's fifth CEO in 2014 -- could reinvent the company by investing billions of dollars on higher wages, employee training, and an e-commerce expansion to counter Amazon (AMZN -0.68%). A look back at Wal-Mart's sales growth in comparison to Amazon's over the past decade shows why investors were skeptical.

WMT Revenue (TTM) Chart

Source: YCharts

Nonetheless, McMillon has made it clear that Wal-Mart plans to counter some of Amazon's most aggressive tactics instead of sitting idly by as it becomes a showroom for online purchases. Let's take a look at three key ways Wal-Mart is finally fighting back.

Matching Amazon's prices

Many of Wal-Mart's stores became showrooms for Amazon purchases because shoppers would walk in the store, scan an item with their phones, and buy the cheaper product online. To counter that habit, Wal-Mart started offering to match the prices of Amazon and other online retailers in 2014. This was a risky move, since Wal-Mart paid higher overhead costs to run brick-and-mortar stores -- meaning that it was accepting lower margins than Amazon.

Amazon fought back by blurring the lines with its $99 per year Prime memberships, which offer special discounts and free shipping on select items. Wal-Mart won't match Prime prices because they're considered "club" discounts, but it can't ignore this growing problem -- Amazon's Prime membership base in the U.S. rose 35% year-over-year to 54 million in January, according to research firm CIRP.

Countering Amazon Prime

To fight back against Amazon Prime, Wal-Mart recently introduced ShippingPass, which gives shoppers free two-day shipping on any item for $49 per year. To counter Amazon's 30-day trial of Prime, which CIRP claims converts 73% of users to paid memberships, Wal-Mart is offering a month of free shipping for trial customers. This move might steal some thunder from Amazon's Prime Day off-season sale in July.

Wal-Mart is also striking back against Amazon Prime Fresh, Amazon's $299 per year plan which adds free same-day grocery deliveries to its basic Prime package. Wal-Mart's plan is much simpler -- it's adding free curbside pickup of groceries in several markets. It recently expanded that service to about 200 locations in 30 cities.

Digital ecosystem expansion

Wal-Mart is doing an admirable job blocking Amazon's blows, but it's woefully behind in terms of digital expansion. Amazon tethers millions of users to Prime by offering them access to free e-books, music, videos, cloud storage, and other perks.

When combined with free shipping and discounts, Amazon Prime becomes a very lucrative bundle for many shoppers. Amazon's recent introduction of buttons for automatic reorders, appliances which reorder consumables, and the Echo speaker all strengthen its grip on Prime members. That's why CIRP estimates that 91% of Prime members renew their memberships after the first year.

Wal-Mart's attempts to grow a digital ecosystem have been clunky and fragmented. It stopped selling Amazon's Kindle and started selling its own e-books for mobile devices. In 2010, Wal-Mart acquired its own on-demand video streaming service, Vudu, but the service has been overshadowed by bigger subscription-based services like Netflix, Hulu, and Amazon Prime Video.

Last year, Wal-Mart launched the Vudu Spark, a streaming stick intended to challenge Amazon's Fire TV Stick, but the device trails far behind Roku, Chromecast, Fire TV, and Apple TV in U.S. market share.

The Vudu Spark. Image source: Vudu.

Wal-Mart also recently expanded its own payment app, Walmart Pay, to over two-thirds of the U.S., but that app is mainly designed to counter Apple Pay instead of streamlining payments across its digital ecosystem. Unless Wal-Mart can somehow bundle all these platforms into a single package with ShippingPass, it's unlikely that it can fully match Amazon Prime's appeal.

The quest to become number two

Wal-Mart is currently the world's largest brick-and-mortar retailer, but its e-commerce revenues accounted for just 3% of its constant currency sales in 2016. Wal-Mart is the fourth largest e-commerce company in the world by sales, according to Deloitte, trailing behind Amazon, Apple, and Chinese e-commerce giant -- in that order.

No one really expects Wal-Mart to overtake Amazon, but its new strategies could remind customers that Amazon isn't the only provider of free shipping and steep discounts. This e-commerce push, which cost nearly $1.3 billion in investments last year, will likely weigh down earnings but prevent it from fading away like other forgotten retailers.