Learning pathsPricingChecking sign-in…
GUIDED PRACTICE

Practice: FB Live Comments

Design a comment stream for live videos, including durable posting, fast fanout, reconnect, and moderation.

Design a comment stream for live videos, including durable posting, fast fanout, reconnect, and moderation.

Write your own design before opening hints or the solution review. The numbers below are exercise assumptions, not claims about any company’s production traffic. You may challenge an assumption, but record the replacement and explain which decision changes.

Scenario and constraints

  • Typical room: 100 viewers; largest room: 100,000 viewers.
  • Largest room receives 100 comments/s at 500 bytes/event.
  • Target visible updates within one second under normal conditions.
  • Retain replay history for one hour in this exercise.

Your deliverables

  • Define accepted-comment and displayed-comment guarantees separately.
  • Specify a room-scoped event cursor and client deduplication behavior.
  • Calculate largest-room raw fanout bandwidth and place its bottleneck.
  • Show a bounded slow-client buffer and an explicit reset response.

Reason about this sequence

Gateway sends cursor 52 → Connection drops → Client reconnects after 51 → Replay includes 52 → Client dedupes and resumes
FB Live Comments · scenario walkthrough
Read the diagram

Gateway sends cursor 52 → Connection drops → Client reconnects after 51 → Replay includes 52 → Client dedupes and resumes

Open original
FB Live Comments · scenario walkthrough
Gateway sends cursor 52 → Connection drops → Client reconnects after 51 → Replay includes 52 → Client dedupes and resumes

FB Live Comments · scenario walkthrough

For every step, annotate what is durable, what the caller knows, and which identity survives a retry. Identify the point where two concurrent actors could disagree. Do not assume a timeout means failure or a cache value grants ownership.

Interviewer follow-ups

  • A gateway crashes immediately after sending an event.
  • A viewer returns with a cursor older than one hour.
  • Moderation removes a comment already cached on clients.

Answer each follow-up using the same design first. If it breaks, change the smallest boundary that repairs the invariant and explain the new cost. Show whether the change adds latency, storage, coordination, or operational work.

Staged hints

Hint 1 — reveal

Answer: Hint 1 — A socket is a delivery attempt, not a durable mailbox. Start by deciding where a disconnected client can recover the last hour of events.

Hint 2 — reveal

Answer: Hint 2 — After durable acceptance, publish to a room distribution tier. Gateways own client connections and subscribe only to rooms they serve. A fanout tree or broker layer prevents one producer from directly writing to a million sockets. Measure bytes per comment times viewers, not just comments posted per second.

Hint 3 — reveal

Answer: Hint 3 — A gateway crashes after forwarding an event but before the client records its cursor. The reconnect replay includes that event again. Client deduplication avoids showing it twice. Conversely, if the client records a cursor before applying an event, it may skip content. Define the client apply-and-cursor sequence and test network flaps, delayed removals, and history expiry.

Evidence-based self-review

  • Durable acceptance precedes the claimed success response.
  • The fanout design accounts for viewers times event rate.
  • Reconnect handles both overlap and expired history.
  • Moderation and authorization apply across live and history paths.

Score each item 0 if absent, 1 if named without an enforceable mechanism, or 2 if the mechanism and a failure are explained. Record evidence from your own diagram beside the score. Then choose one weak decision, revise it, and repeat the relevant follow-up. This rubric is a learning tool, not a hiring forecast.

Clarify this prompt before choosing components

Ask the highest-impact questions first, agree on priorities, and record the interviewer’s answers. If a detail is unspecified, state an assumption and explain which decision depends on it. The numbers in this worked lesson are exercise assumptions, not company facts.

Ask the interviewerWhy the answer changes the design
Per-stream order or a global order?A hot stream needs an explicit ordering owner; global order is usually unnecessary.
Peak viewers, comments/s and acceptable delivery lag?Bound fan-out, replay and slow-client buffers.
How do moderation and reconnect affect already delivered comments?Define delete/tombstone updates and gap-resume semantics.

Use the Interview Playbook for the shared 45-minute sequence and fresher, intermediate, senior and staff evidence. Start with one complete operation. Extend the answer with the failure/recovery traces below, then defend a workload-specific alternative and a measurable rollout. Scope and evidence matter more than a large component list.

Reveal the full worked solution

Save your attempt before continuing.

FB Live Comments: Understand the building blocks

Choose a mechanism because it satisfies a requirement. These explanations describe the exercise design, not undisclosed implementation choices at the named company.

FB Live Comments: Quick vocabulary

TermMeaning and role in this exercise
API: Application Programming InterfaceThe contract for requests, responses and errors between components. An API route does not itself enforce every business invariant.
HTTP: Hypertext Transfer ProtocolThe request/response protocol used by web APIs and media fetching. Application retries still need safe operation identities.

FB Live Comments: Server-Sent Events (SSE)

What it means: A server-to-client event stream over HTTP. Client commands still use a separate request path.

Why this problem needs it: Viewers primarily receive low-latency comment events.

How to use it: Give events stable IDs and define retention/replay when reconnecting; bound slow-client buffering.

Example in this design: Receive identified server events while posting comments via an authorized request.

When it fits: Useful for comments, progress or model output when the client primarily receives updates.

Alternative and limits: WebSocket provides bidirectional messaging. SSE event IDs are not a database transaction or a guarantee of unlimited replay.

FB Live Comments: WebSocket

What it means: A protocol for bidirectional messages over a persistent connection after a handshake. It is a transport, not a durable message store.

Why this problem needs it: Bidirectional interactions may justify a different transport.

How to use it: Authenticate the session, route incoming messages to their owner, and bound outgoing buffers. Reconnect using application message IDs and cursors.

Example in this design: Choose it for the declared interaction contract; do not infer durable history from a socket.

When it fits: Useful when both sides send frequent low-latency updates.

Alternative and limits: Polling is simpler at low update rates; Server-Sent Events fit one-way server updates. A new connection does not restore missed messages by itself.

Mechanism reference

FB Live Comments: Snapshot, retained suffix and recovery cursor

What it means: A snapshot records state at a named revision; the retained suffix contains later changes; a cursor marks a declared consumed position.

Why this problem needs it: Disconnects need a bounded replay cursor and overlap handling.

How to use it: Recover from one consistent snapshot/revision and replay the necessary suffix with stable identities. Reset explicitly when required history expired.

Example in this design: Replay 41–50 and live 49–53 deduplicate by event identity.

When it fits: Useful to bound replay and let disconnected clients catch up.

Alternative and limits: Full replay is simpler for tiny histories. A cursor beyond unapplied events can lose updates; two unrelated reads do not form one consistent snapshot.

FB Live Comments: Durable work queue and backpressure

What it means: A queue separates accepted work from execution. Backpressure limits admission or consumption when downstream capacity is finite.

Why this problem needs it: Slow clients must not cause unbounded broadcast buffering.

How to use it: Persist a stable job identity, consume with bounded concurrency, acknowledge after the required durable transition, and cap retries/backlog according to policy.

Example in this design: Cap a subscriber queue and disconnect/reset according to the agreed loss policy.

When it fits: Useful for asynchronous work that must survive worker failure or absorb a finite burst.

Alternative and limits: A synchronous call is simpler for short bounded work. A queue does not create capacity, strict global ordering or exactly-once external effects.

Interview scope and guarantees

Post comments to a live event, display recent comments with low delay, reconnect without duplicates, and remove moderated content. Ordering is per stream or shard, not necessarily global across the service. Slow consumers must not stall the broadcaster.

Capacity worksheet

Assume one event has 1 million viewers and 1,000 comments/s. Sending every 200-byte comment to every viewer would be 200 GB/s before protocol overhead. That product expectation is often unnecessary; offer a moderated or sampled view, batch updates, and define what each viewer receives.

Concrete API contract

Contract / pseudocode
POST /streams/{id}/comments {clientId,text} -> {commentId,sequence}
GET /streams/{id}/comments?after=...
SSE /streams/{id}/events?cursor=...
DELETE /comments/{id} -> moderation event

Data model and access paths

Contract / pseudocode
comments(stream_id,sequence,comment_id,author_id,text,state)
stream_offsets(stream_id,partition,offset)
moderation(comment_id,version,state)
client_dedup(author_id,client_id,comment_id)

Evolve a solution and explain each change

Three architecture decisions for FB Live Comments, including the pressure each introduces.
Three architecture decisions for FB Live Comments, including the pressure each introduces.
Read the diagram

Append comments / Authenticate the author and append a stream-scoped comment ID. / Per-viewer polling wastes work and does not define replay.; Push bounded streams / Fan out persisted comments over session connections with resume cursors. / Slow viewers can accumulate unbounded buffers.; Handle hot broadcasts / Shard fanout delivery, filter moderation changes, and shed overload predictably. / Delivery shards do not automatically create a global comment order.

Open original
FB Live Comments · architecture decisions
Three architecture decisions for FB Live Comments, including the pressure each introduces.

Three architecture decisions for FB Live Comments, including the pressure each introduces.

Step 1: Append comments

Authenticate the author and append a stream-scoped comment ID. Per-viewer polling wastes work and does not define replay.

Step 2: Push bounded streams

Fan out persisted comments over session connections with resume cursors. Slow viewers can accumulate unbounded buffers.

Step 3: Handle hot broadcasts

Shard fanout delivery, filter moderation changes, and shed overload predictably. Delivery shards do not automatically create a global comment order.

Responsibility overview

Connected responsibilities for FB Live Comments. Trace the authoritative and derived paths separately.
Connected responsibilities for FB Live Comments. Trace the authoritative and derived paths separately.
Read the diagram

Viewer to Comment API: post or resume; Comment API to Comment log: append stream position; Moderator to Comment API: moderate comment; Comment log to Fanout worker: durable delivery intent; Fanout worker to Session registry: find active sessions; Fanout worker to Viewer: bounded live delivery

Open original
FB Live Comments · connected architecture
Connected responsibilities for FB Live Comments. Trace the authoritative and derived paths separately.

Connected responsibilities for FB Live Comments. Trace the authoritative and derived paths separately.

Worked end-to-end scenario

A viewer posts c20 and disconnects before the response. Retrying the client comment ID returns the stored comment. Broadcast subscribers receive c20 through fanout workers, but a slow phone fills its buffer. Rather than accumulating unlimited memory, send a resync signal or disconnect according to policy. The phone reconnects with its stream cursor and fetches a bounded persisted range. A moderator removes c20. The system emits a tombstone or removal event; reconnect replay must not resurrect it. A hot stream can use several delivery shards while one ordered ingest partition assigns stream positions.

Why these access paths matter

Persist by broadcast ID and stream position. Deduplicate author/client IDs and index moderation state. Connection registries map broadcast shards to active sessions; they are ephemeral delivery state, not authoritative history. If sampled comments are allowed under overload, state that separately from full replay and make the client aware of gaps.

Build the baseline first

FB Live Comments: baseline request paths.
FB Live Comments · working baseline
Read the diagram

Comment API → durable append → ordered stream; Fanout service → connection gateway → viewers; Reconnect cursor → retained history → live handoff

Open original
FB Live Comments · working baseline
FB Live Comments: baseline request paths.

FB Live Comments · working baseline

  1. Comment API → durable append → ordered stream.
  2. Fanout service → connection gateway → viewers.
  3. Reconnect cursor → retained history → live handoff.

Evolve the design under load

FB Live Comments: additional scaling and recovery paths.
FB Live Comments · scale and recovery paths
Read the diagram

Stream partitions → regional fanout tree; Gateway batches → bounded client buffers; Moderation event → removal projection → clients

Open original
FB Live Comments · scale and recovery paths
FB Live Comments: additional scaling and recovery paths.

FB Live Comments · scale and recovery paths

  1. Stream partitions → regional fanout tree.
  2. Gateway batches → bounded client buffers.
  3. Moderation event → removal projection → clients.

Defend the hardest decision

An append log preserves a resumable position. Gateways subscribe once per popular stream and fan out locally, rather than establishing one broker subscription per viewer. A client that cannot keep up receives a bounded backlog or a reset-to-latest instruction. If the system samples comments, the UI must not imply a complete ordered transcript. A cursor should encode the shard positions needed to resume a partitioned stream.

Failure and recovery analysis

After a disconnect, subscribe to the live stream while fetching history with a defined high-water mark, then deduplicate the overlap. Fetching history first and subscribing later creates a gap. A moderation deletion must suppress future replay and update connected clients; removing only the database row leaves already-buffered copies visible.

Security and privacy boundary

Rate-limit authors, escape rendered content, and preserve moderator audit trails without leaking removed text to unauthorized readers.

Interview follow-ups with reasoning

Question: Can SSE replace WebSockets?

Show answer and explanation

Answer: Yes for server-to-browser updates while posting uses HTTP.

Question: How do you handle a viral stream?

Show answer and explanation

Answer: Split fanout work across regions and gateways while protecting the append authority.

Question: What do you measure?

Show answer and explanation

Answer: Publish-to-display lag, slow-client drops, reconnect gaps and moderation propagation delay.

Operate and verify the design

Publish-to-display delay, slow-client drops, replay resets and moderation lag.

Reconnect a viewer during a burst and verify the history/live handoff has no unexplained gap.

A second scenario to test transfer

A room receives 100 comments/s and has 100,000 viewers. At an illustrative 500 bytes per delivered event, raw fanout is 5 GB/s before protocol overhead. The storage write rate is modest compared with delivery bandwidth. A popular-room tier can batch or sample display events under a stated UX policy while preserving accepted comments in history. Adding database replicas alone does not solve socket fanout.

A reconnect cursor is older than retained events. What should the server return?

Show answer and explanation

Answer: An explicit reset/snapshot requirement with a new valid cursor. Silently starting at the newest event would hide a gap. The UI can show a recent window and disclose that earlier live history is unavailable.

Compare alternatives

ConcernMechanismTrade-off
Hot roomHierarchical fanoutMore routing state
Slow deviceBounded buffer + resumeMay need snapshot reset
ModerationRemoval events + authoritative historyPropagation delay
OrderingRoom-scoped cursorNo global ordering promise

A design-changing exercise

A fanout node crashes after accepting a comment. Is the comment lost?

Show answer and explanation

Answer: Not if acceptance meant durable log insertion. Delivery can be reconstructed from the log and subscriber cursors; memory-only fanout is not enough.

Design workshop: replay-to-live without gaps

Core scope is posting, recent history, live viewing and moderated removal for one broadcast. Ranking every historical comment is excluded. Choose live delivery p95 under one second under admitted load, durable accepted comments and a 30-minute replay window. Popular-room display sampling, if enabled, is disclosed; it does not delete accepted history.

CONNECT /streams/id/comments accepts afterCursor. Events include streamId, sequence, commentId, type, contentVersion and payload. A cursor binds stream and position; a cursor for another stream is rejected. If it precedes retention, return reset_required with a recent snapshot and new cursor. Never silently return only newest events while pretending the suffix is complete.

Subscribe to live output, capture durable high watermark H, fetch (cursor,H], then consume live output after H. Buffer/overlap may repeat events, so deduplicate by stream/sequence. A bounded buffer overflow during handoff aborts and requires another replay. Attaching after a historical query without a watermark can lose the events between those steps.

A cursor 40 joins a stream at watermark 43. Viewer to Gateway: Resume after 40; Gateway to Room fanout: Subscribe with bounded buffer; Gateway to Durable log: Read high watermark H=43 and suffix 41..43; Room fanout to Gateway: Buffered event 43 then 44; Gateway to Viewer: Deliver 41,42,43; drop overlap 43; deliver 44; Gateway to Viewer: Persist/ack last delivered cursor 44
A cursor 40 joins a stream at watermark 43.
Read the diagram

Resume after 40; Subscribe with bounded buffer; Read high watermark H=43 and suffix 41..43; Buffered event 43 then 44; Deliver 41,42,43; drop overlap 43; deliver 44; Persist/ack last delivered cursor 44

Open original
A cursor 40 joins a stream at watermark 43
A cursor 40 joins a stream at watermark 43. Viewer to Gateway: Resume after 40; Gateway to Room fanout: Subscribe with bounded buffer; Gateway to Durable log: Read high watermark H=43 and suffix 41..43; Room fanout to Gateway: Buffered event 43 then 44; Gateway to Viewer: Deliver 41,42,43; drop overlap 43; deliver 44; Gateway to Viewer: Persist/ack last delivered cursor 44

A cursor 40 joins a stream at watermark 43.

A room log assigns sequence under one ordered append authority. Fanout delivery is then sharded across gateway groups; delivery-shard IDs are not a room-wide order. A session registry maps room→gateway populations and expiring sessions. Root fanout distributes batches to regional workers, then gateway groups, then bounded per-socket queues. Persisted history stays independent of session presence.

Fanout budget for a hot broadcast. 1,000 comments/s × 1M viewers × 200 bytes / 200 GB/s raw payload / Network hierarchy, not only DB scaling; 100,000 sockets × 8 KiB buffer / 819 MB buffer payload / Connection metadata adds more memory; Batch 20 events over 20 ms / One envelope per batch / Bound latency; reduce protocol overhead; Slow socket exceeds buffer / Reset and recent snapshot / Do not allocate unlimited memory
Fanout budget for a hot broadcast.
Read the diagram

Assumption / Calculation / Implication; 1,000 comments/s × 1M viewers × 200 bytes / 200 GB/s raw payload / Network hierarchy, not only DB scaling; 100,000 sockets × 8 KiB buffer / 819 MB buffer payload / Connection metadata adds more memory; Batch 20 events over 20 ms / One envelope per batch / Bound latency; reduce protocol overhead; Slow socket exceeds buffer / Reset and recent snapshot / Do not allocate unlimited memory

Open original
Fanout budget for a hot broadcast
Fanout budget for a hot broadcast. 1,000 comments/s × 1M viewers × 200 bytes / 200 GB/s raw payload / Network hierarchy, not only DB scaling; 100,000 sockets × 8 KiB buffer / 819 MB buffer payload / Connection metadata adds more memory; Batch 20 events over 20 ms / One envelope per batch / Bound latency; reduce protocol overhead; Slow socket exceeds buffer / Reset and recent snapshot / Do not allocate unlimited memory

Fanout budget for a hot broadcast.

Sample display at a gateway only under a product contract that labels the stream as selected comments. Preserve ordering among delivered events and carry a cursor over skipped ranges so resume semantics are explicit. Full-history clients query the durable log, not the sampled socket stream. Backpressure can reject new writes with 429 under overload or accept durably and signal delayed delivery; choose the boundary honestly.

Moderation appends a versioned removal event for comment C. Clients apply newer content versions and retain a bounded tombstone so a delayed create cannot resurrect C. Reconnect snapshots exclude removed content. A moderator can race with publication; authorization and policy checks happen at the write authority and renderer. Report moderation propagation lag separately from accepted-comment latency.

Exercise: Live output is subscribed at time T, the historical query returns through 43, and events 43/44 are buffered. What is sent?

Show answer and explanation

Answer: History through 43, then only buffered events strictly after 43. If the buffer overflows, restart from a supported durable cursor rather than skip to the latest event.

Requirement trace and verification

RequirementImplementing design blockVerification link
R1 — Complete the primary user journey within the stated scope.P01–P04; P09–P10.V1 — Exercise the successful journey and the excluded/boundary case stated in the scope.
R2 — Preserve the problem's authoritative data invariant under concurrency.P05–P06; P11–P12; DD1.V2 — Run the race/replay case below and assert the invariant at the durable authority.
R3 — Meet the declared scale and API behavior without unbounded work.P05–P08; P13–P14; relevant overload deep dives.V3 — Exercise the API errors/retry identity and recompute the workload assumption that drives partition or capacity.
R4 — Recover from the named failure without losing or duplicating the user-visible outcome.P15–P16; deep dives; Operations contract.V4 — Disconnect mid-stream and reconnect while new comments arrive; verify stable order and documented sampling behavior.

Operational contract

AreaDecision and signals
SLIsPublish-to-display lag; replay/live gap resets; moderation lag; slow-client drops; hot-room queue depth.
Overload limitsCap per-stream publish rate, subscriber fanout, replay window, and slow-client buffers.
RecoveryResume from durable sequence/snapshot watermark; reset expired cursors from a consistent snapshot.
Access controlsApply stream membership and moderation policy before fanout; protect private room and author data.
Dominant costHot-stream fanout bandwidth and retained replay history.

Senior-level interviewer follow-ups

Question: A viewer subscribes while the room is receiving comments. How do you avoid a gap?

Show answer and explanation

Answer: Return a high-watermark cursor, subscribe, and replay the overlapping range with deduplication by room sequence. Bound the buffer and fall back to a fresh snapshot if replay exceeds retention.

Question: What does a slow viewer receive when a celebrity room exceeds fanout capacity?

Show answer and explanation

Answer: Apply a documented room policy such as sampling, batching, or dropping low-priority updates while preserving ordering metadata and moderation removals. Bound per-client buffers and expose the degraded mode.

A 60-second design answer

I would persist moderated comments with a room sequence, then fan them through a hot-room distribution tier. Subscribe-and-replay uses a watermark and deduplication to close the live/history race. Slow consumers receive bounded batches or a documented sampled view; moderation removals carry versions. I would measure room skew, replay lag, dropped updates, buffer pressure, and end-to-end freshness.

Real-time Updates Kafka

Technical references

Kafka processing and external-sink boundaries.

PostgreSQL transaction isolation and concurrent updates.

Join history and live delivery at one watermark

Capture a consistent retained-history boundary 100. Return history through 100 and subscribe/replay from 101 under a protocol that closes the handoff gap. If the live path repeats 100, stable sequence deduplication removes it. Reading history first and only afterward subscribing without replay can lose comments committed in between.

Contract / pseudocode
history snapshot: through 100
new comments: 101,102
live/replay start: after 100
duplicate 100: ignore; apply 101,102
history snapshot: through 100; new comments: 101,102; live/replay start: after 100; duplicate 100: ignore; apply 101,102
Join history and live delivery at one watermark
Read the diagram

history snapshot: through 100; new comments: 101,102; live/replay start: after 100; duplicate 100: ignore; apply 101,102

Open original
Join history and live delivery at one watermark
history snapshot: through 100; new comments: 101,102; live/replay start: after 100; duplicate 100: ignore; apply 101,102

Join history and live delivery at one watermark

SSE is a reasonable one-way browser path; user posting remains an authenticated API operation. Routing by stream and distributing scoped events avoids making every server process every comment. A mega-stream may exceed one viewer's useful rate: declare sampling/coalescing or snapshots rather than promising every event to every client. Bound client buffers and reconnect work, and recheck access on resume.

Show answer and explanation

Answer: An expired Last-Event-ID requires resync under retention rules. A socket reconnect succeeding does not prove the missing comments were recovered.

Decision review: FB Live Comments

FB Live Comments: What it is

A live-comment design accepts identified events, fans them out and joins replay to live updates without a silent gap.

FB Live Comments: Why it is needed

Connections fail and clients progress independently; slow consumers can consume unbounded buffers if not controlled.

FB Live Comments: When to use it

Use a retained event/cursor contract when reconnect must recover missed comments; permit snapshot/reset when the cursor exceeds retention.

FB Live Comments: How to use it

Establish the replay/live handoff at a known watermark, apply overlapping event IDs once and enforce current room/moderation policy. Bound per-connection buffers and define disconnect, drop or resync behavior.

FB Live Comments: Compare an alternative

Polling can satisfy a looser freshness target with less connection state. Push reduces update latency but adds routing, buffer and reconnect work.

FB Live Comments: Worked decision exercise

The following inputs and policies are original exercise assumptions; they are not measurements or undisclosed company behavior.

A viewer applied through 41. It replays to watermark 50 while live subscription buffers 49–53. Deduplicate the overlap and deliver 51–53 after the replay boundary; an unordered switch must not lose event 51.

FB Live Comments: Viewer applied through 41; replay target watermark 50; Live subscription overlaps at 49 and 50; Apply overlap once, then continue with 51 onward; Expired cursor requires a declared reset
FB Live Comments: a concrete state and recovery trace under the exercise assumptions.
Read the diagram

Viewer applied through 41; replay target watermark 50; Live subscription overlaps at 49 and 50; Apply overlap once, then continue with 51 onward; Expired cursor requires a declared reset

Open original
FB Live Comments: worked example
FB Live Comments: Viewer applied through 41; replay target watermark 50; Live subscription overlaps at 49 and 50; Apply overlap once, then continue with 51 onward; Expired cursor requires a declared reset

FB Live Comments: a concrete state and recovery trace under the exercise assumptions.

If a client reconnects beyond retained history, may the server pretend the old cursor is complete?

Show answer and explanation

Answer: No. Return a declared reset or current snapshot and explain the loss/recovery policy. Do not advance applied progress before application. Removed comments or revoked membership still need the serving policy, regardless of cursor validity.

FB Live Comments: Check the design

Observe fanout lag, buffer occupancy, forced resync and applied-cursor gaps. Test a gateway crash at the replay/live handoff and a client that never drains.

Extension: Applied replay and persistent moderation evidence

Start with durable comments, replay/live handoff and bounded fanout. This workshop adds broadcast/view lifetime, application cursors, out-of-order moderation and selected-display recovery.

Deep dive: delivered comments and complete replay are different evidence

The baseline already defines retained history, bounded fanout and replay-to-live overlap. This workshop adds broadcast lifetimes, application-applied cursors, sampling identity and moderation floors. These are original exercise policies, not a description of Facebook's implementation. Choose one ordered durable ingest authority per broadcast lifetime; delivery gateways scale independently. A partitioned-ingest alternative needs vector cursors and cannot inherit a single global room sequence by changing the drawing.

Bind a cursor to the broadcast and view it actually covers

A reused public stream ID can refer to another broadcast, so create a non-reused incarnation. A comment command carries authenticated author, stream/incarnation, scoped request ID and bounded text. Append the comment, receipt and publication intent atomically. A compatible retry returns its original accepted comment; a changed payload conflicts and a different incarnation is a different scope. Acceptance does not mean every viewer displayed the comment.

Contract / pseudocode
broadcast(stream_id, incarnation, owner_epoch, next_sequence, lifecycle)
comment(id, stream_id, incarnation, accepted_sequence, body_revision, body)
moderation(comment_id, policy_revision, visible, audit_ref)
command(author, stream_id, incarnation, request_id, payload_hash, accepted_result)
cursor(stream_id, incarnation, viewer_scope, selection_revision, processed_prefix)
client_state(comment_id, body_revision, moderation_revision, visible, applied_prefix)

The replay cursor binds stream, incarnation, authorized viewer scope and selection policy revision. A full transcript and a sampled display do not share completeness semantics. A sampling change either preserves a declared compatible decision history or explicitly resets to a new view snapshot. Reject foreign, expired or old-incarnation cursors rather than interpreting sequence 50 from yesterday as sequence 50 today.

A selected-display cursor means every position through it has a known disposition under that view: displayed, currently suppressed or intentionally skipped. It does not mean every accepted comment was delivered. Control envelopes can state bounded skipped intervals; they must not contain removed comment text or leak private moderation reasons. Do not advance over an unexplained gap simply because a later comment was visible.

Work replay overlap while a removal arrives first

The client has applied through 41. Establish a live subscription, capture durable boundary H=50, replay (41,50] and retain bounded live overlap 49–53. Apply each selected event or explicit skip disposition once and transition to the suffix after 50. Buffer overflow aborts this handoff and requires a new bounded resync; it cannot silently drop 51 and still advance through 53.

Now a moderation removal for comment C20 reaches the client before an old history page that contains C20. Store moderation revision 3/hidden even if C20's body is absent. The late body revision 1 cannot erase that independent moderation floor. A later body edit is not a permission change either. Only an authorized newer moderation decision, such as revision 4/visible under the declared restore policy, can change that state. Keep body and moderation revisions separate; comparing their unrelated integers is meaningless.

Replaying through H does not entitle history to bypass policy that became current afterward. History/reconnect/read paths obtain applicable current visibility evidence before disclosure; connected clients receive removal control events and measure propagation lag. Already delivered text cannot be recalled universally. State whether the service promises authoritative denial of new reads, bounded connected-client removal, or stronger online checks; do not call an asynchronous UI deletion instantaneous revocation.

For this selected-display exercise, moderation control is never randomly sampled. Under overload, reserve its delivery budget or invalidate/reset the view; dropping removal while retaining buffered body events can resurrect hidden text. Retain client/server moderation floors through the maximum body replay/buffer lifetime, including zero/hidden state. If that evidence is no longer retained, bootstrap a current visibility snapshot before replay rather than treating missing policy as visible.

Comment recovery: removal revision 3 arrives before the old body, the client retains its hidden floor, history replays body revision 1, and current policy prevents resurrection
FB Live Comments: recovery decision
Read the diagram

Removal revision 3 arrives before body → Client retains independent hidden floor → History replays old body revision 1 → Body update cannot erase current moderation → Resume uses complete application prefix

Open original
FB Live Comments: recovery decision
Comment recovery: removal revision 3 arrives before the old body, the client retains its hidden floor, history replays body revision 1, and current policy prevents resurrection

FB Live Comments: recovery decision

Commit application progress instead of trusting transport receipt

SSE event IDs support transport reconnection, but browser receipt is not proof the application durably applied a comment or removal. The HTML Standard's SSE specification defines event IDs and reconnection behavior; the normalized client state and applied cursor are application responsibilities.

In this exercise, commit a processed disposition and the complete application prefix with local state under the supported client storage boundary. A crash after receiving 52 but before applying 51 must resume from 50. An automatically retained transport Last-Event-ID of 52 cannot certify the missing application transition. Controlled reconnect opens a new stream using the persisted application cursor; the server defines and validates its precedence over any transport header. Do not let a larger unvalidated header override that requested cursor.

A browser paint and a durable client commit are different milestones. If local storage is unavailable, use explicit volatile replay semantics and accept duplicate recovery work instead of claiming durable progress. Deduplicate by stream/incarnation/event identity and versioned state; repeated removals do not remove a different later comment with the same display position. Authenticate resume and recheck room access before returning snapshots or buffered content.

Below the thirty-minute replay floor, return reset-required with a compatible recent snapshot and boundary. Mark the selected/recent nature of that snapshot and do not claim the missing interval was recovered. A reconnect storm cannot demand unlimited thirty-minute replay for every phone: cap history rows/bytes, concurrent snapshots, retries and live handoff buffers. A viewer may need to rejoin near current time under the disclosed policy.

Keep sampling, retained history and hot-room budgets explicit

At 1,000 accepted comments/s and one million viewers, delivering every 200-byte comment to everyone requires 200 GB/s raw. If a selected view delivers twenty comments/s to every viewer, it still requires 4 GB/s before envelopes, TLS, retransmission and moderation. Sampling reduces fanout, not ingest durability, and it must never be presented as an exact transcript. Viewer-specific ranking/filtering also changes what a cursor covers.

An eight-KiB per-connection queue across one million connections is about 8.192 GB of payload capacity before connection/runtime overhead. Bound aggregate gateway memory as well as per-client queues. Slow clients use a declared disconnect/reset behavior; a durable log is not permission to buffer indefinitely in RAM. Batch compatible display events without merging away the moderation/version identities needed for replay.

At 1,000 events/s, a thirty-minute history contains 1.8 million positions. A reset snapshot with only the last hundred eligible comments does not satisfy a full-history replay promise. A 600,000-event materialization backlog at 5,000/s processing with 3,000/s arrivals takes at least 300 seconds to drain. Budget moderation and current-policy checks during catch-up, not just ordinary display throughput.

Monitor accepted-to-visible latency separately from selection rate, current visibility lag, application-prefix gaps, replay-floor resets and buffer-induced disconnects. Failover recovers the broadcast incarnation, complete log prefix, receipts and visibility state before serving the same contract; a new owner epoch is not a new broadcast identity. Rollout of sampling/selection revisions must preserve cursor meaning or force a clearly labeled reset. These teaching histories do not implement SSE, client storage, policy authentication or real gateway fanout.

Live-comment assessment: say which prefix was actually applied

Question: Removal revision 3 arrives before an old body page. Can the client show the old body until another removal arrives?

Show answer and explanation

Answer: No. Keep the independent hidden moderation floor even without a body, and merge later body revisions without resetting it. Current policy also gates server history disclosure. Body revision numbers are not moderation authority and already downloaded content has a separate recall limit.

Question: The browser retained SSE ID 52, but application state is complete only through 50. Where does controlled reconnect begin?

Show answer and explanation

Answer: From the persisted application cursor through 50. Replay 51 onward under the same authorized incarnation/view, deduplicate overlap and advance only after known dispositions. Transport receipt is not proof of application commit; unexplained gaps cannot be skipped.

Question: A sampling revision changes and the old cursor is below retention. May the API return the latest hundred comments as complete recovery?

Show answer and explanation

Answer: No. Return an explicit compatible recent snapshot/reset and disclose selected coverage. Bind the new cursor to its view policy and preserve current moderation. Bound reset/replay work instead of pretending the lost interval was delivered.

Score one point each for broadcast/incarnation/view/operation identity; complete replay/live/application progress; independent moderation floors and current disclosure; explicit sampling/reset semantics; finite fanout, memory and recovery budgets. Letting old body replay erase a removal or advancing from a transport ID across unapplied work is a critical failure. Repair the replay state machine, then retest with a selection change, a returning old broadcast cursor and moderation during a full handoff buffer.

30:00Self-guided practice timer
The timer resets when you leave this page. Save your design separately.
Your challenge

A reconnect cursor is older than retained events. What should the server return?

Your design draft

Clarify assumptions, explain your approach, and test the difficult cases. Save your draft, then compare it with the study notes.

Open solution review

Self-review checklist

Self-guided practice. Automated AI feedback and code execution are not connected.