Buildfest Learn System DesignRead and experiment freely · Chapter activities stay in this tab
Practice librarySystem DesignWorked interview photo sharing and feeds

LESSON 12 • SYSTEM DESIGN

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.

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
  1. CONCEPTObject storage + CDNDeliver eligible photo bytes
  2. CONCEPTPost databaseOwn post metadata
  3. CONCEPTTimeline storeServe ordered feed entries

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
  1. STEP 1Publish postIdentify eligible followers
  2. STEP 2Background workersAdd timeline references
  3. 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
ApproachWork happensBenefitCost
Fan-out on writeWhen an author publishesCheap ordinary readsHigh write amplification for popular authors
Fan-out on readWhen a viewer asksAvoid massive pre-distributionMore read-time merge and lookup work
HybridSplit ordinary and popular-author pathsControl extreme follower casesTwo paths and deduplication require care
Async notificationsAfter durable intentDo not block post acceptancePreferences, 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.