Design a News Feed (Twitter Timeline), stage 6 of 9: break it
The post that wouldn't die
Find every line that contributes to either problem, or would fall over on a large account.
System so far· 9 parts
Select a component to see what it is responsible for and which state it owns.
- 1Authors → Write API: Post
- 2Write API → Post store: Store post
- 3Write API → Fan-out queue: Fan-out job
- 4Fan-out workers → Fan-out queue: Take jobs
- 5Fan-out workers → Social graph: Active followers
- 6Fan-out workers → Timeline cache: Push ID, trim to 800
- 7Readers → Timeline service: GET home timeline
- 8Timeline service → Timeline cache: Page of IDs
- 9Timeline service → Post store: Hydrate; large accounts' recent posts
- Request / response
- Asynchronous
What you need to know
0 of 2 checks done
A Redis list used as a capped timeline needs two operations per insert:
LPUSHadds the newest entry at the front, andLTRIM key 0 799drops everything past 800. Without the trim, lists grow forever.Sending both in one pipeline (many commands in one round trip) keeps it cheap.
Work it out
A worker awaits each insert separately, at about 1 ms per round trip. How many minutes for an account with 1 million followers?Check
Timelines store IDs. Where does a deleted post get removed from what followers see?