The celebrity problem and the hybrid
After this: Work out how long one celebrity post takes to fan out, and build feeds with a mix of both ways.
On this page · 7 sections · 3 checks
Lesson 3 ended with push winning by 20 times. That sum used an average: 200 followers per person. Most people have far fewer. A few have millions. What happens to push when one of them posts?
One post, 50 million inserts
A famous singer has 50 million followers and posts once. With fan-out on write for everyone:
- The post must go into 50 million feeds: 50 million inserts.
- The whole system makes about 11,574 inserts per second on average (lesson 2).
- 50,000,000 ÷ 11,574 is about 4,320 seconds, and 4,320 ÷ 60 is 72 minutes.
So one post would take all of the system's insert work for 72 minutes, while 57.9 other posts a second wait behind it. And the singer may post again tomorrow. This is the celebrity problem: push treats a post to 50 million followers like a post to 200.
Push most, pull the largest
Pull did not care how many followers an author has: a post is one write. Its cost was on reading, but most people follow only a few very large accounts. So mix the two:
- Choose a , for example 10,000.
- Accounts at or under the limit are fanned out on write, as in lesson 2.
- Accounts above it are not fanned out. Their posts are only saved.
- When someone opens the feed, the app reads the ready feed from the cache, pulls the recent posts of any large accounts they follow, and merges the two, newest first, with the heap from lesson 3.
This mix is a . Most posts, by ordinary people, are pushed. The few posts by very large accounts are pulled, and each read pulls from only the handful of large accounts that person follows.
Watch the hybrid
The same people as lesson 2, plus Zed. To keep the picture small, the limit is 4 followers, and Zed has 5: Ana, Ben, Cy, Dee and Eve.
- Ana posts p1: one job, 3 inserts (Ben, Cy, Dee).
- Cy posts p2: one job, 2 inserts (Ana, Ben).
- Zed posts p3. Zed has 5 followers, more than 4, so p3 is saved and not fanned out.
- Ben opens his feed. The cache holds p2, p1. Ben follows Zed, so the app pulls p3 from the posts database and merges: p3, p2, p1.
In total: 2 jobs, 5 inserts, 1 pulled post. Run it, and watch step 4 come in two parts.
- Feed: 3 postsPress Run it and step through. Ana and Cy post as before. Then Zed posts, and Zed has five followers, more than the limit of four. Watch what happens to Zed's post, and what the app does when Ben opens his feed.
Press Run it, then step through and watch the requests move.
Choosing the limit
A low limit pulls more accounts, so reads get slower. A high limit pushes larger accounts, so some posts take long to fan out. The right limit is a trade-off, and real services set it by measuring. In an interview, name the trade-off and pick a round number; the exact value matters less than the reason.
Check yourself
The hybrid pulls accounts with more than 1,000 followers. Ana has 300 followers, Bo has exactly 1,000, Cy has 5,000 and Dee has 2 million. Whose posts are pulled at read time?
With fan-out on write for everyone, an account with 25 million followers posts. The system makes 11,574 feed inserts per second on average. About how long do this one post's inserts take, if they got all of that speed?
In the hybrid you ran, Eve follows only Zed, whose 5 followers are more than the limit of 4. Zed has posted p3. Where does Eve's feed come from when she opens it?
In an interview
Honesty notes
- Work out the cost of one post by an account with 50 million followers: about 72 minutes of the whole system's inserts.
- Describe the hybrid: fan out ordinary accounts, pull accounts above a follower limit, and merge both when someone reads.
- Run a hybrid by hand: count the fan-out jobs, the inserts and the pulled posts, and give the merged feed.
- Say that averages hide the spread: most accounts have few followers, and a few have millions.