KatInterview

Live Comment Thread with Instant Local Posting and Reconciliation

System DesignModel answer
MediumModel answerSystem Designsystem-designoptimistic-uiidempotency

Last updated

Design a live comment feature where new posts show up instantly on the author's screen, then reconcile safely with server acknowledgments, broadcast events, retries, and durable storage.

You are building the comment section for a page where many people read and discuss at once, such as a live event page or a shared document. Comments from other people should appear in near real time.

A key requirement is that the author's own comment shows up in the list the moment they hit submit, so they can keep scrolling, typing, or reacting while the network request is still in flight.

Design the full system, covering the client, the API, the real-time channel, and storage.

What to cover

  • How a locally rendered, not-yet-confirmed comment is identified, and how that identity is later replaced by the server's identity.
  • How the write path avoids duplicate comments when requests are retried or time out with an unknown outcome.
  • How the server's response and the live broadcast event for the same comment are merged without showing it twice.
  • How comments are ordered, and what happens to a pending comment's position when the server assigns the final order.
  • What the user sees for pending, failed, and retrying comments, and what actions they have.
  • How history is stored durably and how a client that reconnects or opens a second device catches up.

Assumptions

  • A pending comment on screen does not mean the server accepted it. The UI must treat it as provisional.
  • Decide and state your position on edits and deletes, ordering guarantees, and delivery guarantees (at-most-once, at-least-once, exactly-once effect).
  • Give rough scale numbers and say how they influence your choices.

Treat the points below as clarifying questions you should answer or assume explicitly: can comments be edited or deleted, how are they ordered, what should happen after a timeout where the commit outcome is unknown, and must a second device see the same conversation?

Hints

Hint 1

Give every comment two identities: a client-generated ID created at submit time and a server-assigned ID and sequence. Think about which one the retry key should be.

Hint 2

Assume the same comment can arrive twice on the client, once in the HTTP response and once through the live event, in either order. What single rule makes both paths safe?

Hint 3

Separate display order from commit order. Ask what a reconnecting client needs to send, such as a last-seen cursor, to fetch exactly what it missed.

Hint 4

Model the pending comment as a small state machine (sending, confirmed, failed, retrying) and decide which transitions are legal after a timeout.