If Cloverdale, Calif., makes it through one of the worst droughts in state history, it will be in large part due to the efforts of an unlikely source: beer.

The recent installation of an innovative water treatment system at the Bear Republic Brewing Company, along with the ongoing construction of two local wells in part paid for by the company, could go a long way toward keeping Cloverdale afloat before it’s estimated to run out of water in a few months.

“We hope to weather this drought, and with the help of this technology and the support of the city of Cloverdale we feel we have a pretty good chance,” Bear Republic owner Richard Norgrove Sr. recently told The North Bay Business Journal. The company is famous for its tasty IPA, Racer 5.

Originally designed for the U.S. military, the treatment system, named EcoVolt, will use recycled wastewater to supply about 10 percent of the 7.8 million gallons of water the brewery uses each year to produce 72,000 barrels of beer. It will also generate enough biogas to slash the facility’s electricity use by 50 percent.

Here’s the nitty-gritty of how the proprietary process works, according to the National Science Foundation:

The system sends wastewater through a bio-electrochemical reactor. As the water filters through it, special bacteria in the reactor eat the organic waste in the water, releasing electrons as a byproduct. Those electrons travel through a circuit to generate methane. This very high quality methane is then piped out to an engine, where it's burned with a small amount of natural gas. It then generates heat and energy.

Even before installing the EcoVolt system, for which it reportedly paid $1 million, Bear Republic was already well ahead of its competitors in terms of water conservation. The average brewery uses six gallons of water for every one gallon of beer produced, but the Cloverdale facility boasts a ratio of just three and a half to one.

In November, the brewery lent Cloverdale $466,000 to hasten the digging of two new wells, which would provide more water for the city’s residents and also enable the brewery to increase supply for a planned expansion, reports The San Francisco Chronicle.

Scheduled for completion in July, the wells will increase local water capacity by 600,000 gallons a day, a 40 percent increase over current supplies. Bear Republic currently uses up to 2,000 gallons of water a day to make beer—meaning beer will be directly responsible for city residents getting access to an additional 598,000 gallons. But since the volume of water used by the brewery is based on the city's ability to provide, that number could change.

Last week, the need for the new wells became more acute: State officials said Cloverdale is one of 17 California cities estimated to run out of water by May without the new supply.

“The Russian River is where we get our water, and it’s just about dry,” said Cloverdale Vice Mayor Robert Cox. “There’s no rain. About the only good news on the horizon is those new wells. We’d be in really bad shape without them.”