You have 1 million players and need to show the top 100 by score. In a SQL database
that's: SELECT * FROM players ORDER BY score DESC LIMIT 100.
Sorting 1 million rows on every page load gets painfully slow as you grow.
Redis Sorted Sets maintain the order as you write each score. The top-100 read is always O(log N) — fast whether you have 100 or 100 million players.
| # | Player | Score |
|---|---|---|
| 🥇 | carol |
1,450
|
| 🥈 | alice |
1,200
|
| 🥉 | eve |
1,100
|
| 4 | bob |
980
|
| 5 | dave |
670
|
Try submitting a name that already exists — Redis will update the score, not duplicate the entry. Then check where they appear in the ranking.
Every time you call ZADD, Redis inserts the member into a skip list
data structure that is always sorted. Reading the top-N is never a sort operation —
it's just walking a pre-ordered list. The leaderboard stays fast forever.
Fortnite and Call of Duty real-time kill leaderboards. Duolingo weekly XP rankings that reset every Sunday. Hacker News story rankings (votes minus time decay = score). Any time you see a live "top N" list updating in real time, Redis is probably behind it.