AlgoViz

Design a Multiplayer Game Leaderboard

easy 45 min

Keep 250 million players in order while results arrive all the time, and tell any of them their place in milliseconds.

API and data

The contract first, then the data that serves it.

Interface

Calls

CallWhoAnswer
POST /v1/resultsGame server202 and a result ID
GET /v1/boards/{b}/topAnyoneRows with rank, player, score, movement
GET /v1/boards/{b}/mePlayerRank, score, percentile, neighbours
GET /v1/boards/{b}/friendsPlayerFriends in order, my place
GET /v1/players/{id}/historyPlayerPlace at the end of each period
WebSocket topic my-resultPlayerOld place, new place, cause
JSON
{  "match_id": "m_781",  "player_id": "u_42",  "mode": "battle",  "region": "eu",  "score": 48500,  "ended_at": "2026-11-23T10:30:00Z",  "stats": { "eliminations": 12, "place": 1, "seconds": 1800 }}
The call is signed by the game server. Match and player together are the idempotency key.

What a place looks like

FieldExampleNote
rank1,523 of 15,000,000One-based for people
percentiletop 0.01%1,523 / 15,000,000
next milestonerank 1,000 at 48,0002,800 more points than 45,200
as of10:30:02How old the answer is
movementup 1301,650 to 1,520

Data

What is stored

DataWhereKey
ResultPostgreSQL by day, then object storagematch, player
Best scorePostgreSQLboard, player
OrderRedis sorted setboard and period
Band countsRedis hashboard, band
Frozen listObject storageboard and period
Names and avatarsProfile service, cached for 5 minutesplayer
Text
ZADD board:battle:eu:w2968 GT 50856983975 u_42ZREVRANK board:battle:eu:w2968 u_42       place, from 0ZRANGE board:battle:eu:w2968 0 99 REV WITHSCORESZRANGE board:battle:eu:w2968 1514 1524 REV  neighbours of rank 1520ZCARD board:battle:eu:w2968ZMSCORE board:battle:eu:w2968 u_7 u_9 u_11
Index 1519 is rank 1520, so five rows either side are indexes 1514 to 1524. Board and profile rows are joined in the service.

A result becomes a place