Technical case study

Redis Sorted Set ranking

Fast rank lookups, atomic score writes and a recovery path from durable storage.

Redis ZSETLuaHyperLogLogMySQLO(log n)

01 · Context

Competitions rank individuals and teams by score and submission time. Sorting directly in MySQL on a hot path can become a bottleneck as traffic grows.

02 · Problem

Provide fast rank lookups, time-based tie-breaking, atomic ranking updates and a recovery path when Redis data is missing or inconsistent.

03 · Architecture

Processing flow

01 Exam result
02 Lua atomic write
03 ZSET + Hash
04 Ranking API
05 MySQL rebuild

04 · Result

The solution runs in production with O(log n) rank lookups, reducing reliance on expensive MySQL sorting for the ranking hot path.

05 · Ownership

I directly implemented and operate the Redis ranking version currently running in production.

06 · Trade-off

HyperLogLog provides estimates rather than exact counts. Redis scores use doubles, so precision matters when encoding tie-breaks. MySQL remains the rebuild source.

Want to go deeper?

I can walk through the technical decisions, constraints and alternatives in a conversation.

Email me