I was reading about cyanobacteria and came to know that they are the first organisms that filled the atmosphere with oxygen around 2.3 billion years ago but then I realized that they themselves are aerobic and I couldn't understand how an aerobic organism would be able to survive the oxygen poor atmosphere in the first place to make enough oxygen that filled the whole atmosphere and caused almost all anaerobic organisms go extinct
The first cyanobacteria were probably anaerobic, and this matter seems to be a hot topic of contemporary research. A recently published studya that performed a phylogenetic analysis of various Cyanobacteria genomes states:
The most parsimonious inference from these data is that the last common ancestor of the Cyanobacteria did not use oxygen and that the three classes [of Cyanobacteria] acquired aerobic respiration independently after their divergence. The absence of aerobic respiration in ancestral Cyanobacteria suggests that abiotic oxygen sources on early Earth were insufficient to allow for its evolution until after the appearance of oxygen produced by photosynthesis.
a Soo, Rochelle M., et al. "On the origins of oxygenic photosynthesis and aerobic respiration in Cyanobacteria." Science 355.6332 (2017): 1436-1440 (http://web.gps.caltech.edu/~wfischer/pubs/Sooetal2017.pdf)