Work / Case study
Real-time rankings with Redis sorted sets
A leaderboard built with a Node.js backend, a React dashboard, scheduled resets, and an audit history.
Problem
A leaderboard is only useful while it's current. Scores change continuously, and everyone watching should see the new order without refreshing. The rankings also restart on a schedule, daily and monthly, and the history has to outlast each restart.
That gives three jobs: keep a ranked order up to date, push changes to viewers, and keep history.
Architecture
A Node.js backend sits between a React dashboard and the data stores. Rankings live in Redis sorted sets on a self-hosted Redis instance on a Google Cloud VM. Live rank changes reach the dashboard over WebSockets, and MongoDB stores the audit history.
A sorted set keeps each member ordered by its score, so the ranking is always ready to read. According to the Redis sorted set documentation, adding or updating a member and looking up a member's rank both take logarithmic time, and reading a top-N range is cheap. That fits a workload of frequent score updates and frequent ranking reads.
Reset and audit lifecycle
A scheduler runs the resets on a daily and a monthly schedule. Resetting a ranking starts a new competition period in Redis. The audit history in MongoDB is kept separately, so a reset of the live ranking doesn't remove the record of earlier periods.
Keeping the two apart gives each store one job. Redis answers "who is ahead right now", and MongoDB answers "what happened".
Tradeoffs
Rankings in memory
Sorted sets make updates and rank reads fast because the order is maintained as scores change. The cost is that the live ranking is held in memory, and durability depends on how Redis persistence is configured.
Self-hosting Redis
Running Redis on a VM gives full control over its version, configuration and cost. In exchange, the team owns upgrades, backups, monitoring and recovery that a managed service would otherwise handle.
Pushing updates
WebSockets deliver rank changes as they happen, instead of having every dashboard poll. The server keeps a connection open per viewer and has to decide how often to send changes when scores move quickly.
Two stores
Separating the live ranking from the audit history keeps each store simple, but it means two systems to operate and keep in step.
Scale and latency figures are left out on purpose. They will be added when they can be published with their measurement method.