2026Local
Real-Time Leaderboard
- Node.js
- Express
- Socket.io
- Redis
- PostgreSQL
- Prisma
- React
- Docker Compose
Overview
A real-time leaderboard for games. Scores are kept in a Redis sorted set, and each new score reaches every connected player at once through Socket.io. It runs locally with Docker Compose.
01 · Problem
A leaderboard has to be read quickly without scanning the database on every request, simultaneous scores must not overwrite each other, and changes have to appear on screen at once.
02 · Solution
The ranking lives in a Redis sorted set: the top 10 and a user's rank are each a single command, and a new score is written with ZADD GT only when it beats the old one. Every score is also stored in PostgreSQL as history. Score submissions are limited with a Redis counter, and the current ranking is pushed with Socket.io.
03 · Outcome
A four-service Docker Compose project (interface, API, PostgreSQL, Redis) whose read path runs entirely in memory.