As tempting as it is, I would avoid the obvious snarky replies: “No problem, Poopsie.” or “I’m not your sweetheart!” Most of the time, pet names are just misguided niceties and responding rudely is too aggressive, like in your waitress example. But that doesn’t mean you should have to put up with feeling demeaned. Instead, say in a really friendly way, “My name’s [Alexandra]. Nice to meet you.” Shake the person’s hand, get their name, and at the very worst you’ve put a halt to their “endearments”; at best, you’ve just made a new acquaintance.
Now, if you’re not much for confrontation, I’d say the same advice goes for those times when “baby cakes” is coming from someone less benign (like the dirty old man I’m always running into at the gym). You’re not likely to change their actions and taking the high road will be the simplest way to get your point across. But, if your self-control wanes for a moment, and something a bit harsher just happens to slip out, I don’t think anyone would fault you.