The town of Borrego Springs, which is 86 miles northeast of San Diego and is served by a single long-distance transmission line, uses a microgrid. After a wildfire took down that line in 2007, leaving the town’s 3,500 residents stranded without power for two days, the local utility, San Diego Gas & Electric, built a microgrid demonstration project for the town.

Today, if the transmission line feeding power to Borrego Springs goes down, the town can detach itself from the grid and draw power from an array of diesel generators, solar farms, rooftop solar panels and batteries. The system faced an early test in 2013, when severe storms knocked out the power lines and the microgrid fed power to more than 1,000 customers and critical facilities — such as gas stations, stores and a cooling center at the library — for more than 20 hours while the line was being repaired.

The drawback of microgrids is that they can take years to build and they tend to be more expensive than the traditional grid. San Diego Gas & Electric relied on $13 million in state and federal grants to set up the Borrego Springs project and is still working to refine the system. But the costs of blackouts can also be high: Borrego Springs has a large elderly population and can experience 100-degree heat in the summer.

Interest in microgrids is rapidly growing around the United States. Philadelphia’s Navy Yard, Alcatraz Island and an affordable housing complex in Brooklyn all have versions of microgrids that can operate autonomously when the larger power grid goes down. And while many of these microgrids rely on diesel or gas power to provide electricity around the clock, some are incorporating cleaner energies like solar power and batteries as the prices of those technologies drop.