AlgoViz

Design Netflix

hard 45 min

Paying members press play and a film starts within two seconds, in the quality they paid for.

See it run

A press on play, a film on its way to the boxes, a night of filling, a buffer and a stream limit.

Operations

Press on play

Rights, licence and bytes until the first picture.

Step 1 of 11

Play

Our systemTelevisionGatewayPlayback serviceLicence serviceEdge boxat the providerPlayer events

device

4K television

The viewer presses the button. The app had fetched the title's data while it was in focus.

Step 1: Play

def start(req):    acc = auth(req)    check_plan(acc, req.device)    check_rights(req.title, acc.country, req.profile.age)    if not leases.start(acc, req.session, limit=acc.streams):        return 409, "too_many_streams"    return 201, {"manifest": manifest(req), "resume_at": pos(req),                 "boxes": steering.rank(req)}# device: at the same timelicence = fetch_licence(session)init, first = box.get("init"), box.get("seg/1")decoder.show(decrypt(init, first, licence))
Time
1.8 s here, 2 s target
Load
1 session, 1 licence

When a title is in focus, the app already fetches its data and opens connections.

In the real world

The same subscription streaming doing real jobs. Pick one and step through it.

Ten million plays in one minute.

Step 1 of 4

Days before

Forecastviews by siteFill plannerObject storageExchange boxesall 2.1 PBProvider boxes360 TB

Every box gets the files, hidden until the hour.

Step 1: Days before

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Count streams up and down

    critical

    A device without power never says stop, and the member is locked out.

    Wrong
    start: n += 1     stop: n -= 1
    Right
    lease 90 s, renewed by heartbeats
  • Put members' data on boxes

    critical

    The boxes stand in other companies' rooms.

    Wrong
    box: files + history + keys
    Right
    box: encrypted files only
  • Pull only

    major

    Everybody misses in the same evening, over full links.

    Wrong
    on miss: fetch from storage
    Right
    night: copy what tomorrow needs
  • Rank by views times size

    major

    Huge files push out small popular ones.

    Wrong
    key = views * gb
    Right
    key = views   # saved bytes per byte stored
  • A spare region that sleeps

    major

    It fails on the one day it is needed.

    Wrong
    region C: cold standby
    Right
    three active regions, each with room for a half

Interview tips

  • Name the lever

    • 2.1 PB is small.
    • Tomorrow is predictable.
    • The night is free.
  • Keep planes apart

    • Decide in the cloud.
    • Send from boxes.
    • Different failures.
  • Check units

    • 29M × 5 Mb/s: terabits.
    • 17,000 titles: petabytes, not exabytes.
    • Say units aloud.
  • Fail softly

    • Next box, lower quality.
    • Old rows before errors.
    • Leases open, payment closed.