On a teeming street in Mumbai's Dharavi slum, amid a colorful swirl of sweet lime carts and red-clay pottery, Pastor Bala Singh brings an assortment of buckets to retrieve his daily ration of water. The indoor spigot he uses provides water only three hours a day. It is the only source for the six small homes on his street, and each family has 30 minutes to fill its containers.

Pastor Singh is not complaining, though. Things are greatly improved from when he first immigrated to Dharavi – the most crowded part of one the world's most crowded cities. "The roads were muddy," he says from his second-floor office, above the popping sizzle of a man welding, sans protective gear, downstairs. "Now they put down bricks." Singh ministers to a small congregation that meets above the church-sponsored kindergarten where his wife has taught for 17 years. Though relatives have begged him to come home to Tamil Nadu, 700 miles east, he has no plans to leave.

"Three times I tried to go back to my native place," the pastor says, explaining that there were no jobs there. "I don't want to live here ... but God's plan is different."

Singh's migration to the city, a combination of divine impulsion and the simple need to work, is part of what could be called an epic trend affecting billions of people worldwide. Sometime in 2007, for the first time in human history, more people began to live within the cacophonous swirl of cities than in rural hamlets or on countryside farms.

It's a fundamental shift that may be altering the very fabric of human life, from the intimate, intricate structures of individual families to the massive, far-flung infrastructures of human civilizations. In 1950, fewer than 30 percent of the world's 2.5 billion inhabitants lived in urban regions. By 2050, almost 70 percent of the world's estimated 10 billion inhabitants – or more than the number of people living today – will be part of massive urban networks, according to the Population Division of the United Nations' Department of Economic and Social Affairs.

These staggering statistical trends are driving the evolution of the "megacity," defined as an urban agglomeration of more than 10 million people. Sixty years ago there were only two: New York/Newark and Tokyo. Today there are 22 such megacities – the majority in the developing countries of Asia, Africa, and Latin America – and by 2025 there will probably be 30 or more.

Consider just India. Though the country is still largely one of villagers – about 70 percent of India's 1.2 billion inhabitants live in rural areas – immigration and internal migrations have transformed it into a country with 25 of the 100 fastest-growing cities worldwide. Two of them, Mumbai (Bombay) and Delhi, already rank among the top five most populous urban areas.

In the "developed" countries of the West, this trend had been building since the Industrial Revolution, which sparked, relatively quickly, the exponential growth of cities seen today. The quest for "efficiency" and the corresponding divisions of labor generated technological innovations that obliterated the need for farm laborers and local artisans. This drove populations from the country to the city over time and transformed the plow and the hoe into mere tools for backyard gardeners.

Today, on average, 3 out of 4 people living in modern industrialized states are already building their lives within an urban area – a ratio that will jump to more than 5 in 6 by 2050. By contrast, today in the least-developed regions of the world, more than 2 out of 3 people still eke out a living in a rural area. For these people, even the slumdog existence in places like Dharavi can offer more opportunities than their villages ever could. And within these developing regions, according to UN-HABITAT, cities are gaining an average of 5 million new residents – per month.

"Most of these [urban immigrants] couldn't earn cash in their rural situations," says Chuck Redman, director of the School of Sustainability at Arizona State University in Tempe. "There's not as much of a cash economy there, but they still want cash to buy radios and mobile phones or TVs – or even send their kids to school, which costs money in many of these countries."

Call it the lag of modernity: The changes wrought by industrialization began slowly 200 years ago, accelerated through the 20th century in the West, and now are spreading exponentially around the globe. Many observers see great promise in this urbanizing trend: The efficiencies of cities can cut energy consumption up to 20 percent, transportation costs for goods and labor can drop significantly, and entertainment industries can thrive when millions live together. In other words, cities are giant cash machines, the primary locus of economic growth.

"Some companies look at this as a huge opportunity," says Fariborz Ghadar, director of Penn State's Center for Global Business Studies and the author of a book on megacities. "We're going to build roads, we're going to build buildings, and [tech companies] love this because you can put the Internet in concentrated cities much more efficiently."

Yet, as megacities evolve in the developing world, many groan under the weight of a sudden, massive, and unprecedented demand for services never seen in the West. The basic necessities of clean water, of sanitation systems to remove megatons of garbage and human waste, of transportation systems to shuttle millions of workers, not to mention the need for electrical networks, health-care facilities, and policing and security, are, simply put, creating one of the greatest logistical challenges ever seen in human history. And this is even before factoring in the challenges of climate change, terrorism, and the preservation of human dignity.

Mexico City: on a bowl of pudding

An orange metal elevator heads deep into the bowels of Mexico City, where a crew of technicians and engineers is inspecting a 900-ton machine, longer than a football field, that burrows through a muddy mélange of rock, silt, and water. It's the first stage of the city's plan to build a massive new tunnel that officials hope will relieve the pressures on Mexico City's drainage system.

Nearly 1,000 feet into the passageway, made up of adjacent rings each composed of concrete slabs weighing some 4 tons each, the air is thin. Oxygen roars in through a tube, providing relief for those working on the project's edge. Workers crawl along scaffolding, crouching under an Erector Set of tanks and pipes that pump out water and hurl the deep-earth's rock and mud to the surface.

Their task is to prevent large portions of Mexico City, one of the world's most populous megacities, from catastrophic flooding. The area's growing population has placed demands on water supplies that are simply unsustainable. Its 20 million residents have laid down an urban jungle that obstructs water from naturally filtering into the ground.

Today, the city is sucking up water from the natural aquifers at twice the rate they are being replenished. The result: Mexico City is sinking, in some areas up to 16 inches a year, threatening its entire infrastructure. This includes the city's deteriorating drainage system, whose capacity has diminished by 30 percent since 1975 while the area's population has doubled.

"It's an alarming situation," says Felipe Arreguin, the technical general subdirector at Mexico's National Water Commission (Conagua), which is building the drainage tunnel. "We are taking [out] so much water, the city is sinking. What if an entire block were to go under?"

It nearly has. In 2007, a giant sinkhole swallowed a large swath of a busy street. At Revolution Monument, a water pipe installed over 75 years ago now stands near nearly 30 feet above ground. Given Mexico City's history as a "floating city" in the middle of a lake, it's no surprise that water is what vexes most urban planners here. When the Spaniards arrived to conquer the great Aztec Empire, the mode of transportation was not horses but canoes. Today, the city sits essentially on a bowl of pudding. Jose Miguel Guevara, the general coordinator for water supply and drainage projects at Conagua, calls this basin a giant "saucepan," with no natural exit for the torrential rains that fall each year. But these drainage problems and the corresponding threats of catastrophic flooding belie one of the great ironies of its urban plumbing. When it comes to water, the city is also facing the kind of shortages that plague the rest of the globe. Mexico City, which sits at an altitude of over 7,300 feet, must pump water up 3,000 feet to reach residents. Last year it had to ration water after one of the worst droughts in six decades. The drainage program includes plans for treatment plants to turn runoff into clean water for use by farmers.

These problems, and the enormously complex engineering and plumbing challenges they create, reveal a much larger global concern. Like Mexico City, megacities around the world must find ways to control runoff while providing clean water for millions of inhabitants. With 1.1 billion people – or 18 percent of the world's population – now lacking access to safe drinking water, according to the World Health Organization, governments of developing countries need the money and know-how to build massive public works.

In São Paulo, Brazil, for instance, planners are struggling to cope with a drainage system that was built when the city was a fraction of its current size. Poor maintenance has left much of it clogged, while forest and parkland have given way to haphazard housing in many areas of the world's third-largest city. Now there are fewer green areas to soak up incessant rains.

"Irregular construction and expansion have taken place in areas that the rain runs into, and, as the weather has been so bad over the last six months, these areas that act as natural reservoirs have become flooded," says state meteorologist Marcelo Schneider. "Now they are occupied, but people shouldn't really be there. It is the poor that suffer."

Beijing: The commute that never ends

Zhao Ning lives just outside Beijing's Fifth Ring Road, one of the massive concentric expressways that circle the center of China's second-largest city. She wakes up at 5:30 a.m. each workday morning, quickly puts on makeup, and then rushes out to catch her first bus for her interminable commute to work. She barely has time for breakfast.

She transfers to a second bus, which takes her to the subway. Then she transfers twice more, needing three different lines to make her way to another bus that will take her to her office in northwest Beijing, where she is the associate director of an American study-abroad program. The subway system is only two-thirds the size of New York's, but it carries the same number of daily commuters, more than 5 million.

"Each day I spend four hours on the road," she says. "It is very exhausting and it puts so much pressure on me, especially in the morning."

Despite Beijing's modern, well-kept web of beltways and feeder roads into the city, driving is not an option now for Ms. Zhao, even though she and her husband own a car. Like most sprawling megacities, traffic – and the resulting, oft-reported pollution problem – is a constant urban plague. More than 4 million cars jostle along Beijing's roadways, with nearly 1,300 added every day, according to the city's Traffic Management Bureau. In April, the city began to adjust the working hours for nearly 810,000 of these commuters, hoping to alleviate the morning and evening rush.

When Zhao once tried to drive, her car was quickly entombed in traffic. "I was so worried – like an ant dancing in a hot pan," she says, using a classic Chinese expression. "Since then I haven't driven to work."

Indeed, along with water and sanitation, the challenges of mobility virtually define the growth of megacities. At the same time, they reveal the profound social and political upheaval the world's transition to city life can create. Cities bring economic growth and the expansion of the middle class. Members of the middle class want to own property – homes and, increasingly, cars.

That is certainly the case in São Paulo. Brazil's economy has grown enormously over the past few years and a full 15 percent of the nation's gross domestic product is based here. The country's family aid programs and a progressive government have helped more than 20 million people become middle-class since 2000. Big-ticket items like cars and houses are now within reach. More than 600 additional vehicles hit São Paulo's roads every day.

"One of the main characteristics of the city is that it grows horizontally," says Dr. Marcel Solimeo, the chief economist of the São Paulo Commercial Association, an interest group. "Housing is further and further away, and jobs are concentrated in the city center. The amount of time we spend getting to work is enormous."

The city and state have added bus lanes, and authorities have put restrictions on trucks and other big vehicles. But it is the city's nascent rail system that holds the key to easing gridlock on the roads. São Paulo currently has just 37 miles of rail line. The city hopes to expand that sevenfold by the time it hosts the soccer World Cup in 2014

"All investments were based on cars, but that is starting to change and the focus is moving towards organizing public transport," says Antonio Carlos Barrossi, an urban expert at the University of São Paulo. "Now it is about people. It is late, but it is important."

A major problem confronting expanding cities is how to graft new subways and sewer systems onto existing neighborhoods. In China, authorities have tried to circumvent that by creating entire cities from scratch. As part of the government's aggressive urbanization program, it has poured large resources into building new communities, especially deep within the mainland. In fact, many of the most educated Chinese professionals on the coast have never heard of cities in their own country, some with populations the size of Houston.

In 1980, only 51 cities with more than 500,000 people existed in China, according to UN figures. Since then, that number has jumped to 236. By 2025, the UN estimates, China will add 100 more cities to this group, as it pursues moving millions of rural peasants into vast urban networks. And with its robust rate of economic growth, China has the money to pursue the theorem, "If we build it, they will come." Its centralized political system also makes it easier to plan new urban networks without significant resistance.

India, by contrast, is a democracy that must confront layers of competing political interests as it plans new large-scale projects for its megacities. The building of the Bangalore airport, finished just last year, took more than 15 years to plan and develop, and many consider the process a disaster.

Yet the massive migration to cities is causing challenges beyond taxed sewer systems and tribal politics. Mumbai, for instance, is experiencing the arrival of 500 newcomers a day, many of whom compete with locals for jobs. This has caused a backlash among regional politicians, who are trying to pass laws to preserve work for area residents.

"While European cities are struggling with multiculturalism [from other countries], we are coping with cities that have huge proportions of internal migrants – and internal migrants who are still diverse," says Amita Bhide, an urban expert at the Tata Institute of Social Sciences in Mumbai.

In China, the effects of massive urbanization may be more political. As its middle class grows, the freedoms that come with greater wealth could put more pressure on Beijing to open up its political system.

For now, though, people like Zhao are simply enjoying the allure of urban life. "I think the most attractive thing about big cities like Beijing is the invisible halo it brings to me," says Zhao. "My friends back home think I'm amazing that I can survive and even have a good life in a big city like Beijing."

Tokyo: the megacity that works

Zhao's friends raise a basic question: As the world tilts inexorably urban, will the megacities of tomorrow even be livable? Experts point to cities like Lagos, Nigeria, as the kind of urban beehive that doesn't work – traffic, untold pollution, the lack of even the most basic services.

Yet other megacities have certainly found the right blend of concrete and urban cachet. Most notable is the world's largest urban conglomeration – Tokyo. Though the multitudes in Tokyo proper are shoehorned into a relatively small area, the city consistently ranks near the top in surveys of the world's most livable places. It boasts high-quality goods and services, a wealth of world-class restaurants, and an enviable choice of museums, galleries, and architectural wonders.

But its near-faultless transportation system may be the most impressive and efficient means of public mobility ever built. Many residents cite the ease with which they can explore their city as a primary reason Tokyo is a desirable place to live.

"You can be anywhere in the city within an hour, easily," says Mami Ishikawa, a university student.

Outside Shinjuku Station, the busiest train station in the world, a swarm of 3.64 million commuters per day spill out onto the streets, seemingly in unison, via countless exits and well-designed traffic lights. Innovative "cycle trees," multilevel mechanized parking lots for cyclists, make it simple to get around without a car.

Yet Tokyo's urban efficiency is due as much to social factors as it is to its transportation system and technological prowess. "Cultural aspects, such as the Japanese penchant for order, respect for social rules and norms, and reluctance to intrude on others' private realms is also very important to minimizing friction," says Julian Worrall, an expert at Waseda University.

Undeniably, Tokyo has its challenges: high costs, dense living, patience-sapping gridlock for those brave enough to drive. Mr. Worrall points to aesthetic deficiencies, too – the spread of high-rise condos, the lack of urban space devoted to something other than consumption and production.

Maybe so. But to someone like Pastor Singh, who has to line up each day in Mumbai just to get water, those might seem like petty annoyances.

• Staff writer Sara Miller Llana in Mexico City and correspondents Taylor Barnes in Mumbai; Zhang Yajun in Beijing; Justin McCurry in Tokyo; and Andrew Downie in São Paulo, Brazil, contributed to this report.

Related stories:

Earth’s big problem: Too many people

Sustainable population, minus the control