SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 26
Limit simultaneous streams per account
A video subscription service sells plans that allow 1, 2 or 4 screens to play at the same time. When a family member presses play on one screen too many, they should see a clear message listing which devices are watching, with an option to stop one. Paying customers should never be blocked by a phone that died in a tunnel an hour ago.
Requirements
- Before playback starts, admit or refuse the stream based on the account's plan limit and its currently active streams.
- When refusing, return the list of active devices, and let the user stop a stream on another device remotely.
- Free a slot when playback stops normally, and also when a device crashes or loses its network.
- A device that restarts playback (after a crash, or moving to the next episode) must not take a second slot.
Constraints and assumptions
- 250 million accounts; up to 40 million streams playing at once at the global evening peak.
- Average session about 45 minutes; play starts peak around 15,000 per second, and 100,000 per second during a major premiere.
- The admission check may add at most 100 ms to playback start at p99.
- A slot held by a vanished device must free itself within about 2 minutes.
- Brief over-admission (one extra stream for under a minute) is tolerable; systematic over-admission is not. Streams are served from 3 regions, and accounts are occasionally used from two regions at once.
Out of scope for the first sketch
DRM license protocols · Detecting password sharing between households · Plan purchase and billing
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Limit simultaneous streams per account
Finish your first sketch before answering these. Cross out freely.
- What does an active stream look like in your store, and how is the slot freed when a phone dies in a tunnel?
- On a 2-screen account with one stream already playing, two TVs press play within the same 50 ms. Show why at most one is admitted.
- The app crashes and immediately restarts playback. Why does it not now count as two streams?
- A traveler streams from a region that cannot reach the account's home region. Do you admit the stream? What do you risk either way?
- The account downgrades from 4 screens to 2 while 4 streams are playing. What happens, and when?
Compare afterwards: worked approaches and reading at sketchbook /questions/concurrent-stream-limits/review