TO GET some idea of the scale of Foxconn’s Longhua campus in Shenzhen, in southern China, a visit to its massive central kitchens is all that is needed. They lie at the heart of this sprawling complex of factories, dormitories, sports facilities, banks and stores built by the secretive Taiwanese-owned firm. The food-preparation centre, spread over 12,500 square metres on four storeys, goes through three tonnes of meat a day as it prepares grub with military precision.

The enormous scale is to be expected, given that Foxconn (also known by its parent company’s name, Hon Hai) is the world’s largest contract manufacturer. The Longhua campus, covering 2.5 square kilometres, employs 240,000 people. Across China, it employs 1.4m on 28 campuses (see chart). Nor, given the firm’s prowess at churning out gazillions of gadgets like Apple’s iPhones, does the kitchen’s efficiency come as a surprise. Tens of thousands on each shift pay for meals swiftly by swiping cash cards loaded with 400 yuan ($64) a month in food credits. The only things more impressive than the size of the canteen’s woks—more than 1 metre wide—are the firm’s spectacular growth and outsized ambitions. In the past decade it has gone from being one of many invisible firms in the electronics supply chain to the world champion of flexible manufacturing. Barclays, a bank, forecasts that the company’s revenues will exceed NT$3.9 trillion ($134 billion) this year. Foxconn is investing heavily to expand in the interior of China. By the end of this year its newish facilities in Zhengzhou, in Henan province, will employ more workers than the Longhua campus. It is also expanding in Brazil and Mexico. There are rumours it might even open a factory in America, since Apple, its biggest customer, has just declared that it plans to have some of its Mac computers made at home. Rich-world companies looking to follow suit, “reshoring” jobs back home, are struggling to find enough skilled manufacturing workers; Foxconn could apply to Americans its extensive experience of training Chinese workers from scratch. It admits it is “exploring the opportunity”. More strikingly, Foxconn believes it can double in size yet again. Executives talk of becoming one of the world’s top 20 businesses. This is no fantasy: Barclays foresees Foxconn’s revenues growing by 15-20% a year in the coming three years. There are two main obstacles to sustaining such growth: finding and retaining good workers in China, and improving the firm’s anaemic profit margins. Both problems will only be aggravated by growth.

As good employees become scarcer, Foxconn is having to pay more attention to working conditions—an issue on which it has attracted much unwelcome publicity. A lunchtime visit to the Longhua campus suggests that nowadays life there is not so bad. Off-duty workers smoke and fiddle with their mobile phones on the kerb outside the production halls, snooze on the campus’s football pitch or sit crocheting together in their dorms. Employees on an assembly line making corporate IT equipment look bored senseless but the facilities are orderly and spotless—a far cry from South Asian firetraps.

When your correspondent requested an unscheduled visit to an assembly-line workers’ dormitory, officials immediately obliged and remained outside the dorm’s entrance. The women inside, who bunk eight to a room in basic but decent conditions, were unafraid and in good humour. People on campus dress in casual clothes, not company uniforms, and seem only about as discontented as the youth found in any Chinese city. Look closer, though, and you notice something jarring: enormous safety nets hung on many buildings to prevent suicide jumpers.

That hints at Foxconn’s biggest challenge: demography. No longer can the firm rely on a steady supply of migrant workers grateful for any escape from grinding rural poverty. The country is rapidly ageing, and the pool of hungry young workers is shrinking. Besides expecting ever better pay and conditions, today’s new recruits want more fulfilling lives than those their predecessors put up with.

Until recently Foxconn was unyielding in its discipline and working practices. But two years ago a spate of suicides led to a global outcry that shook the firm. Since then, several outbreaks of worker unrest and noisy campaigns by activists have further blackened its name. In response, Apple requested that the Fair Labour Association (FLA), an American watchdog, audit its suppliers. A report issued by that group in March found that although Foxconn’s facilities were “no worse than any factory in China” there were violations of the FLA’s code of conduct.

Peter Deng, a manufacturing director at the firm, recalls that a decade ago Foxconn gave only one or two days off per month and there was no limit on overtime—“and the workers didn’t mind.” Now, the firm claims to limit overtime and to insist that workers take a day off every week. It is also increasing wages and, after scandals, limiting the use of interns (about 2.7% of its workforce). In August the FLA said that Foxconn was “ahead of schedule” in improving conditions.

Fine, but if Foxconn wants to keep booming, it must do far more. The canteen visit hints at three ways it plans to improve workers’ lives.

First, automation. It takes just three people to prepare the eight tonnes of rice consumed at lunch. The assembly lines are next. Terry Guo, the company’s flamboyant chairman, has vowed to build “one million robots” in an effort to eliminate mind-numbing tasks and move towards fully automated plants. The challenge is that tastes change quickly in consumer electronics. By the time bespoke robot kit is ready to automate a given factory line, the product mix has changed, making it obsolete. Scepticism is warranted, but insiders believe the firm is just a year away from breakthroughs that work at scale on commercial lines. Such “Foxbots”, and related services, could even be sold to other firms.

Second, a bit of freedom. Workers can now skip the canteen, instead swiping meal cards at food courts on campus or going off campus to eat. They also now get a housing allowance, letting them choose between staying in dorms or (as 70% now do in Shenzhen) living off campus. There is more of a social life, too: a young employee, recently arrived from remote Xianyang, talks blushingly about her evenings with handsome co-workers at the Cyberfox, the campus internet café.

Third, outsourcing. The dorms, catering, security and much else at Longhua are now run by outsiders. Louis Woo, special adviser to Mr Guo, insists this is not to save money but to improve workers’ quality of life: “they simply do a better job than us.”

Going west

Foxconn’s net margin has already fallen from above 6% a decade ago to around 2% now. It risks being squeezed further as the firm splashes out to attract and retain new workers. The trouble is, Foxconn is stuck in the hyper-competitive middle of the electronics supply chain. Upstream, the designers of components make enormous margins, as do the firms downstream that market the finished products. But midstream gadget assemblers do not. In China, it costs Apple a few dollars to have an iPod assembled, which it then sells for $299.

Could Foxconn’s push towards cheaper inland provinces boost margins? Not for long. Because of tax holidays granted to its new plants, the firm’s effective tax rate will drop from 25% in 2011 to 16-18% this year. But the gains will soon be eroded by higher inventory and logistics costs (because of the more remote locations), rising pay and fading subsidies. Within a few years, argues Alberto Moel of Sanford C. Bernstein, an investment bank, the shift will bring “no net benefit to gross margins.”

Dull work, but not dangerous Still, Mr Guo does have a strategy for increasing margins. First, he is moving upstream. In March he announced plans to buy a stake in Sharp, a troubled Japanese technology firm, and to help finance Sharp’s glass-panel research. (When Sharp’s shares later plunged, he waffled when asked to reconfirm the stake-buying.) Already, almost everything Foxconn makes has glass display screens—and this week it was reported to be working with Apple and Sharp on a new range of high-definition televisions. Foxconn wants to learn how to make screens better and cheaper. By using its manufacturing savvy to scale up any breakthroughs, it plans to boost Sharp’s sales—pocketing a share of the gains. Other such deals are likely. Mr Guo is also pushing downstream into retailing. He does not want Foxconn to create its own consumer brands; the idea is to use the firm’s supply-chain muscle to help its branded customers promote their products, by guaranteeing retailers that they will get their supplies on time and on demand. To help with this, it has taken stakes in several retail chains in China, including the local operations of Media Markt, a German electronics seller. Foxconn says branded manufacturers, especially Western ones with poor penetration in smaller Chinese cities, will benefit from its promotion of their products, shops will be able to hold lower inventories and consumers will enjoy lower prices. Analysts are doubtful. But if this takes off over the next five years, the firm also plans to tighten its links further with retailers by letting them tap directly into Foxconn’s internal e-commerce portal. These moves may pay dividends in the long term. But Mr Moel argues that quicker returns are to be found in the company’s core manufacturing operations, for instance by making more parts in-house. Foxconn is increasingly making components such as batteries, lenses, speakers and touch panels. It has scope to improve the efficiency of its production lines, especially on new campuses purpose-built for automation. The firm could also try demanding higher prices. There are signs that it is ready to move away from a low-price strategy, instead stressing reliability and high-volume capabilities.

Can Foxconn really persuade Apple, the world’s most powerful electronics firm, to cough up more money? That risks alienating a customer that accounts for 40-45% of its revenues. But as the world’s largest outsourced manufacturer grows even bigger, it is becoming ever more indispensable to Apple as well. In the end, that is the best thing Foxconn has cooking.