The alveoli and capillary walls are the points of exchange of gasses. Most cells use oxygen to produce enough energy to carry on the basic functions of life. As cells are using oxygen to produce energy they also produce carbon dioxide. Carbon dioxide is harmful and must be eliminated from cells.
Oxygen enters the blood through the respiratory membrane.
Blood transports the oxygen to the systemic capillaries. There, the oxygen moves through the thin capillary walls into the cells. Carbon dioxide passes through the capillary walls from the cells. Blood transports the carbon dioxide to the lungs where it crosses the respiratory membrane and enters the alveoli. This exchange of gasses must be rapid enough so that trillions of cells can acquire the energy they need for survival.