Answer :

Bacteria take on many roles in the environment. They act as decomposers at the end of food chains and food webs. During decomposition, they also liberate advantageous gases and nutrients which are used by other living beings.
Some bacteria also participate in the nitrogen cycle, making fixation of nitrogen, nitrification and denitrification, almost always in mutualist ecological interaction with plants.
Bacteria also live inside us; there are over 500 species of bacteria in the human gut and they are responsible for carbohydrate fermentation and absorption; prevention of the growth of pathogenic microbes in the gut by occupying the space that would otherwise be used by harmful microbes; and they are also involved in immunity, metabolic function and prevention of inflammatory bowel disease.
Excessive proliferation or mass destruction of bacteria can impact entire ecosystems. For example, when a river is polluted by organic material the population of aerobic bacteria increases since the organic material is food for them; the great number of bacteria then exhausts the oxygen dissolved in water and other aerobic beings (like fishes) undergo mass death.