27/30
Part 7 of 7 · Follow-upsLearn and do

Many viewers: share the ranking, keep a little state per viewer

Netflix doesn't show one billboard. Every viewer has their own rotation, and a viewer's loop has nothing to do with anyone else's. Building a Billboard per viewer copies the whole catalog per viewer, which is wasteful when the ranking is the same for everyone.

Split what's shared from what isn't:

  • Shared: the ranked order of titles, rebuilt when scores change.
  • Per viewer: the set of titles they've seen in their current loop.

The next title for a viewer is the first one in the shared order that isn't in their set. When every title in the order is in the set, the loop is over: clear the set and start again.

Check "every title is in the set" with the titles themselves, not with the sizes. A viewer's set can hold a title the catalog has since dropped. Then the set is as big as the catalog while a title is still unseen, and a size check starts a new loop too early.

Walking the order from the top is O(n) per call in the worst case. A per-viewer cursor into a versioned order is O(1), and when the version changes, you fall back to the set.

The editor holds next_for. Write next_for(order, seen) to return a viewer's next title, starting a new loop when every title in order is in seen.