AVL and Red-Black Trees
In short: an AVL tree rebalances after every insert so that for
every node, the heights of its two subtrees never differ by more than 1 —
its balance factor (bf = height(left) - height(right)) always stays
in {-1, 0, 1}. An insert can push several ancestors' bf to ±2 at once,
but fixing the lowest unbalanced one with one of four rotation
recipes — LL, LR, RR or RL — restores that subtree to its pre-insert
height, which makes every ancestor above it balanced again too. A
red-black tree relaxes the rule (a looser "never more than twice as
deep on one side") and fixes violations with cheaper recolouring most
of the time, trading a slightly taller tree for fewer rotations per insert.

Keeping a leaderboard fast after a losing streak
A game's leaderboard indexes players by score. Scores update constantly, and a bad run of matches can insert a long streak of similar, nearly-sorted scores — exactly the pattern that degrades a plain BST. An AVL-backed index keeps lookups at O(log n) no matter how the scores arrive, by checking the balance factor after every single insert and fixing it immediately if it's broken.
bf(70) comes out -1 — its right child 90 makes that side one level
taller — and that extra level echoes up to the root: bf(50) is -1 too,
while bf(30), a leaf, is still 0. None of these cross ±2 yet, so no
rotation fires. That's the check an AVL insert runs after every single
node on its way back up, not just at the root.