The Cepheid variable relationship was worked out by Henrietta Swan Leavitt observing Cepheids in the Magellanic Clouds. This is a smallish (astronomically speaking) cluster of stars a ways outside our galaxy, so to all intents and purposes are more or less all at the same distance. A bit like observing the lights of Manchester from London, they're all about the same distance away. So if there is a relationship between their brightening and dimming and their luminosity, you can tell that the relationship is pretty much fixed. It turned out there is a little more to it in the case of Cepheids, but that's mostly what it is. So once you have calibrated this and worked out how this equates with distance, you have a convenient yardstick