SD-26 · Back to the write-up
Design a Concurrent Stream Limits
Every playing device holds a 3-minute lease, renewed every minute; one atomic script per account decides if a new screen fits.
Follow a request
Press play
At the limit
Heartbeat and license
Stop another device
A TV loses power
Devices
Edge
Services
Data
PlayerTV, phone, browser
Device pushStop now
Auth servicePlan in the token
Load balancerSpreads requests
License server5-minute keys
Stream-limit serviceStateless
Lease store32 shards by account
Accounts DBPlans, devices
Session eventsAnalytics
The numbers, at a glance
1 start ≈ 40,000/s17 heartbeats ≈ 667,000/s
4M10 s
1.3M30 s
667K60 s
333K120 s
94% heartbeats6% starts
A start, in order
The whole check is one script on one shard, so two starts on one account never interleave.
Player
Load balancer
Stream-limit service
Lease store
License server
1 POST /streams + token
2 route
3 prune, count, add
4 added, 2 of 2
5 201 session
6 201 session
7 license request
8 lease live?
9 yes
10 5-minute key
RequestResponseAsync, does not block
How the count is kept
The decision this question is really about.
COUNT(*)
INSERT row
667K writes/s
+ Familiar.− A write per heartbeat; races.
INCR on start
TV unplugged
stuck at 2 of 2
+ Tiny and fast.− Crashes never decrement.
prune expired
countadd if room
one shard, one step
+ Heals itself; atomic.− Crash frees in 3 minutes.
How it grows
Add a box only when a number forces you to. Highlighted boxes are new at each stage.
Player
App server
SQL database
Player
Load balancer
Service × N
Lease storeAccounts DB
PlayerAuth service
Load balancer
Service × N
Lease store × 32Accounts DB
PlayerAuth serviceDevice push
Load balancerLicense server
Service × N
Lease store × 32Accounts DBSession events
Was this walkthrough useful?Your vote tells us what to improve next.