Late in the summer of 2012, while walking his coffee groves on a hillside rising above Santa Ana, El Salvador, Mario Mendoza Corleto noticed something unusual: the leaves on some of his trees were coated with an orange fungus and had begun dropping to the ground. It was “leaf rust,” a form of blight that had pestered coffee farmers in El Salvador since the 1970s. Normally, spraying the trees with fungicide once or twice a year would keep the disease at bay. Not anymore. “This year it was totally different,” Mendoza recounted to me recently. “Spraying didn’t help.”

As the days wore on, the problem only worsened. By September, many of Corleto’s once-bushy trees stood completely bare. Their green fruit hardened in the sun, never ripening into the candy-red cherries that Mendoza’s workers would pick and process into coffee beans destined for specialty roasters. That year, half of the trees on his family’s 100-year-old farm died. The next year, as Mendoza’s remaining trees continued to struggle, he laid off most of his workers. The harvest was a quarter of its usual size.

What happened to Mario Mendoza Corleto played out all across El Salvador, as well as Honduras and Guatemala: ground zero for the Western hemisphere’s most prized coffees.

For the next two years, la roya, as leaf rust is known locally, tore through Latin America’s coffee farms, infecting as much as half of the total acreage, inflicting over $1 billion worth of damage, and helping to trigger a migrant crisis as farmers and farmworkers fled economic ruin.

Coffea arabica is one of the least genetically diverse — and therefore, least resilient — modern crop species on earth.

How did leaf rust suddenly gain the upper hand? Researchers think the disease, a fungus that evolved with coffee trees in the forests of Ethiopia, may have undergone a major recent mutation to become more aggressive. Meanwhile, climate change created the warm, wet weather conditions that sent it into hyperdrive, breaking through coffee’s natural disease resistance.

Leaf rust’s sudden fury did more than devastate individual farmers. It exposed a surprising weakness at the root of the $175 billion global coffee business. Coffea arabica is one of the least genetically diverse — and therefore, least resilient — modern crop species on earth. The trees that growers plant today, especially for the most coveted coffees, haven’t changed much since the 19th century. As one insider put it, “the whole industry is running on software that’s 150 years old.”

Since 2012, the leaf rust has retreated, thanks to a combination of milder weather and diligent control efforts in the fields. But researchers are certain that it will return — some believe as soon as next year — which would mean walloping farmers already suffering from both low prices and yields that haven’t fully recovered from the last outbreak.

For people who grow good coffee, sell it, or simply like to drink it, that’s a major problem. And it’s why one group of scientists, bankrolled by the coffee industry, is racing to bring coffee cultivation into the 21st century before it’s too late.

In recent decades, the third wave coffee movement has transformed coffee from a mere commodity — sold in bulk, and more or less interchangeable in taste — into a specialty beverage with a connoisseurship culture that rivals wine. Venti Frappuccinos have given way to three-minute pour-overs. Dollar coffees are an endangered species. In some circles, it’s no longer considered eccentric to travel with your own handheld burr grinder and vacuum extractor to ensure a good cup is always within reach. But while coffee culture has evolved, coffee agriculture has not. Even as we place increasing value on flavor and quality, the world’s best coffees are becoming more and more vulnerable to leaf rust and the many other ravages of climate change.

Worldwide, we plant two species of coffee: Coffea arabica and Coffea robusta. Robusta, as the name would suggest, is a vigorous, low-maintenance tree that stands up to diseases and pests, but it produces harshly flavored beans that are mostly used for instant coffee, or to cut better quality stuff in mass-market brews. Suffice it to say, you don’t want to be stuck drinking Robusta for the rest of eternity. Arabica, which accounts for over 60 percent of global coffee volume, is the hero of our tale. The plant is finicky and demanding, but the beans it produces have the smoother, more nuanced flavor profiles that humans have come to know and love.

The Arabica we grow today commercially uses only a fraction of the species’ total genome. It lacks the genetic vigor it needs to adapt to climate shocks such as drought, heat, flooding, and leaf rust.

Modern food crops aren’t usually quite so high-strung, but Arabica has a curious backstory. In the sixth century, a small number of coffee beans (which are also coffee seeds) were exported from the high plateau forests of Ethiopia, where Arabica trees grow wild, to Yemen, where coffee plantations were established. Coffee became such a valuable trading commodity for the Ottoman Turks ruling the place that they went to great lengths to prevent plants from leaving the territory. In the 17th century, as the story goes, an Indian pilgrim smuggled seven Arabica beans out of Yemen by taping them to his stomach. Around the same time, the Dutch somehow managed to sneak a whole tree out. Those plants provide the genetic basis for the world’s Arabica crop today.

Now imagine if every dog in the world was descended from a handful of puppies; that’s the level of inbreeding we’re dealing with in coffee. The Arabica we grow today commercially uses only a fraction of the species’ total genome. That means it lacks the genetic vigor it needs to adapt to the climate shocks we know are coming, such as drought, heat, flooding, and leaf rust.

Shortly before the leaf rust crisis touched off in Latin America, a plant geneticist named Timothy Schilling stumbled upon this big glitch in the coffee industry. He had spent decades breeding food crops in the developing world — peanuts in Cameroon, sorghum and millet in southern Africa — and in 2002, he found himself running a project for USAID, the international relief agency, to beef up Rwanda’s coffee sector.

As Schilling set out to help Rwanda’s smallholders improve the quality of their crops, he was dumbstruck by how little innovation and research existed regarding the effects of genetics, agronomy, and geography on coffee quality, compared to, say, peanuts. The trouble, he came to realize, was money: Crops grown in rich countries receive hefty government investment, but coffee is grown mostly in poor ones that lack these resources. “Coffee is an orphan crop,” Schilling said to me. There are hundreds of breeders working on keeping corn, rice, and wheat ahead of the climate, creating new and better varietals to cope with changing growing conditions. Schilling estimates that in coffee, there are only around 40 breeders, globally.

So, Schilling decided to take matters into his own hands. In 2011, he convened the big industry players at Texas A&M University — roasters, distributors, importers — and catalogued the most pressing issues jeopardizing their businesses. The outgrowth of that meeting was a nonprofit called World Coffee Research (WCR), funded by Keurig Green Mountain, J.M. Smucker, Illy, Lavazza, and about 150 other coffee companies. Its top priority: rewire the plants.

With WCR formed, Schilling moved quickly to recruit a heavyweight coffee researcher as the group’s scientific director. Christophe Montagnon, a Frenchman in his late 50s, had devoted his life to coffee somewhat by accident: as a young man, armed with a degree in plant genetics and yearning to escape France’s cold winters, he stumbled upon a research posting in Cote d’Ivoire. The job happened to be in coffee. Three decades later, Montagnon has risen to become a world-renowned coffee geneticist, and one of the crop’s leading scholars.

In 2012, one of the first tasks for WCR’s scientists was to weave genes from wild Ethiopian Arabica back into the commercial crop, mating wild coffees with commercial ones to create trees better suited to modern growing conditions. That’s easier said than done. For one, the greatest wealth of genetic raw material sits, wild and uncatalogued, in the mountains of Ethiopia — the full spectrum of Arabica, as well as dozens of other coffee species that we’ve never even touched on. Montagnon knew that avenue was a nonstarter. The local government wasn’t about to let a team of foreign scientists march in and rip out exotic plant specimens for the benefit of foreign farmers. Instead, WCR would focus its attention on a research institution in Costa Rica called CATIE, which is home to the world’s only open-source coffee gene bank.

Researchers gathered leaf samples from each tree and, using cutting-edge DNA sequencing technology, mapped their genomes. This has allowed WCR to leapfrog years of breeding efforts.

The words “gene bank” conjure images of subterranean laboratories bathed in halogen light, or else Fort Knox-style vaults filled with rows of lockboxes safeguarding meticulously catalogued seeds. But CATIE’s gene bank is something else entirely: a rather ordinary bunch of tropical fields, where over 1,000 unique types of wild Arabica have been planted (many having been carried there from Ethiopia in the 1960s, during a brief window when the country opened its forests to researchers). Here, at CATIE, there are big trees and little trees; scraggly trees and bushy ones; mutant trees with leaves and cherries of a deep purple hue. Experimenting with all of them would take an eternity. That’s the second problem.

So, Montagnon devised a strategy to speed things along. Researchers gathered leaf samples from each tree and, using cutting-edge DNA sequencing technology, mapped their genomes. This has allowed WCR to leapfrog years of breeding efforts by predetermining which of CATIE’s trees are likely to make the most promising mates. A hundred of them have been drafted into a group called the Core Collection: samples that represent the greatest breadth of Arabica’s genetic diversity, all now growing under observation at a WCR research farm near Santa Ana, El Salvador.

Shoring up coffee’s agricultural foundations is only part of the problem, however. While WCR works, it’s up to the coffee industry to give growers a reason to keep growing.

Latin America produces a small share of the world’s overall coffee volume, but when it comes to the coveted specialty beans sold by roasters like Intelligentsia, Blue Bottle, and others like them, it is arguably the world’s most important growing region — and one dominated by smallholder farmers with little in the way of savings or loan access, which makes a disease outbreak of this kind particularly devastating. After la roya came in 2012, some growers weren’t able to claw their way back from the loss of a major asset like their trees; others, already faced with rising costs and shrinking prices, didn’t want to. A spike in U.S. immigration from the region coincided with the worst of the leaf rust epidemic, suggesting that rather than rebuild, thousands of farmers and laborers simply dropped their tools and left. While hard numbers are difficult to come by, Montagnon says that it’s clear on the ground that fewer farmers are growing coffee now than they were before (he has no sense how many have emigrated, versus stayed on their land and switched to other crops). “We know for sure that some farmers have left coffee production,” he tells me. “We can see it.”

In Sheridan’s view, roasters have two responsibilities to the farmers growing coffee in the developing world. One is to fund organizations like WCR creating the kind of new and better varietals. The second is to protect farmers from the wild price swings of the commodity coffee market.

Lately, Arabica prices have hovered at a record low on the global commodities market — around $1 per pound, as of this writing — while input costs like fertilizers and labor continue to rise. Farmers in Latin America must now also bear the cost of spraying their trees with fungicide five or six times a year to have any hope of keeping ahead of the leaf rust. “It’s been a time of existential conversations for farmers, and there are lots and lots who have made the decision to leave coffee,” Michael Sheridan, the former aid worker in Latin America and now the Director of Sourcing & Shared Value for Intelligentsia Coffee, tells me. In other words, better plants are only part of the problem. If the prices don’t improve, there won’t be anyone left to grow them.

In Sheridan’s view, roasters have two responsibilities to the farmers growing coffee in the developing world. One is to fund organizations like WCR creating the kind of new and better varietals that can continue to keep them afloat. (He’s been surprised at how many in the industry haven’t stepped up yet, a dereliction of responsibility he likens to “like people listening to NPR and not paying their dues.”)

The second is to protect farmers from the wild price swings of the commodity coffee market. Fair Trade buying arrangements, set a price floor when the market dips below $1.40 per pound (buyers must pay at least 5 cents over the market rate when prices are above $1.40). This ensures steady profit margins for growers so that they have the financial resources to endure weather shocks and disease outbreaks.

Roasters like Intelligentsia, and North Carolina-based Counter Culture, go a step further by practicing Direct Trade: a niche buying strategy where roasters form long-term direct relationships with farmers. The arrangement is more expensive for the roaster, and more labor intensive, but typically gives growers better pricing and more security than Fair Trade, alone. Sheridan says this kind of support is crucial to motivating small growers to stick with coffee through what are likely to be even rockier times ahead. “There’s a whole narrative from specialty roasters that there’s no substitute for coffee that reflects a certain terroir, certain production methods,” Sheridan told me. “The measure of our commitment will be in places hit by leaf rust, and whether we’re willing to stay and fight with growers who have been there for us.”

In plant breeding, a race against time tends to look… sluggish. Even with the help of state-of-the-art DNA mapping, WCR’s work is still a matter of old-fashioned cross-pollination and then watching seeds grow. Three years into their work on that Santa Ana research farm, Montagnon leads a team that has created 50 new hybrids by crossbreeding the most promising Core Collection specimens with local commercial coffee varieties. They are now beginning to test them for qualities like flavor, yield, disease resistance, climate tolerance, and so on. Once they pass muster on the research farm, they will be further evaluated on farms around the region to evaluate how they grow at different altitudes, rain levels, shade conditions — a stage that could take several more years. Montagnon expects a handful of new commercial varieties to be ready by 2025, but how soon farmers adopt them will depend on how willing they are to take the risk with a relatively unknown new variety.

Meanwhile, Montagnon worries that the next leaf rust epidemic could be right around the corner. He has good reason for concern: Recently, researchers have determined that leaf rust epidemics have historically coincided with periods of low coffee prices. Montagnon explains that low prices means farmers have less to invest in caring for their trees, which makes them more vulnerable. “Coffee trees are like human beings,” he says. “When they’re tired, not well cared for, they get the disease more easily.”

When I ask Montagnon whether it could be as bad as 2012 all over again, he pauses, and then asks if I’m familiar with the agricultural history of Ceylon (I’m not). Back then, he says, the British East India colony, now Sri Lanka, was a renowned coffee region supplying cafes that blanketed London. In 1869, blight struck. “Coffee was devastated by rust,” Montagnon says. Local farmers spent twenty years battling the beast before they gave up, replanting with another specialty beverage crop that wouldn’t cause them all the headaches. “Now,” he says, “the British are tea drinkers.”