Walmart Needs a Friend, Buys CEO Marc Lore has 3.3 billion reasons to smile.

Mike Pont/Getty Images for AWXII

Like many a bully confronted with a changing social scene, Walmart has had trouble adjusting its behavior in the face of the e-commerce boom. On Monday, it moved to bring in a younger sidekick—deals startup—to help make the world’s largest company (by revenue) more competitive with Amazon.

The deal, which Walmart expects to close before year’s end, has Walmart buying Jet for $3.3 billion, which includes $300 million of Walmart shares. That’s on top of $2 billion the company had pledged to spend bolstering its online business over 2016 and 2017 with investments in warehouses, grocery services, and a mobile app.

Jet is a sleekly designed site that tallies discounts based on combinations of items in your cart. Prices vary based on your ZIP code and supplier, reflecting the cost of shipping. “On one Heinz ketchup bottle we could either lose 20% if it had to ship cross-country, or make 20% if it was near,” Jet founder Marc Lore told USA Today last year. “So we thought, let’s give retailers the ability to compete for that ketchup depending on where the order comes from.”

The acquisition is a great outcome for Jet, which debuted just over a year ago, and a familiar one for Lore, who sold his previous startup, Quidsi (parent of, to Amazon in 2010. (Walmart also made a bid.) Jet processes 25,000 orders a day but struggled with its business model. It had planned to make all its profits from a $50 membership fee, but later scrapped that model, and lost money in its quest to offer customers the best prices on the internet. Walmart will maintain Jet’s site separately but bring Lore into a senior role, integrate Jet’s software with its own, and gain access to the startup’s customer base, which is younger and wealthier than Walmart’s own.

Online, Walmart has tried to position itself as the blue-collar alternative to Amazon, with its ShippingPass as the poor man’s Prime. As I wrote in May, that effort has brought mixed results:

Over the past two years, Walmart’s digital growth has been on a steady downward trajectory, from 20 percent growth rates in 2014 down to 10 percent, 8 percent, and 7 percent in the past three quarters.

That’s way out of step with the rest of the retail sector. Target’s digital sales rose 23 percent in the first quarter of 2016. U.S. retail sales grew 2.2 percent between the first quarters of 2015 and 2016, but e-commerce growth was at 15.2 percent during the same period, according to the Census Bureau—more than twice Walmart’s own performance.

Sometimes, these big fish/little fish acquisitions feel defensive, like an effort to control (or smite) a potential rival. (See: Amazon’s purchase of Quidsi.)

That’s not the case here: What Walmart’s doing online isn’t working, and the company is hoping Jet will help fix it.