Five years ago, the world’s largest retail chain didn’t have to worry much about the world’s largest online mall. Only about a quarter of Wal-Mart Stores (WMT) customers shopped at Amazon.com (AMZN), according to data from researcher Kantar Retail. Today, however, half of Wal-Mart customers say they’ve shopped at both merchants. That’s leaving the mega-retailer—which long ago bested local brick-and-mortar merchandise stores and supermarkets across America—with a massive online competitor that is too tough to ignore.

Threatening Wal-Mart’s dominance are two trends: The discounter’s traditional customers—bargain hunters making less than $50,000 a year—are getting more tech-savvy, and more-affluent shoppers who began frequenting Wal-Mart during the recession are returning to Amazon as their finances improve. Amazon has moved into merchandise categories that Wal-Mart traditionally has sold, from diapers to vacuum cleaner bags. In its last fiscal year, Amazon posted 41 percent revenue growth, to $48.1 billion, vs. 8 percent at Wal-Mart. The chain’s 2011 online sales amounted to less than 2 percent of its $264 billion in U.S. revenue, says Kantar. “Amazon is always in our sights,” says Jeremy King, chief technology officer at the retailer’s @ WalmartLabs skunkworks in Silicon Valley. “My biggest issue is playing a catch-up game.”

In the last year Wal-Mart has increased its investment in its online business. The company has spent more than $300 million acquiring five tech firms since May and hired more than 300 engineers and code writers in the U.S. and India. Wal-Mart is also launching a program to allow the 20 percent of its customers without credit cards or bank accounts to make online purchases.

Wal-Mart’s acquisitions include Kosmix, a social-media firm, and iPhone app creator Small Society. The company hopes the newcomers can find a way to stop shoppers from engaging in scan and scram. That’s when would-be customers use their smartphones in stores to scan an item’s bar code and then buy it online from a rival merchant. The chain’s tech team also is working on a concept called Endless Aisle, which would let shoppers immediately order from Walmart.com via smartphone if an item is out of stock. “You can’t ask people to leave their phones at the door. So you have to give them value and an experience,” says Venky Harinarayan, @WalmartLabs’ senior vice president of global e- commerce. The former Amazon executive joined from Kosmix.

Wal-Mart is trying to improve links between its store inventory, website, and mobile phone apps so that more customers can order online and pick up their purchases at stores, which half of Web customers do already. Wal-Mart is trying Web-based shopping tactics, like its Pay With Cash program for Wal-Mart customers who don’t have credit cards. The new program allows them to reserve products online and pay cash at their nearest store. To cater to its affluent customers, Wal-Mart is selling more expensive items—for example, high-end televisions from Sony (SNE) and Samsung—only online.

Harinarayan’s team is also trying to tackle a new problem for Wal-Mart. Last year the chain was the No. 1 destination for holiday shoppers, with 53 percent of U.S. customers visiting its stores. That was down from 59 percent the year before. To lure gift shoppers, the techies have developed a Shopycat feature that scans the social media preferences of a consumer’s Facebook friends and suggests gift ideas sold on Walmart.com. About 150,000 users have installed the app.

To roll out more such innovations, Wal-Mart must improve its in-house e-commerce technology, so King will hire 87 engineers and coders to bolster the links between the stores and the website. “We’re starting from scratch to build a foundation,” says the EBay (EBAY) veteran. “Ideally, we’d have this platform built a couple of years ago.”

 

The bottom line: Wal-Mart, which gets less than 2 percent of its U.S. sales online, aims to bolster its technical capabilities to compete with Amazon.