Earlier this year ominous headlines blared that Cape Town, South Africa, was headed for Day Zero—the date when the city's taps would go dry because its reservoirs would become dangerously low on water. That day—originally expected in mid-April—has been postponed until at least 2019 as of this writing, thanks to water rationing and a welcome rainy season. But the conditions that led to this desperate situation will inevitably occur again, hitting cities all over the planet.

As the climate warms, extreme droughts and vanishing water supplies will likely become more common. But even without the added impact of climate change, normal rainfall variation plays an enormous role in year-to-year water availability. These ordinary patterns now have extraordinary effects because urban populations have had a tremendous growth spurt: by 2050 the United Nations projects that two thirds of the world's people will live in cities. Urban planners and engineers need to learn from past rainfall variability to improve their predictions and take future demand into account to build more resilient infrastructure.

How did Cape Town get into a Day Zero situation? The city gets its water from six reservoirs in Western Cape province, which usually fill up during the rainy season, from May through August. But since 2015 the region has been suffering from the worst drought in a century, and the water in those reservoirs dwindled perilously. Compounding the problem, Cape Town's population has grown substantially, increasing demand. The city actually did a pretty good job of keeping demand low by reducing leaks in the system, a major cause of water waste, and has even won awards for its conservation policies. But the government of South Africa was slow to declare a national disaster in the areas hit hardest by the drought, paving the way for the recent crisis.

Cape Town is not alone. Since 2014 southeastern Brazil has been suffering its worst water shortage in 80 years, resulting from decreased rainfall, climate change, poor water management, deforestation and other factors. And many cities in India do not have access to municipal water for more than a few hours a day, if at all. For example, the city of Shimla ran out of drinking water in May, prompting locals to beg tourists to stay away from the popular Himalayan summer retreat. The water infrastructure in many Indian cities is old and leaky, but city governments have not repaired it. Municipalities have, however, given free electricity to farmers for irrigation, depleting local groundwater stocks.

In the U.S., the situation is somewhat better, but many urban centers still face water problems. California's recent multiyear drought led to some of the state's driest years on record. Fortunately, about half of the state's urban water usage is for landscaping, so it was able to cut back on that fairly easily. But cities that use most of their water for more essential uses, such as drinking water, may not be so adaptable. In addition to the problems that drought, climate change and population growth bring, some cities face threats of contamination; crises such as the one in Flint, Mich., arose because the city changed the source of its water, causing lead to leach into it from pipes. If other cities are forced to change their water suppliers, they could face similar woes.

Fortunately, steps can be taken to avoid urban water crises. In general, a “portfolio approach” that relies on multiple water sources is probably most effective. Cape Town has already begun implementing a number of water-augmentation projects, including tapping groundwater and building water-recycling plants. Many other cities will need to repair existing water infrastructure to cut down on leakage.

Metropolitan leaders should be thinking about meeting long-term needs rather than just about daily requirements. Good organization and financial accountability are equally critical. And planning efforts should include diverse stakeholders from the community. One major challenge is providing services to informal areas, which develop haphazardly, without any government foresight. Such regions often lack basic resources—a well-planned water supply among them.

The global community has an opportunity right now to take action to prevent a series of Day Zero crises. If we don't act, many cities may soon face a time when there isn't a drop to drink.