Fan-out
Also called: fanout, fan-out on write, scatter.
Sending one incoming message or request out to many receivers at once. Fan-out on write copies a new post into every follower's feed when it is created, so reading a feed later is one quick lookup.
When Ana posts, the API saves it once and answers her. A background worker then writes the post into each follower's feed. More followers means more writes, but opening a feed stays one quick read.
Followers: 4 · No posts yet
Ana hasn't posted yet. Each follower has an empty feed.
Say it in a prompt
When a user posts, fan out on write: a background worker pushes the post ID onto each follower's Redis list feed:{followerId} and trims it to the newest 800. For accounts with more than 10,000 followers, skip the fan-out and merge their latest posts in at read time. Vague vs precise prompt
Vague prompt
build a home feed that shows posts from people I follow Typical resultRuns one big query joining follows and posts on every page load, and the feed gets slower with every user who signs up.
Precise prompt
Fan out on write: when a user posts, a worker pushes the post ID to feed:{followerId} in Redis for each follower (trim to 800). For accounts with over 10,000 followers, skip fan-out and merge their posts at read time. Typical resultOpening the feed is one Redis read, posting costs one write per follower in the background, and a celebrity post doesn't trigger millions of writes.
Seen on
- Amazon SNS: In its fanout scenario, a message published to a topic is copied to many endpoints, such as several SQS queues, for parallel processing.
- Twitter: Its Timelines at Scale talk, summarized by High Scalability, describes a fanout service inserting each new tweet ID into every follower's home timeline list in Redis, capped at 800 entries.
You might describe it as
- copy the new post into every follower's feed
- one event goes out to many places at once
- send the same message to all the queues
Not to be confused with
- Pub/sub
Fan-out is the copying of one message to many receivers; pub/sub is a messaging setup that does that copying through a topic.