Got2B glued is the best stuff. I use the blue gel and the blasting freeze spray. My dd has super fine hair and she's never had her bun come close to falling out! I do have to gel every single part of the hair in every step to get it to hold.
I do the bun donut, as a pp mentioned. And starting with damp hair around the scalp which allows the gel to dry and really hold helps too. I do a high pony, gel, comb, and secure with a rubber hair tie (not the cloth coated ones, it's the goody brand that is literally rubber). Bun ring on, spread out hair, gel, rubber elastic around. Gel remaining hair and braid, put small holder on end of braid, wrap around, rubber elastic around that. Snap clips for the ends that need to be held down (gelled down before clipping). 3-4 bobby pins. Tons of hair spray everywhere!
She's not up in optionals yet, so hopefully this continues to work with harder tricks. But I have done her hair the night before a meet, she sleeps in it, goes to school, goes to an afternoon meet and I only have to do a quick spray to hold down tiny flyaways right before the meet.