Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 26

Limit simultaneous streams per account

Expert · 40 min · Distributed infrastructure

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

Done on paper? Compare with the worked approaches