Bacteria can be found on every single part of our planet, from the air we breathe, to deep sea vents, in our soil, plants, animals, on our own skin and inside our bodies. Only 30,000 species of bacteria have been formally named out of an estimated one trillion species on earth. That means about 99.9% of bacteria is left to be discovered. What was done once purely for flavor and preservation is only now starting to be understood on a microbial level.
Fermentation is considered one of the oldest methods of food preservation, some estimate over thousands of years. And while there may have not been a microscope or understanding of what the bacteria were, these techniques evolved through observing natural phenomena and were passed down from generation to generation. In almost every culinary tradition around the world, there is a co-existing relationship with microbes and fermented foods that exist in some form.
Katz, Sandor Ellix. The Art of Fermentation: An In-depth Exploration of Essential Concepts and Processes From Around the World. Chelsea Green Pub, 2012.
Redzepi, R., Zilber, D., Sung, E., & Troxler, P. The Noma Guide to Fermentation. Artisan, a division of Workman Publishing Co., Inc, 2018.