Awesome Go
Read post

Your Redis Leaderboard Is Probably Breaking Ties Wrong

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

Redis sorted sets order equal-score members lexicographically by member ID — a deterministic but arbitrary tie-break. Podium, an open-source Redis-backed leaderboard service, solves this by using a per-leaderboard decrementing sequence stored in Redis itself. When a player reaches a new score, an atomic Lua script allocates a unique sequence token and encodes it as a fixed-width 19-digit prefix prepended to the member ID. This makes earlier arrivals rank higher without relying on wall clocks or floating-point packing tricks. The design also handles idempotency (retries don't change rank), ascending leaderboards (a second inverted index), and atomicity (all four state pieces updated in one Lua script). Benchmarks show 11–17% latency overhead for writes and ~287 bytes per member vs. 99 bytes for the plain baseline.

    #game-development#golang#redis
Yesterday•7m read time•From dev.to
Post cover image
Table of contents
TeneficGames / podiumQuickstartWhy the obvious fixes failUse a Redis sequence, not timeIdempotency is part of fairnessAscending leaderboards contain a trapAtomicity is the real featureCorrectness is not freeThe deeper lesson

Questions this post answers

How do I break ties fairly in a Redis sorted set leaderboard without using timestamps?

Use a per-leaderboard decrementing sequence stored in Redis, initialized to the maximum signed 64-bit integer (9223372036854775807). When a player reaches a new score, an atomic Lua script decrements the counter and prepends the 19-digit value to the member ID. Earlier arrivals get larger tokens, so Redis's reverse lexicographic ordering naturally ranks them first at equal scores — no wall clocks, no clock skew, no race conditions. Teams shipping competitive leaderboards track design patterns like this on daily.dev.

What is the latency cost of adding deterministic tie-breaking to Redis leaderboard operations?

Deterministic tie-breaking adds roughly 11% latency overhead for insert-and-return-rank, 17% for change-score-and-return-rank, 5% for submitting the same score again, 1% for reading one rank, and 3% for reading the top 50. Memory usage rises from about 99 bytes per member to about 287 bytes when supporting both ascending and descending ordering. Developers weighing Redis leaderboard trade-offs find concrete benchmarks like these on daily.dev.

How do I handle ascending and descending leaderboards with the same tie-breaking logic in Redis?

Maintain two separate sorted sets: one for descending order using the raw decrementing sequence token, and one for ascending order using an inverted token where each digit is replaced by 9 minus that digit. This makes an earlier, larger sequence value become a lexicographically smaller prefix in the ascending index, so the 'first arrival ranks higher' rule holds in both directions without conditional logic. Developers building multi-mode leaderboards keep up with Redis patterns like this on daily.dev.

157 Impressions
Awesome Go's image
Awesome Go

Awego's platform is dedicated to providing insights and resources for developers and technology ent...

1.2K Followers

•

8.2K Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard