The common housefly has amazing tips on the ends of its legs that can allow it to hold on to even apparently very smooth surfaces even upside down.
The leg tips have tiny claws that can dig in and hold on to even slight imperfections of surfaces. But if its not enough, moist suction pads called pulvilli allow the housefly to adhere to any surface.
Even more amazing, the fine hairs on the end leg segment are the housefly's "taste buds" called "tarsi". So when you see a housefly walking in circles over something, it is tasting it to see if it is potential food.