Design a Live Comments System: Junior, Senior, and Staff Answers
When an interviewer asks you to design a live comments system they want to see how you balance real-time delivery, data durability, and cost. They look for a clear request-path walk-through, sensible data modeling, and an awareness of the trade-offs between consistency and latency. Below we walk through the core design, then layer on what each interview level should cover.
Core Design Overview
1. Request Path – One Hop at a Time
- Client → API Gateway – The browser sends a POST to
/commentsor a GET to/comments?articleId=…. API Gateway validates auth tokens and forwards the request. - API → Lambda (Write Path) – The Lambda function extracts the payload, enriches it with a server-side timestamp, and writes the comment to a DynamoDB table keyed by articleId and commentId (a ULID for monotonic ordering). It also pushes a lightweight event to an SQS queue for downstream processing.
- SQS → Lambda (Fan-out) – A second Lambda consumes the event, writes the comment to an ElastiCache (Redis) sorted set for fast retrieval of the most recent N comments, and republishes the event to a Kafka on MSK topic used by the real-time push service.
- Kafka → WebSocket Service – A fleet of EC2 instances runs a WebSocket server (or uses Amazon API Gateway WebSocket) that subscribes to the Kafka topic. As soon as a new comment arrives it pushes the payload to all connected clients for the article.
- Client → API (Read Path) – When a user opens the article, the client issues a GET request. The Lambda first checks Redis for the recent comment window; a cache miss falls back to a DynamoDB query for the full comment history, which is then cached.
2. Data Model
| Entity | Primary Key | Sort Key | Important Attributes |
|---|---|---|---|
| Comment | articleId (partition) | commentId (ULID) | userId, text, createdAt, status |
| CommentMeta | articleId | — | lastCommentId, commentCount |
The ULID guarantees lexical order that matches creation time, so retrieving the latest N comments is a simple range query. status supports moderation (e.g., visible, hidden).
3. Key Choice – DynamoDB vs Aurora
We pick DynamoDB because writes are cheap, can scale to millions of writes per second, and the schema is simple. Aurora would give stronger relational guarantees but would require sharding or read-replicas to handle the same write volume, adding complexity and cost.
What a Junior Answer Covers
- Functional requirements: post comment, read recent comments, pagination, basic moderation.
- Non-functional requirements: low latency (< 200 ms for reads), durability, handle spikes of a few thousand writes per second.
- Simple flow: client → API Gateway → Lambda → DynamoDB. Reads go directly to DynamoDB.
- Data model: single table with
articleIdpartition key,commentIdsort key. - Scalability basics: enable DynamoDB auto-scaling, use provisioned throughput.
- Missing pieces: no caching, no real-time push, no async processing.
What a Senior Answer Adds
- Caching layer: add ElastiCache (Redis) for the most recent comments to meet sub-100 ms read latency.
- Asynchronous fan-out: introduce SQS and Kafka on MSK to decouple writes from real-time delivery, allowing the system to absorb write spikes.
- Ordering guarantees: use ULIDs or a monotonic sequence generator to keep comments in order without a global lock.
- Sharding strategy: partition DynamoDB by
articleIdand use a high-cardinality hash (e.g.,articleId#shardId) if a single article can receive >10 k writes per second. - Basic monitoring: CloudWatch alarms on write throttling, Lambda error rates, and queue depth.
- Moderation hook: a background Lambda reads from the same Kafka topic, runs a profanity filter, and updates the
statusfield.
What a Staff Answer Looks Like
- Failure modes: discuss what happens if Redis is unavailable (fallback to DynamoDB), if Kafka lags (use a dead-letter queue), and if a Lambda times out (retries, exponential back-off).
- Operational concerns: rolling deployments of the WebSocket fleet, schema migrations in DynamoDB using versioned items, and backup strategy (DynamoDB point-in-time recovery, S3 export of comment archives).
- Cost analysis: estimate write volume (e.g., 100 k comments/day ≈ 1.2 writes/sec) and read volume (10 k reads/second during a live event). Show that DynamoDB on-demand plus a modest Redis cache stays under a few hundred dollars per month, whereas over-provisioning Kafka clusters would dominate cost.
- Trade-off defense: argue why eventual consistency for reads is acceptable; real-time ordering is guaranteed only for the most recent window, older pages can tolerate slight re-ordering.
- Advanced scaling: use CloudFront with signed URLs to serve static comment archives from S3, reducing load on DynamoDB for historic data.
- Security: IAM policies for least-privilege Lambda access, API Gateway authorizers, and encryption at rest for DynamoDB and S3.
Common Mistakes That Sink the Question
| Mistake | Why It Hurts |
|---|---|
| Ignoring write spikes | Live events can push QPS from a few hundred to tens of thousands; without async buffering the system throttles. |
| Over-engineering ordering | Trying to enforce global ordering with a single write lock kills scalability; a ULID or per-shard sequence is simpler. |
| Forgetting moderation | Interviewers expect a hook to hide abusive comments; missing it suggests lack of product thinking. |
| No caching | Reading DynamoDB for every viewer of a busy stream multiplies read cost and can throttle the hot partition, which puts the real-time requirement at risk. |
| Skipping ops | Without monitoring, alarms, and rollback plan the design looks brittle. |
How to Practice This
- Study the worked design for a live comments system in the System Design AI library; note the step-by-step board and the component notes.
- Draft your own answer on a blank canvas: start with the basic request path, then layer caching, async fan-out, and finally ops concerns.
- Use the practice brief rubric to evaluate whether you covered junior, senior, and staff expectations, then iterate based on the AI coach feedback.
Questions people ask
What are the main scalability challenges for a live comments system?
The biggest challenges are handling sudden write spikes during live events, keeping read latency low for millions of concurrent viewers, and ensuring ordered delivery without a single bottleneck.
Why use DynamoDB instead of a relational database for comments?
DynamoDB provides horizontal scaling with low write latency and can handle high QPS without manual sharding, which matches the bursty traffic pattern of live comments.
How does real-time delivery work without overloading the backend?
Writes go to DynamoDB and an SQS queue; a fan-out Lambda pushes the event to Kafka, and a WebSocket service subscribed to Kafka streams the comment to connected clients instantly.
What is a simple way to order comments reliably?
Generate a ULID (or similar monotonic identifier) on the client or Lambda; ULIDs sort lexicographically in creation order, letting you retrieve comments with a range query.