skip to content

In document data modeling, what is fan-out on write versus fan-out on read, and how do you choose?

level: middleimportance: must knowfreq 62%

answer

  1. someone has to pay: writer or reader
  2. count how many documents hold the copy
  3. read-to-write ratio decides it
  4. one popular account breaks the arithmetic
  5. real answers are usually hybrid

basics

~20 s

Fan-out on write copies a fact into every document that will need it at write time, so reads are single lookups. Fan-out on read stores it once and gathers it from many sources per read. Choose by read-to-write ratio and fan-out size.

solid answer

~50 s

Fan-out on write means the writer pays: when a fact is produced, it is written into every document that will need to read it, so a later read is one targeted lookup with no assembly. Fan-out on read means the reader pays: the fact is stored once and each read gathers it from the sources that own it. The choice is arithmetic plus latency. If a fact is read far more often than it changes and the fan-out is bounded, writing copies is cheap and reads get fast and predictable. If the fan-out is huge or unbounded, or the fact changes constantly, write amplification and the sync obligation dominate and you should read it live. Real systems usually split: fan out on write for the common case and read live for the pathological entities — the account with millions of followers whose every post would trigger millions of writes.

code

json · 11 lines
json
// Fan-out on write: assembled at publish time, read is one lookup
{
  "_id": "feed:user-77",
  "entries": [
    { "postId": "p-501", "authorId": "u-12", "authorName": "Ada", "text": "...", "at": "2026-08-19T10:02:00Z" }
  ]
}

// Fan-out on read: one copy of the post, assembled per read
{ "_id": "p-501", "authorId": "u-12", "text": "...", "at": "2026-08-19T10:02:00Z" }
{ "_id": "follows:user-77", "following": ["u-12", "u-31", "u-44"] }

go deeper

for a junior

Be able to state the trade in one line: fan-out on write makes reads a single lookup by doing extra work when data is written; fan-out on read keeps one copy and assembles at read time.

for a middle

Explain the three numbers that decide it — write rate, read rate, fan-out factor — and show you know that fan-out on write also fixes read latency rather than only reducing total work.

for a senior

Bring the hybrid: fan out on write for ordinary entities, read live for the high-fan-out ones, and copy only the small stable fields. Talk about propagation lag as a measured, alarmed property.

for a principal

Own the failure mode before it happens: identify which fan-out factors are unbounded, decide what the system promises about propagation lag, and set the threshold at which an entity switches strategies.

## The two shapes Every denormalization decision is ultimately about *when* the work of assembling data happens. **Fan-out on write** does the work at write time. When a new fact appears — a post is published, a user changes their display name, a price is set — the writer immediately pushes copies of it into every document that will later need to read it. The classic example is a feed: publishing a post appends an entry to each follower's feed document. A later read of a feed is one lookup of one document, already assembled, with no per-read joins and a latency that barely depends on how complex the underlying relationships are. **Fan-out on read** does the work at read time. The fact is stored exactly once, in the document that owns it, and each read gathers it from the sources. Reading a feed means finding who the user follows, then querying recent posts from each of them, then merging. Nothing is duplicated, nothing can drift, and a change to a post is one write — but every read pays the assembly cost, and the cost grows with the reader's connections. ## The arithmetic Start with three numbers: how often the fact is written, how often it is read, and the fan-out factor — how many documents would hold a copy. A fact read a thousand times for every write, duplicated into a handful of documents, is an easy fan-out-on-write case: you pay a few extra writes to eliminate a thousand assemblies. A fact rewritten constantly and copied into hundreds of thousands of documents is the opposite: each source write becomes a storm of copy writes, and by the time the storm finishes the value may already have changed again. The dangerous middle is a fan-out factor that is *unbounded* — no maximum you can state — because the design works fine in staging and collapses on the largest real entity. ## Latency shape, not just total cost Fan-out on write converts a variable, connection-dependent read latency into a fixed one. That is often worth more than any total-work saving: a feed that reads in a few milliseconds regardless of whether you follow ten accounts or ten thousand is a product feature. It also moves the expensive work off the user-facing path — the copies can be written by a background consumer while the publisher's request returns immediately. Fan-out on read keeps writes trivial and predictable and makes reads the variable part, which is fine when reads are rare, internal, or already batched. ## The hybrid, and why it is the real answer Most production designs are hybrids, split on the property that breaks the arithmetic. The standard example is the celebrity account: fan out on write for ordinary users, and for the small set of accounts with enormous follower counts, do not write copies at all — read their recent posts live at read time and merge them with the precomputed part of the feed. The read path becomes "one assembled document plus a live query for a handful of high-fan-out sources", which keeps both the write storm and the read assembly bounded. The same split appears outside feeds: duplicate a team's name into member documents unless the team has a hundred thousand members, in which case read it. A second hybrid axis is *which fields* you copy. Copying a small, rarely-changing subset — an id, a display name, a thumbnail — gives most of the read benefit for a fraction of the sync obligation, while volatile fields stay behind a live read. ## What fan-out on write costs beyond writes Copies consume storage and cache space proportional to the fan-out, which can matter more than the write cost when the working set stops fitting in memory. They also create a permanent correctness obligation: every copy needs an owner, a bounded staleness, and a way to be found and repaired. And they raise a delivery question — if the copies are written asynchronously, the write is acknowledged before the reads are correct, so the propagation lag becomes a user-visible property you must measure. ## How to answer Name both shapes, state the three numbers that decide between them (write rate, read rate, fan-out factor), and add the two refinements that mark experience: latency shape matters independently of total work, and real systems go hybrid at the entities where the arithmetic breaks rather than picking one strategy globally.

  • What makes a fan-out factor 'unbounded', and why is that the real danger sign?
    Unbounded means you cannot state a maximum — followers, group members, subscribers can all grow without limit. The design is validated against typical entities and then meets the largest one, where a single write turns into an enormous burst of copy writes that saturates the write path and delays every other change. Bounded fan-out fails predictably; unbounded fan-out fails suddenly and only in production.
  • If copies are written asynchronously, what does the user-visible contract become?
    The write is acknowledged before all readers can see it, so the system promises correctness only within a propagation lag. That lag must be measured and alarmed on, not assumed, and the product has to tolerate it — a feed entry arriving a second late is fine, a permission or a balance is not. Anything that must be correct at the moment of the read stays a live lookup.
  • Which fields would you copy and which would you leave behind?
    Copy small, rarely-changing, display-oriented fields — an identifier, a name, a thumbnail path — because they give most of the read benefit for little sync cost. Leave volatile fields (counts, status, current price) and anything used for authorization or money out of the copy and read them from the owning document, where they are correct by construction.

Fan-out on write is a mailroom that photocopies a notice into five hundred mailboxes the moment it arrives; fan-out on read is a single notice on the wall that every reader walks over to check.

saying these in an interview costs you the question

  • Picks one strategy globally instead of splitting on fan-out size
  • Ignores that fan-out on write amplifies every source update
  • Assumes fan-out on read is always 'the normalized, safe choice'
  • Compares only total work and ignores read latency shape
  • Copies volatile or security-relevant fields to speed up reads

context