Worked interview photo sharing and feedsTurn posts into a feed. Choose where the work happens.
Worked interview photo sharing and feeds. Learn the concepts, explore a model and defend your design.
12SYSTEM DESIGN
DEFINITION
A feed assembles posts that a particular reader may see in a chosen order. Its design separates media bytes, authoritative post records, follow relationships and the derived list of feed entries. This worked case uses a Meta candidate-reported topic; its scale assumptions, chronological order and original solution are teaching choices.
Photo bytes and feed metadata take different paths
A timeline reference is not a duplicate copy of the image file.
CONCEPT 1
Meta reported topic · A photo-sharing feed
1 Clarify the teaching problem
Support photo upload, following people, reading a feed and receiving a new-post notification. Start with a reverse-chronological feed, not machine-learning ranking. Require private-account access checks and accept a short delay before a new post appears in every feed. Assume ten million daily users, each reading 20 feed pages a day and creating 0.2 posts a day. These are our hypothetical numbers.
2 Calculate the important paths
Feed demand is 200 million page reads per day, about 2,315 per second on average. Two million daily posts is about 23.1 posts per second average. A stated 10x peak factor gives about 23,150 feed reads per second and 231 post writes per second. Photo bytes can dominate storage and transfer, so keep them outside the small post metadata records and calculate media size separately.
3 Define the data and APIs
Store User, Follow(follower_id,author_id), Post(id,author_id,object_key,created_at,visibility) and a feed entry referencing post IDs. Example operations are create-upload, create-post, follow-user and read-feed(cursor,limit). Use the authenticated caller for ownership. Upload bytes to object storage using limited access; mark a post ready only after the upload checks pass. A CDN can deliver suitable media, but private media still needs an access policy.
CONCEPT 2
Photo-sharing feed · Choose and defend fan-out
4 Decide when to build the feed
Fan-out on write adds a new post ID to followers' feed lists when the author posts. This makes ordinary feed reads cheaper, but one author with millions of followers can create huge write work. Fan-out on read gathers recent posts from followed authors when a reader asks. That avoids the same write explosion but makes reads more expensive. A hybrid can prebuild feeds for ordinary authors and merge popular authors' recent posts at read time.
5 Trace a complete read
Read a bounded page of feed-entry IDs, merge any required recent popular-author posts, remove duplicates and fetch display metadata. Recheck current visibility before returning private content; an old feed entry must not override an unfollow, deletion or permission change. Use a cursor with stable ordering and a tie-breaker. Keep media delivery separate so large image bytes do not pass through every feed-metadata worker.
6 Recover from partial failures
Write the post and a durable event intent consistently, for example with an outbox. Workers can retry feed distribution; make insertion safe under repeated events using a unique user-and-post relationship. A delayed worker means a temporarily stale feed, not a lost published post. Notifications need preference checks, deduplication and rate control so one active author does not overwhelm every follower. Keep notification failure separate from accepting the original post.
A concise model answer
I would separate media bytes from post metadata, serve bounded feed pages and choose hybrid fan-out according to follower distribution. I would accept a defined propagation delay, but still recheck current permissions on reads. The biggest scale trap is a popular author generating massive fan-out; the biggest privacy trap is returning an old feed entry after its access was revoked.
Write fan-out trades publishing work for reading work
STEP 1Publish postIdentify eligible followers
STEP 2Background workersAdd timeline references
STEP 3Read feedFetch prepared references
Large-follower accounts may need a hybrid policy instead of unbounded write fan-out.
Key learning points
Keep media delivery independent of small post-metadata reads.
Specify the order and allowed propagation delay.
Compare preparing entries at write time with assembling them at read time.
A derived feed entry must never override current permissions.
Compare the important ideas
Worked interview photo sharing and feeds: concepts and trade-offs
Approach
Work happens
Benefit
Cost
Fan-out on write
When an author publishes
Cheap ordinary reads
High write amplification for popular authors
Fan-out on read
When a viewer asks
Avoid massive pre-distribution
More read-time merge and lookup work
Hybrid
Split ordinary and popular-author paths
Control extreme follower cases
Two paths and deduplication require care
Async notifications
After durable intent
Do not block post acceptance
Preferences, retries and duplicates need policy
WORKED EXAMPLE
Reason about fan-out cost
Suppose an ordinary author has 300 followers and a popular author has three million. Pre-inserting one feed reference per follower creates 300 versus three million entry writes for one post. That comparison explains why average author behavior is not enough. A hybrid can keep ordinary prebuilt entries and merge popular-author posts at read time, while enforcing visibility in either path.
Further reading
Original teaching explanations by Buildfest Learn. Check these primary references for the underlying concepts and implementation details.
Interview cases adapt publicly reported topics with original teaching constraints and solutions. They are not official company questions or answer keys.
CHANGE AN ASSUMPTION. EXPLAIN THE RESULT.
Explore feed fan-out
Compare timeline write work at different follower counts. Switch to read-time assembly and identify where the work moves.
110,000 followers
25 posts/s
350,000 references/s
Modeled timeline writes: 50,000 references/s
Fan-out on write prepares follower timelines. A hybrid strategy can avoid extreme write amplification for very large authors while keeping common reads efficient.
Chapter review: two questions
Attempt both questions before opening the model answers.
Question 1
An author has two million followers and publishes three posts. Estimate feed-entry writes under pure fan-out on write, then describe a hybrid alternative.
Reveal model answer
At one entry per follower per post, six million feed-entry writes are created before other costs. A hybrid can avoid that pre-distribution for selected popular authors and merge their recent posts when readers ask. It trades lower write amplification for more read-time work and merging complexity.
Question 2
A user unfollows a private author while a fan-out job is delayed. What may the job still contain, and what must the feed read do before returning the post?
Reveal model answer
The delayed job may still carry an older follower list or an old feed-entry reference. The read must apply current visibility and ownership/permission rules before returning private content. Deletion and revocation policies must handle derived copies and media access; stale distribution does not grant permission.
Answers stay in this tab. Download before leaving. This practice is not graded or saved to your account.