KatInterview

Build a Post Comment Thread with Reliable Alerts

System DesignModel answer
MediumModel answerSystem Designsystem-designcommentsnotifications

Last updated

Design the comment feature for an existing social app: APIs, schema, pagination, durable notification fan-out, and how to scale reads and writes when one post goes viral.

You are adding a comment feature to a social app that has fewer than one million users. Login, user accounts, and posts already exist and should be reused as they are. Your job is to design the comment thread under a post and the alerts it triggers.

Cover these three areas.

1. APIs and storage

  • Define how clients create, list, edit, and delete comments.
  • Describe the data model: identifiers, links to post and author, reply structure, timestamps, and edit/delete state.
  • Explain authorization and how pagination stays stable while new comments arrive.
  • Explain how a client retry of a create request avoids producing a duplicate.

2. Notifications

  • Say who gets notified (post author, parent-comment author, mentioned users) and how duplicates and user preferences are handled.
  • Show how a committed comment leads to notifications without the comment write depending on every downstream channel (push, email).
  • Explain how you recover if the system fails between committing the comment and publishing the event.

3. Scaling

  • Explain where you would add capacity for reads and writes.
  • Describe how you would handle one post that suddenly receives heavy traffic.
  • List the metrics you would use to tell an application bottleneck from a database bottleneck or a notification backlog.

Request rates, traffic distribution, and latency targets are not given, so state your own assumptions and numbers. Before finalizing the schema, say which product questions you would clarify (reply depth, what deleting a parent does, ordering, who is notified).

Hints

Hint 1

Pick answers to the product questions first (for example one level of replies, tombstones for deleted parents, chronological order) because the schema and indexes follow from them.

Hint 2

Use keyset (cursor) pagination on (post_id, created_at, id) rather than OFFSET, and give create requests a client-supplied idempotency key with a unique constraint.

Hint 3

Write the comment and an outbox row in the same transaction; a separate worker publishes events and creates notification rows, so a crash between commit and publish loses nothing.

Hint 4

Do a quick capacity estimate: even a generous assumption gives a few hundred writes per second at peak, so one primary database plus caching and replicas is likely enough. Focus on hot-post behavior and the metrics that locate the bottleneck.