Skip to content

Feeds: choose fan-out and stable pagination

10 min reading

A feed design whose ordering and audience rules are explicit

Page details

System Design · Compose complete systems

10 min reading · 25 min with practice

Sources

Published · Last edited:

Prerequisite: Chat after disconnection. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. Northwind buyers follow supplier activity. Dev proposes copying every new activity into every follower’s inbox. Priya points to a large audience whose members rarely open the feed and asks how much work that one publication creates.

Dev: “The prebuilt inbox would make the read straightforward.”

Maya: “Compare the publication cost with the reads this audience actually needs.”

Build a chronological baseline by comparing publication-time materialization with read-time assembly. Keep source authority, withdrawal and stable pagination visible. This supplier workload is separate from the preceding chat and short-link cases; a later ranking policy would be a new requirement. Most suppliers have modest audiences; a few have many followers. New pages must respect the declared withdrawal policy. Personalized ranking remains outside this first release.

The core state is posts, follow relationships and visibility decisions. A reader's assembled feed is derived state. Its freshness and completeness can differ from the authoritative post record, but those differences must be intentional. A cache hit cannot establish that the reader is still permitted to see an item.

Scope includes posting, following, pagination, visibility and derived-view recovery. Advertising auctions, video processing and personalized ranking are excluded. This case studies fan-out and read assembly rather than promising a universal social platform.

What does a reader’s feed represent?

Fan-out-on-write appends a reference into recipient inboxes when a post is created. It makes some reads inexpensive but multiplies write work by recipients and requires handling follow changes and deletion. Fan-out-on-read stores author histories and assembles a reader's view later, shifting work toward reads.

Neither is always better. A quiet reader may never consume eagerly prepared entries. A highly active reader may repeatedly need expensive merge work. A publisher with a large audience can dominate fan-out while contributing little post volume.

Do not use one average follower count to hide that distribution. Identify hot publishers, active-reader fractions, retention and the freshness expected for new follows. Those inputs determine whether a mixed strategy is useful.

Separate post authority from reader projections

Write a post under a stable identity and author authority. Record publication intent with the authoritative change. Projection workers append deduplicated references to eligible recipient inboxes. They preserve the source post version so retries and older updates do not recreate withdrawn content.

A mixed feed assembles references from two pathsOrdinary posts populate derived reader inboxes. High-fan-out author histories can be merged at read time. A final visibility check applies before returning the assembled page.Reader inbox refsSelected author logsMerge + cursordeduplicateVisibility checkpage + next cursor

A read merges the selected sources under an explicit ordering rule, removes duplicates and checks visibility. Use a deterministic tie-breaker, such as an agreed creation order plus unique identity. If ordering changes between pages, define whether the cursor pins a snapshot or permits bounded movement.

A hybrid design may retain ordinary author fan-out while reading selected high-fan-out histories directly. That requires one coherent merge contract. Calling a publisher a special case does not eliminate authorization, freshness or pagination obligations.

Make feed materialization a workload choice

Hypothetical scenario. Store posts at their source and feed entries as references, not independent copies of truth. A push design appends references to reader inboxes when a publisher posts. A pull design merges eligible publisher histories when a reader opens the feed. A hybrid chooses cohorts under an explicit rule.

Make feed materialization a workload choice — selected design evidence
RecordKey / fieldsAuthority
Postpublisher + post ID, order key, visibilitySource post owner
Followreader + publisher, membership versionRelationship owner
Feed referencereader + order key + post IDDerived materialization
Page cursorboundary key, tie-break, view ruleRead contract
Push and pull move work between publication and reading while source eligibility remains authoritative.Push and pull move work between publication and reading while source eligibility remains authoritative. Publisher source to Reader inboxes: push references; Publisher source to Merge on read: pull source histories; Reader inboxes to Merge on read: hybrid reader merge.Publisher sourceReader inboxesMerge on readpush referencespull source historieshybrid reader merge
Push and pull move work between publication and reading while source eligibility remains authoritative. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

For a separate toy comparison, choose one publisher with one hundred followers, two posts and ten active readers each opening once. Push writes 100 × 2 = 200 references; pull considers 10 × 2 = 20 publisher-post candidates before merge overhead. These are different work units, not a claim that pull is ten times faster. Cost weights, freshness, other followed publishers and read frequency determine the decision.

Use a cursor with a stable ordering key and tie-break identity. Under concurrent insertions, a cursor can avoid ordinary offset shifting, but completeness still depends on its declared snapshot or moving-view semantics. Deletion and changed visibility can remove entries between pages. Source permission and current post state must govern display even if an inbox reference remains.

Derive the fan-out and read cost

Hypothetical scenario. Choose 10,000 ordinary authors producing two posts daily with 100 recipient inboxes each. Logical posts are 10,000 × 2 = 20,000 per day. Projection appends are 20,000 × 100 = 2,000,000 per day, excluding retries and later relationship changes.

Now one publisher creates ten posts for 100,000 followers. Its fan-out alone is 10 × 100,000 = 1,000,000 references daily, half the ordinary group’s append work from only ten posts. That difference is why a single global average hides an important design choice.

Choose 32 bytes per logical reference. Three million daily references use 3,000,000 × 32 = 96,000,000 bytes, or 96 MB. Thirty days retain 96 × 30 = 2,880 MB, or 2.88 decimal GB of reference payload before indexes, replication and allocation. This is not the size of the original post bodies or a complete storage estimate.

For read assembly, suppose one page examines five author streams and requests 20 candidate references from each. It considers 5 × 20 = 100 candidates before filtering and deduplication, but returns at most 20. A visibility filter that removes many candidates may require another bounded fetch; it cannot promise a full page without more work.

A projection backlog of 120,000 references with 20,000 appends per minute of capacity and 10,000 new references per minute drains at 20,000 −10,000 = 10,000 per minute. Recovery takes 120,000 ÷ 10,000 = 12 minutes under constant successful processing rates. Cold reads during that interval need a declared fallback.

Give the cursor actual semantics

For the first chronological release, select a deterministic ordering position and unique tie-breaker. Decide whether one browsing session pins a boundary or tolerates later arrivals ahead of its current position. Bind the cursor to the reader and query so a position from one feed cannot quietly become authority to read another.

An opaque token can carry that state, but opacity is not the invariant. New posts, removed posts and follow changes alter the candidate population. Specify whether older posts appear after a new follow and how unfollow affects already materialized entries. A ranked view would add a different ordering contract and is deferred.

In the wild: timeline APIs expose pagination choices

Mastodon’s timeline API documentation specifies authenticated home-timeline access and pagination parameters. It is an inspectable public API contract, not evidence of Northwind’s materialization strategy or Mastodon’s internal storage layout.

The projection records publication before the source commits

Hypothetical failure scenario. A worker appends an activity reference to reader inboxes while the source transaction is still pending. That transaction aborts. Readers now hold a reference to an activity the service never accepted. Retrying the projection does not supply the missing authoritative publication.

Bind the accepted source change and durable downstream intent at the selected local commit. Dispatch afterward and recognize repeated projection work by source identity and version. An inbox is a projection of accepted activity, not an independent authority that can create publication by receiving a message.

Choose a simple first path and name its limit

Start with indexed supplier histories and a bounded chronological merge when that meets the measured workload. Introduce materialized reader references where repeated serving work or latency justifies them. If choosing a mixed path, preserve one deduplication and ordering contract across eagerly copied and directly read activity.

The selected fan-out counts exclude retries, later relationship changes and physical storage overhead. They justify investigating concentrated work, not provisioning a fixed number of machines. Monitor candidate-to-return ratio and projection age as well as publication latency. The next page changes publisher concentration and removal timing while retaining this baseline.

Challenge the proposed mechanism

A page returns ordered eligible identities and a cursor whose view semantics are stated.A page returns ordered eligible identities and a cursor whose view semantics are stated. Reader to Feed view: 1 · cursor-bound page; Feed view to Post authority: 2 · eligible source references; Feed view to Reader: 3 · ordered identities + cursor.ReaderFeed viewPost authority1 · cursor-bound page2 · eligible source references3 · ordered identities + cursor
A page returns ordered eligible identities and a cursor whose view semantics are stated. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

Which publisher should move to pull when follower count grows?

Reveal the design reasoning

Compare weighted write fan-out with active-reader merge demand and freshness, including current background debt. A follower threshold alone misses inactive audiences and repeated reads. State an exit condition and measure the selected cohort.

Decision and reconsideration: Choose a feed cohort using its actual publish/read mix. Keep source identity and page observation rules explicit.

Defend the materialization decision

  1. A publisher emits few posts but dominates projection appends. Which input matters?

    Count recipients per post

    Fan-out multiplies publication by recipients. The selected ten posts for one hundred thousand followers produce one million references despite the small source-post count.

  2. The cursor is an opaque string. Does it guarantee stable pages?

    Inspect ordering and scope

    No. It must represent a defined order, tie-breaker and any required snapshot context, bound to the reader and query. A renamed offset supplies none of those properties automatically.

  3. Five streams supply twenty candidates each. Is a full twenty-item page guaranteed?

    Account for filtering

    No. The hundred candidates may include duplicates or ineligible activity. Further bounded fetching or an explicit short-page result may be necessary.

The baseline exposes the cost of publication and reading. Page 46 changes the publisher distribution and withdraws an activity during replay, testing whether the same source and eligibility rules survive.

Northwind decision log

Keep accepted activity and visibility authoritative outside reader projections.
Choose materialization from recipient distribution and actual read demand.
Next, isolate high-fan-out publishers and preserve removal through replay.

Go deeper: communication and workflow boundaries