Design a Fantasy Sports Platform
Understanding the Problem
🏏 What is a fantasy sports platform? In fantasy sports, users pick a team of real athletes, and the team scores points based on what those athletes actually do in real games: runs, wickets, touchdowns, goals. Users compete against friends or strangers in contests, often with an entry fee and cash prizes. The fantasy result is entirely driven by a live feed of real-world stats.
You'll hear this asked as "design ESPN Fantasy," "design DraftKings" or "design Dream11." They're two flavors of the same system. Daily fantasy (DraftKings, Dream11) is built around a single match or slate: you build a team under a salary cap, join contests that can have millions of entries, everything locks when the match starts, and the contest is settled when it ends. Season-long fantasy (ESPN, Yahoo) is built around a small private league that drafts players before the season and plays head-to-head matchups every week. Both share the core: rosters of real players, a lock at game time, and a points engine fed by live stats.
We'll design daily fantasy as the main flow, because it's where the scale problems are (millions of teams joining in the last minutes before a match, and live ranking of giant contests). Season-long leagues and their live draft get their own deep dive.
Functional Requirements
Fantasy platforms have a lot of surface area: research tools, news, chat, referrals. Pin down the slice with your interviewer.
Core Requirements
- Users should be able to browse contests for an upcoming match and join one with a team they build: 11 players under a credit cap, with a captain and vice-captain.
- Users should be able to edit their teams until the match starts, at which point every team locks.
- Users should see live fantasy points for their teams and their rank in each contest while the real match is being played.
- Winners should be paid when the match ends, according to each contest's prize table.
Below the line (out of scope)
- KYC, geo-restrictions and responsible-gaming limits (required by law in many places, but a separate system).
- Payment gateways for deposits and withdrawals. We'll assume a wallet with a ledger already exists.
- Content: news, player stats pages, expert picks.
- Fraud and multi-account detection, beyond a mention.
Non-Functional Requirements
Ask about the biggest events, because fantasy traffic is spiky in a very particular way. For our design, a marquee cricket match (think an IPL final) draws 20 million users who create 50 million teams and 150 million contest entries. The largest single contest has 10 million entries.
Core Requirements
- The system should handle the join spike just before lock: most entries arrive in the last 30 minutes, peaking around 100,000 joins per second.
- No entry or team edit should be accepted after the match starts. The lock must be strict.
- Live points should update within a few seconds of a real event, and contest ranks within ~30 seconds, for every one of the 150M entries.
- Money must be exact: an entry fee is charged once, prizes are paid once, and refunds happen for cancelled contests.
- The platform should stay available during the match, when tens of millions of users are refreshing their rank at once.
Below the line (out of scope)
- Multi-region active-active. We'll run each sport's contests out of one region with a warm standby.
- Real-time streaming video of the match.
Two quick calculations shape the design. First, the join spike. If 150M entries come in mostly over the final 30 minutes, the average is already 150M / 1,800 s ≈ 83,000 per second, and the last few minutes are worse. This looks a lot like a flash sale: a fixed deadline, a few hot contests, and a hard cutoff.
Second, live scoring. A T20 cricket match has about 240 deliveries, one every 30-40 seconds, and each one can change several players' points. If we naively recompute 50M team scores and re-rank 150M entries per delivery, that's a lot of work every half minute. But a match has only 22 real players, and every team's score is just a weighted sum of their points.
That's the key insight for this problem: there are millions of teams but only 22 numbers that change. Each team is a fixed vector of weights over those 22 players (0, 1, 1.5 for vice-captain, 2 for captain). The live state of the entire match is a 22-element array, and every team score can be derived from it cheaply.