How did western countries deal with this kind of problem? Or they havent faced anything of such scale till now?
In the UK, in the 1800's, millions moved to London, and lived in shocking slum conditions. Life expectancy was ~30 years, diseases like cholera killed many, because of overcrowding and poor sanitation. Pollution was awful, As recently as 1952, 10,000 people died in four days in the great smog of London https://en.m.wikipedia.org/wiki/Great_Smog_of_London.
In summary, it took a long time to address the problem.