Six months ago Cape Town was a city on edge. The mayor had declared that Day Zero, when officials would shut off water to most homes and businesses in order to preserve fast-shrinking reservoirs, was imminent. Police began to ticket individuals for washing taxis, watering lawns, or otherwise wasting water.

Residents responded to the panicked messages from City Hall with their own panic. They queued for hours to fill bottles at local springs. They hoarded water. They took showers while standing in buckets and rejiggered their home plumbing to reuse water from laundry machines.

By July, Cape Town looks to have evaded a water catastrophe, at least for this year. Residents are using substantially less water. Severe water supply restrictions instituted on agriculture and city dwellers alike, and a heroic, last-ditch conservation effort halted the swift drop in reservoir levels. Winter rains are now providing some relief. The amount of water stored in the reservoirs more than doubled in the last month and rivers in the Western Cape swelled in downpours. Snow graced the mountain peaks. The start of the wet season this year is more promising than any of the last three.

The near-death experience, though, is revealing for the gorgeous seaside city at the southern tip of Africa. And it offers lessons in the immense challenges fast-growing and drought-prone cities all over the world face in making adequate supplies of water available in the era of intensifying hydrological disruption. Other big cities also contend with severe water shortages, some that prompt civic violence. They include Beijing and São Paulo; Chennai, New Delhi, and Bangalore in India; Karachi, Amman, and Mexico City.

The Western Cape drought and the subsequent receding of Cape Town’s reservoirs exposed individuals and businesses to months of hardship and anguish. It laid bare the inadequacies of institutions, laws, and leadership to recognize and respond quickly enough to severe water shortage. The drought magnified the city’s racial and economic divides, which are legacies of apartheid.

It also unveiled the precarious risk calculations that local and national authorities charged with safeguarding Cape Town from just such an emergency had to make. Those authorities and their agencies have been aware for years of vulnerabilities in the Western Cape water system. They even drew up careful plans to address weaknesses. Yet after more than a decade of planning, and regular meetings to discuss drought-related risks, they determined that they could keep delaying the date at which they needed to invest in new water supplies. As it turns out, they waited too long. Severe drought took hold and the Cape Town region slid to the brink of catastrophe.