LILY LI wears a lanyard with a little plastic card around her neck, even at weekends. It is a badge of honour: it shows that she has a white-collar job. (She is a secretary at Access Asia, a retail-research company in Shanghai.) She uses Apple earphones for the cheap Chinese mobile phone in her pocket, so it looks as if she owns an iPhone. And she drives to work, though it takes four times longer than public transport, just to show off her little car.

After decades of deprivation and conformism, Chinese consumers regard expensive consumer goods as trophies of success. In public, they show off. In private, they pinch pennies. The owner of a gleaming new BMW will drive around for half an hour to avoid a 50 cent parking fee. And she will hesitate to spend much on interior decoration, because only her family sees the inside of her flat.

By some forecasts China will be the second-largest consumer market in the world by 2015, not far behind America. Chinese people already buy more cars than people in any other country: 13.5m last year to Americans' 11.6m. China is on its way to becoming the biggest luxury-goods market. The central government made an increase in domestic consumption one of the priorities of its latest five-year plan.

Small wonder that Western firms are piling in. On July 4th Nestlé, the world's largest food maker, confirmed that it is in talks with Hsu Fu Chi, one of China's biggest makers of confectionery and baked goodies, with a view to buying the firm.

If a deal is sealed, it would be one of the largest foreign takeovers yet seen in China: Hsu Fu Chi is valued at $2.6 billion on the Singapore stock exchange. China is currently Nestlé's ninth-biggest market, with sales of SFr2.8 billion ($2.7 billion) last year. That is less than half what Nestlé sells in Brazil, although China has seven times Brazil's population. Hence Nestlé's hunger for Hsu Fu Chi's distribution network, and for its knowledge of what tickles Chinese taste buds.

“Understanding the consumer is the most important thing for us,” says Paul Bulcke, the boss of Nestlé. The food business is more local than almost any other—trying to sell cheese in China is like trying to sell stinky tofu in Switzerland. Nestlé has been sniffing around for takeover targets in China for the past two years. Hsu Fu Chi is not its first bite. In April it took a controlling stake in Yinlu Foods Group, a family-owned maker of peanut milk and canned rice porridge.

Multinational firms trying to woo Chinese consumers have so far concentrated on the country's thriving coastal regions. P&G, an American maker of shampoo, toothpaste and other sundries, has its Chinese headquarters in Guangzhou. Its Anglo-Dutch rival Unilever's home is in Shanghai. Yet both firms are preparing for a “second consumer revolution” among the 665m Chinese who live in rural areas. The income gap between China's coastal cities and rustic interior is still six-to-one, but rural incomes are rising and 665m heads could use a whole lot of shampoo.

The Chinese government presents its own unique challenges. “Everything is political,” says James McGregor, a former head of the American Chamber of Commerce in China. “This is a government that lets foreign companies build market share when it needs them.” Its longer-term goal is to learn enough from foreigners so it can build its own national champions. To this end, it pushes foreign carmakers, among others, into unhappy partnerships with Chinese state-owned firms.

Almost all Western consumer-goods makers have felt Beijing's heavy hand. Bernard Arnault, the boss of Moët Hennessy Louis Vuitton (LVMH), a luxury-goods firm, was summoned by the Chinese ambassador in Paris in 2008 for a high-decibel dressing down after Nicolas Sarkozy, France's president, said he would meet the Dalai Lama. In the following weeks scores of women marched into Louis Vuitton shops in China with fake Louis Vuitton handbags and brazenly demanded their money back.

Unilever got into trouble recently for hinting that the price of some of its products would rise. The Chinese government is terrified of inflation, which it fears might spark unrest. It accused Unilever of inciting shoppers to hoard its products, and slapped it with a hefty fine. Yet Harish Manwani, Unilever's chief operating officer, is undeterred. He is planning to increase Unilever's business in China four- or fivefold in the next few years.

Buttering up local party bosses

The central government is not the only problem. Companies need to cultivate cordial relations with local potentates, too. Often the provincial governor's say-so is needed to obtain land, employment licences and a stack of other bits of paper a firm needs to operate. Local party bosses tend to favour local Chinese firms—another reason why tie-ups can be helpful.

Another big challenge for Western multinationals is that their Chinese rivals are catching up fast. “Domestic players will be ferocious competitors,” predicts Derek Sulger at Lunar Capital, a private-equity firm in Shanghai.

For now, Western firms enjoy a lucrative reputation for quality and safety. Lead pollution from local tinfoil-making workshops in Zhejiang province recently injured 103 children and scores of adults. Chinese consumers are as averse as anyone else to being poisoned, so such incidents persuade many to buy Western brands. But domestic companies can make things much more cheaply, and their quality is improving.

Some Western consumer-goods firms that are also-rans at home do surprisingly well in China. Back in America, Kentucky Fried Chicken (KFC, part of Yum! Brands) is dwarfed by McDonald's. In China it has 3,300 restaurants—more than three times as many as its rival—and opens a new one each day. The secret of its popularity is local managers with the freedom to adapt KFC's offerings to the Chinese palate. That means fewer bargain buckets of wings and more congee, a rice porridge with pork, pickles or mushrooms.

Other Western firms can't cope. Home Depot, an American DIY chain, is retreating from China after trying for years to persuade middle-class Chinese people to decorate their own homes.

Home Depot “didn't understand the market for home decoration,” says Ben Cavender at China Market Research in Shanghai. Chinese people typically have no garages in which to store tools. And there are legions of poor people who will paint and decorate for low wages. The middle classes tend to hire decoration companies, which subcontract to whichever construction firm pays the best kickbacks. At the beginning of this year Home Depot closed its last shop in Beijing. It now has only seven stores on the Chinese mainland.

In a recent report on market dynamics and a profile of the Chinese consumer, Bernstein Research offers several tips to help Western consumer-goods firms profit from the “second consumer revolution”. Don't offer too many brands: offer only a few, but produce in quantity to exploit economies of scale. Keep improving your products and (crucially) the packaging; otherwise you won't keep pace with such a fast-changing market. Build an efficient distribution network early on—delivering goods to inland shelves is hard. And court talent tenaciously. Few employees are loyal, and few want to work in the countryside, even if they were born there. Finally, be patient. It may be years before your Chinese operations make money.

Bernstein could have added: beware. The rules in China are still being written. Different arms of government may interpret them differently (see next article). And if someone in power changes his mind, there is not much you can do about it.

Will the Chinese government allow Nestlé to buy Hsu Fu Chi? In 2009 it rejected a $2.4 billion bid by Coca-Cola to buy Huiyan Juice Group, a drinks firm, for no apparent reason. Analysts say that this is unlikely to happen again, however. “The company is not strategically important and together Nestlé and Hsu Fu Chi would control only about 5% of the market,” says Jon Cox at Kepler Capital Markets in Zurich. As the world's largest chocolate-maker Nestlé has high hopes for a market of more than a billion people who currently eat shamefully little chocolate.

Much could go wrong. Many economists think Chinese households save too much. Some fear a property bubble or a banking crisis. The risks of selling consumer goods in China are immense. But so is the opportunity cost of staying away.