Bugpit

Lessons › Big architectures

Watch next: a row for every person

A streaming app at the evening peak: 12,000 req/s. A quarter are home screens asking what this person should watch next, 3,000 a second. Today a model scores all 20,000 titles for each of them, and the plays, pauses and ratings, 15% of requests, are saved one by one into the main database.

Play this level

Part of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

Recommending is two jobs. First pick a few hundred titles worth considering out of 20,000. That's candidate generation, and it has to be cheap: a Vector DB finds the titles whose embeddings sit close to what this person watches. Then the expensive model ranks only those.

The model needs to know what someone did a minute ago, not last month. Keep each person's latest features in a fast store, here a NoSQL DB, and let the model read them. That's a feature store. A Stream Processor keeps it fresh from every play and rating.

The same events are tomorrow's training data. A Worker copies them to a Data Warehouse, where the model is retrained overnight. Training is slow and offline, serving is fast and online, and they never share a machine.

The model will fail one day, and brand new users have no history at all. Both get the same answer: what's popular right now. That fallback is how recommenders handle a cold start.

What you have to achieve

12,000 requests a second at the busiest hour, 15% of them writes.

What you learn

The model scores 500 titles a request instead of 20,000, so 8 GPU machines do what 240 couldn't. Every play reaches the feature store in seconds and the warehouse in time for tonight's training. Real recommenders go further: they mix in a few titles the model is unsure about, to keep learning, and test a new model on a slice of users before it replaces the old one.

Check yourself

Why not let the model score every title for every person?

Show the answer

Its work grows with each title scored, so 20,000 a request needs 40 times the machines. Ranking is the expensive step. A cheap candidate step cuts 20,000 titles to a few hundred, and only those are ranked.

Someone signs up and hasn't watched anything yet. What should they see?

Show the answer

What's popular right now, until their own history builds up. That's the cold start problem. Popular picks are the same fallback you use when the model is down.

Why retrain the model from a warehouse instead of the live database?

Show the answer

Training reads months of history, and on the live database it would slow every user. Training is offline and heavy, serving is online and fast. Keeping them apart means neither gets in the other's way.

If you only ever show the titles the model scores highest, what goes wrong?

Show the answer

It never learns about titles it doesn't show, so new ones never get a chance. Showing only what you're sure of is exploitation. Mixing in a few less certain picks, exploration, is how the model keeps learning.

Try it yourself

More in Big architectures

← Black Friday, worldwide Payouts: every cent accounted for →