Interview: one celebrity posts, and every timeline in the app slows down

Feed fan-out. Slide the follower count to see writes per post against reads per view for push, pull and hybrid, using a 5,800 posts/s example.

More on Ticket interviews

Keep learning

Overview

Two ways to deliver a newspaper. Top: the paper boy puts a copy in every subscriber's mailbox when the paper is printed. Bottom: one pile sits at the newsstand and each reader walks over to collect it. For a very famous author the pile stays at the newsstand. Deliver when printed (write) … one per fan Work happens once, at print time. Reading is opening your box. Collect when read (read) one pile per author … every reader walks over Work happens at every read. Printing is free. timeline writes/s · 1.16M timeline reads/s · 2M post writes/s · 5.8K follow lookups/s · 400M Log-scale bars for an example of 5,800 posts per second, 200 followers each, and 10 million users refreshing every 5 seconds. Fan-out on write: about 1.16 million timeline writes per second and 2 million cheap reads per second. Fan-out on read: only 5,800 writes per second but 400 million lookups per second. Fan-out on write (push) Fan-out on read (pull) per second, log scale · an example, not a benchmark Star A Star B Hybrid timeline. Posts from normal accounts were pushed into the viewer's stored timeline. Posts from celebrities stay in the celebrities' own lists. When the viewer opens the app, the two lists are merged by time into one timeline, newest first. Stored timeline (pushed) Celebrity lists (pulled at read time) merge by time What the viewer sees, newest first One cheap stored read, plus a few small lookups for celebrities. A post arrives follower timelines (first 40 shown) author’s own list 1 write no timeline writes at all celebrity: no timeline writes A reader opens the app my stored timeline Fan-out on write copy the post into every follower’s timeline Fan-out on read gather the posts when someone opens the app push for normal accounts, pull for celebrities typical · 200 popular · 50K celebrity · 50M One author posts. Slide their follower count and watch the work move. Number of followers, log scale Celebrity threshold, log scale at 1M writes/s, the whole average load nothing to deliver You gain It costs Pick when Avoid when Opening the app is one lookup. Reads far outnumber posts. A few accounts are huge. Fan-out on write via a queue Posts arrive a bit late. Queue to run. Bursty posting, push at scale. Everyone must see it instantly. One write per post. Follows are instant. Every view merges every followed account. Few readers, small follow lists. Many readers or huge follow lists. Hybrid (push, but pull celebrities) Cheap reads, no write storms. Two code paths plus a tuned threshold. Audiences range from tiny to millions. Everyone’s audience is small. Explain simply: what is fan-out, and why not always do it on write? explain simply One post becomes one request per follower. On write, huge accounts make huge bills. Pick by which happens more, and by the extreme accounts. move work between write and read extremes matter What breaks if a 100-million-follower account posts under pure fan-out on write? what breaks if One post eats about 100 seconds of the whole write budget. Everyone else’s posts queue behind it. All timelines go stale. queue backs up for everyone dropping is not OK here separate store + merge Do the numbers: 5,800 posts per second, 200 followers each. What is the write load? What if you polled instead? Push: about 1.16M writes/s. Pull: about 400M lookups/s. Push: 5,800 posts × 200 followers ≈ 1.16M timeline writes per second. multiply followers by posts multiply views by follows compare the two totals What would you do instead of picking only one? what would you do instead Hybrid: push normal accounts, pull celebrities. Celebrity posts live in their own list. On open: stored timeline + a few celebrity lists, merged by time. Tune the threshold: write cost vs extra read lookups. hybrid by follower count a tunable threshold Someone follows 30,000 accounts that post constantly. Their timeline gets a flood of writes. Fine? edge case Yes. Dropping some writes for this reader is fine. Drop per reader, never per author. Follows and unfollows must update timelines too. drop for heavy followers not for celebrities follow changes update timelines Curveball: the author edits or deletes a post that sits in 5 million timelines. What do you do? staff level Store only post ids in timelines, so edits happen once. At read time, fetch post bodies by id from a store or cache. A timeline is derived data. Keep copies small, so syncing stays cheap. ids not bodies one source of truth derived data must stay in sync Fan out inside the post request The author waits. Use a queue. Copy the whole post into every timeline Edits become millions of writes. Store ids. Drop a celebrity’s writes to cope Loses what everyone came for. Using the average follower count Averages hide the accounts that cause outages. Defined fan-out: write vs read Did the maths: writes/s vs lookups/s Celebrity case breaks pure push Hybrid with merge at read Timelines hold ids, not bodies Busy posting. One cheap lookup per read. One write per post. Busy merging on every read. timeline writes, one post whole write budget (example) everyone else waits Push moves the work from reads to writes. Same app, different bill. The viewer’s list is one stored list plus a few celebrity lists, sorted by time. Reader follows 30K Drop some writes. A sample is fine. Celebrity posts Never drop. Pull and merge instead. Whole post in each timeline Post id in each timeline

One celebrity posts, and every timeline in the app slows down.

Each post is copied into every follower’s timeline, so reads are fast. Then one account with 100 million followers posts. celebrity problem materialized timeline One celebrity post makes every timeline minutes late. Hybrid: push normal accounts, merge celebrity posts at read time.

Mailboxes or a newsstand

A daily paper can be delivered to every subscriber’s mailbox as soon as it is printed. Or it can sit in one pile at the newsstand, and each reader walks over to collect it. Mailboxes: printing is busy, reading is easy. Newsstand: printing is easy, reading is busy. For a famous author with millions of subscribers, filling every mailbox takes forever.

Everyone’s timeline is minutes behind whenever one account posts

Mobile team Workers copy each new post into every follower’s timeline. When a huge account posts, workers stay busy for a long time. Friends’ posts show up minutes late. average followers posts per second ≈ 5,800 (book example) biggest account > 100M followers friends’ posts delay minutes (illustrative) The question: keep reads fast, and stop one huge account starving everyone. Show the numbers.

Slide the followers. Watch the work move.

followers: push is ideal followers: push still fine followers: push breaks What to notice: the extremes decide the design. The hybrid only changes past the threshold. What to notice: pull ≈ 400M lookups/s. Push ≈ 1M writes/s plus 2M cheap reads. What to notice: the reader still gets one sorted list.

Four ways to build a home timeline

50 million users, a few thousand accounts with over 1 million followers. What do you build? Hybrid: push for normal accounts, merge celebrities at read Reads stay cheap and huge accounts never cause write storms. Cost: two code paths and a threshold. Read speed Write storms Code complexity Push for everyone, with a bigger worker pool and a queue Pull for everyone, cache the merged result No write storms, but every cache miss reads every followed account. New posts keep busting the cache.

A model spoken answer

Design the home timeline. What about celebrities? Do the math ~1M writes/s push vs ~400M lookups/s pull. The catch Celebrity lists merged at read time.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.