Those structures worked as they were supposed to when the avian flu arrived in December 2014. The virus was detected as it jumped the Canadian border from small farms in British Columbia and landed in wild birds in Washington State before spreading through poultry farms on the West Coast. Avian flu usually comes from wild birds: mostly ducks, geese and shorebirds, which shed the virus in their bodily waste and secretions as they migrate. To watch for its arrival, federal and state agencies collaborate on surveillance systems, taking samples of lakes where birds roost, wild birds when they are banded and wild turkeys and ducks that are shot by hunters. But those systems cannot test every one of the millions of birds that cross the United States every season. The first signal of the flu’s arrival can be when domesticated birds die.

And that was what happened next. The flu changed course, zigzagging across the map instead of down: On March 4, 2015, it struck Minnesota, the No. 1 turkey producer in the United States; Missouri was next, on March 9; then Arkansas on March 11, Kansas on March 13, South Dakota on April 1. The pattern did not match wild migration patterns, and scientists watching its spread were baffled as they tried to find the source. On April 2, it struck Minnesota yet again, and within two weeks, the flu hit 23 farms holding 1.5 million turkeys. It descended on Iowa on April 13, invading first a turkey farm and then a giant property holding more than 4.1 million egg-laying hens.

The U.S.D.A. had written plans anticipating the arrival of avian flu, but there was no way to test how effective they would be: There had not been a multistate epidemic of highly pathogenic avian influenza — fast-moving, virulent and very infectious — in the United States for more than 30 years. The main effort against avian influenza has been geared toward detecting and controlling an epidemic in people. A strain known as H5N1 emerged in Hong Kong in 1997, and since then it has infected 846 people in 16 countries and killed more than half of them — a small number of victims, but an enormous mortality rate. So far almost all the victims have been farmers or people who live in proximity to chickens, but virologists fear its spreading to the global population. The United States has a Na­­tional Strategy for Pandemic Influenza, created to counter that threat, that focuses on how the disease would affect humans. Farmers have built their barns and established their routines around the more common diseases of turkeys and chickens — Marek’s disease, infectious bronchitis, fowl cholera — which can be prevented with vaccinations and good hygiene. But those protections weren’t adequate against this flu.

Turkeys in the United States are raised in solid-walled barns for their first few weeks, and after that in open-sided buildings, hundreds of feet long and faced with a few feet of plywood topped by walls of mesh. Panels that resemble upside-down roller blinds slide up when conditions are cold or blustery and down again when the wind drops or temperatures warm. The design is industry-standard, as were the procedures the Molines followed to protect their birds. They swapped their outdoor boots for indoor ones before they walked into the barns that housed the adult birds. They also dipped their outdoor boots in disinfectant before entering the brooder barn and pulled on coveralls and fresh boots once they were inside. As the flu drew near, they added extra precautions, like extra boot dips and parking cars farther away from the barns.

The Molines’ property is small and relatively low-tech, but even huge farms, where advanced biosecurity is routine, had no better luck. Rembrandt Foods, about 100 miles northwest of the Molines, is the third-largest egg producer in the country; before the flu arrived, it owned 15 million hens on its farms. The birds live in sealed solid-walled sheds, hundreds of thousands per building, under computerized lights and climate-controlled ventilation. Workers shower and change into uniforms when they arrive for work, step through disinfectant before they enter a barn and shower and change again on the way out. The parking lots are cement instead of gravel to reduce the omnipresent Iowa dust and any organisms that might hitch a ride on it, and the company commissions outside audits of its biosecurity. It passed one just before the epidemic started. The flu got in anyway. More than eight million birds had to be destroyed.

“Fifteen years of work,” says Dave Rettig, Rembrandt Foods’ president, who began his career with a farm of just 25,000 birds. “Gone in a week.”