Architecture Overview
A multiplayer game backend handles: matchmaking (finding players with similar skill), game sessions (real-time state sync during a match), leaderboards (global and friend rankings), and player data persistence (inventory, progress, achievements). The most challenging part is the real-time game session — thousands of concurrent matches, each requiring low-latency state synchronization between players.
Matchmaking
Matchmaking groups players with similar skill ratings (ELO or MMR — Match Making Rating). Algorithm: players join a matchmaking queue. A matchmaking service polls the queue and groups players by skill bracket. Skill brackets: partition players into windows (e.g., MMR 1000-1100, 1100-1200). As queue wait time increases: expand the bracket (after 30 seconds, accept MMR 900-1200). After 2 minutes: accept any MMR. This ensures fast matches at peak hours and eventual matches during off-peak. Implementation: Redis Sorted Set per game mode with score=MMR. ZRANGEBYSCORE to find players in a bracket. On match: atomically remove selected players from the queue (ZREM), create a game session. Regional matchmaking: match players on the same geographic region first (reduces latency). Redis Geo for regional grouping.
Game Session Architecture
Each match runs on a dedicated Game Server (a long-running process managing the game state for one match). Game server selection: a Fleet Manager maintains a pool of game servers (EC2 instances, Kubernetes pods). On match creation: find a server with available capacity in the appropriate region. Assign the match. Game server communication: players connect directly to their assigned game server via UDP (low latency, game-appropriate). WebSockets for less latency-sensitive games (card games, turn-based). Game loop: the game server runs at a fixed tick rate (20-60 ticks/second for action games). Each tick: receive player inputs, advance game state, broadcast updated state to all players.
State synchronization: client-side prediction (client immediately applies the player’s own input locally without waiting for server confirmation). Server reconciliation: periodically receives the authoritative server state and corrects any divergence. Lag compensation: the server rewinds game state to the player’s perspective time to check if a hit was valid. This prevents high-latency players from being penalized for their connection.
ELO and MMR Updates
After each match: update each player’s MMR. ELO formula: expected_score = 1 / (1 + 10^((opponent_MMR – player_MMR)/400)). actual_score = 1 (win) or 0 (loss) or 0.5 (draw). new_MMR = old_MMR + K * (actual_score – expected_score). K-factor: 32 for new players (converges quickly), 16 for experienced players. Store MMR history for analytics. Leaderboard update: after MMR change, update the global leaderboard Redis Sorted Set: ZADD leaderboard player_id new_MMR. Global rank: ZREVRANK leaderboard player_id. Top-100: ZREVRANGE leaderboard 0 99 WITHSCORES.
Leaderboards
Redis Sorted Set is the canonical leaderboard implementation. ZADD O(log n), ZREVRANK O(log n), ZREVRANGE O(log n + K). Global leaderboard: a single sorted set for all players. Friend leaderboard: ZADD friend:{user_id}:leaderboard friend_id score for each friend. Update on each friend’s MMR change. Pagination: ZREVRANGE leaderboard offset offset+page_size-1. Seasonal leaderboard: create a new sorted set each season (leaderboard:{season_id}). Archive the previous season’s top-100 to a database. Player rank context: ZREVRANGE leaderboard player_rank-5 player_rank+5 to show the player and their neighbors.
Interview Tips
- Game sessions require dedicated servers (not serverless) — a persistent process maintains game state across a match. Stateless servers cannot handle real-time game state.
- UDP vs TCP: action games use UDP (lower latency, acceptable packet loss). Card games, strategy: TCP/WebSockets (reliability matters more than latency).
- The leaderboard is a classic Redis Sorted Set problem. Know ZADD, ZREVRANK, ZREVRANGE, and ZRANGEBYSCORE — they cover 99% of leaderboard operations.
Asked at: Meta Interview Guide
Asked at: Snap Interview Guide
Asked at: Twitter/X Interview Guide
Asked at: Netflix Interview Guide