Design league-of-legends backend: system design interview for a large scale systems
Facing a system design interview soon? I found so much value in doing hypothetical designs that decided to create my own guide on how to build your own roleplay CTO-designer system design process. All that said, I actually enjoyed every system design interview I have had. There is something very satisfying about figuring out a solution on paper and then seeing it work ‘in-game’. This guide is completely free, and if you’re looking for any tips or help with coding interviews, definitely check it out!
Disclaimer: All of this analysis is speculative I have no affiliation to Riot Games.
Design a backend system architecture for 50 Million daily league of legends players.
~ 2,414,739 simultaneous Players Online
~ 14.44% per region
~ 250k simultaneous matches globally
~ 35k simultaneous matches in US (15–60m long)
Features (most interesting):
- Match history/analytics
- Game server
Important Design Considerations:
- Client game state can not be trusted (to avoid cheaters and bots)
- Human reaction time 200–400ms and 100–150ms for professional gamers (visual and audio signals). But my assumption is that in order to make a smooth picture on the screen we need to target 1/5 th of that value
- The game should be scalable to 10x peaks in a high demand hours
Capacity Estimation and Constraints
Given that 350k simultaneous matches with an assumed median of 30minute match that gives us 200 RPS to Auth service which is not super challenging to design and scale. Even on 10x load 2k RPS is not a super high load.
For live game servers, we are gonna need
- 350k of simultaneous TCP connections (one connection per player, 10 players per match)
- Low latency game updates (<20ms) champ coordinates, abilities
- Server state synchronization (no client state)
- 50 RPS per one client (50 updates once per 20ms) or 500 RPS per match
- Given (4) we could host 2–20 matches per compute node (1k — 10k RPS) which give us 3.5k compute nodes per region
- Approx only game server infra will cost $100 * 3.5k = $350k / month
Approaches and trade-offs
Solution 0: Since all state and data are grouped by match this is super easy to linearly scale with the number of servers. Given generated match_id we could use a hashing function/registry to lookup specific hosting server coordinates (dc/az/ip) and route clients traffic. Even simpler would be to pin specific live server ip address to the client on matchmaking
Solution 1: Since live game matches in a real-time data we could use RAM as primary storage for game state. As a secondary data storage, we could just dump aggregated game state as a blob to some analytics db / data lake.
Tradeoffs: When the game server process crash we could lose the game state and have to end the match
Solution 2: With 500 RPS per match and shared state between 10 clients we could spin up a dedicated server process by a match for better isolation, performance, and resiliency. Even more, it’s possible to spawn a server node in the availability zone with an optimal latency for all players.
Tradeoffs: Server spin up time could delay the game start but we could optimize that. Management of dedicated server processes could be an overhead of ops
Solution 4: Match history/analytics we can use the live server in mem state for data aggregation by match/team and client and then store this state externally by match/team and client ids
Tradeoffs: None obvious
- How to implement AI/Bots?
- How to gracefully handle game server crash?
- How to protect a match for a DDOS attack?
- Is it possible to p2p client state updates?
- How to handle slow clients?