Design a Chat System like WhatsApp: Junior, Senior, and Staff Answers
When you hear "Design a chat system like WhatsApp" the interviewer is looking for three things: how you reason about massive scale, how you balance latency against consistency, and how you think about operations. They expect you to start from a single request and walk the path hop by hop, exposing the components you would use, the data model, and the trade-offs you made.
What the interviewer is testing
- Scalability – can you handle millions of users and billions of messages per day?
- Consistency vs. availability – where do you favor eventual consistency and where do you need strong guarantees?
- Operational insight – do you consider monitoring, failure handling, and cost?
- Communication skills – can you explain each piece clearly and justify choices?
Requirements and driving numbers
| Requirement | Typical figure (hedged) |
|---|---|
| Daily active users (DAU) | 10 million (≈ 115 users/second) |
| Messages per day | 200 million (≈ 2,300 messages/second) |
| Latency target for a send-receive cycle | < 200 ms end-to-end |
| Message retention | 30 days of history per chat |
These numbers drive three design dimensions:
- Throughput – the system must ingest a few thousand messages per second and serve a comparable read load.
- Storage – at 200 M messages/day, 30 days of history is ~6 billion records. With a 1 KB payload each, that’s ~6 TB of raw data, plus indexes.
- Latency – users expect near-real-time delivery, so the critical path must stay in memory as much as possible.
Core design in prose
Request path, one hop at a time
- Client – the mobile app uses HTTPS (or gRPC) to talk to an API Gateway (Amazon API Gateway). The gateway terminates TLS and routes to the appropriate service.
- Auth & routing – a Lambda authorizer validates the JWT from the client and injects the user ID.
- Message service – a stateless ECS/Fargate service receives the POST /messages request. It performs validation, writes a record to DynamoDB (primary store), and publishes an event to SNS (or Kafka on MSK) for downstream processing.
- Delivery – if the recipient is online, a connection service pushes the message over that user’s open WebSocket; if not, a separate Lambda subscribed to the SNS topic sends a notification through Amazon Simple Notification Service (SNS) Mobile Push, which talks to FCM/APNs.
- Read path – when a client opens a chat, it calls GET /messages?chatId=…. The request hits the same API Gateway, then the service reads from DynamoDB. Frequently accessed recent messages are cached in ElastiCache (Redis) to keep latency under 50 ms.
- Media handling – images, videos, and voice notes are uploaded directly to S3 via a pre-signed URL. The message store only keeps the S3 object key.
- CDN – CloudFront distributes media objects globally, reducing latency for large files.
Data model
- Users table (PK =
userId). Stores profile info, device tokens, and lastSeen. - Chats table (PK =
chatId, SK =memberId). Allows quick lookup of participants. - Messages table (PK =
chatId, SK =timestamp#messageId). Stores text, media key, senderId, and status flags. - MessageStatus table (PK =
messageId, SK =userId). Tracks delivery/read receipts.
The primary key choice (chatId + timestamp) enables range queries for recent messages and guarantees ordering without extra sorting. An alternative would be a composite key on messageId alone, but that would require a separate index to fetch the conversation timeline, adding latency and cost.
What a complete junior answer covers
- Lists functional requirements (one-to-one, group chat, media, read receipts) and non-functional ones (latency, scalability).
- Draws a simple diagram: client → API Gateway → stateless service → DynamoDB + S3.
- Mentions basic sharding by chatId and uses DynamoDB for durability.
- Talks about push via SNS/Firebase.
- Acknowledges offline sync but does not detail it.
- Ends with a brief note on monitoring (CloudWatch) and security (TLS, IAM).
What a senior answer adds
- Sharding strategy – keeps
chatIdas the partition key so load spreads across DynamoDB partitions, and uses global tables to replicate data across regions (e.g.,us-east-1,eu-west-1). - Caching layer – adds ElastiCache for recent messages and a write-through cache pattern.
- Message queue – introduces Kafka on MSK for reliable ordering and replayability of events (e.g., for analytics).
- Consistency handling – explains why eventual consistency is acceptable for read receipts but strong consistency is needed for message ordering within a single chat.
- Media pipeline – details S3 lifecycle policies, CloudFront edge caching, and background transcoding via Lambda.
- Operational metrics – defines key SLOs (99th-percentile latency < 200 ms) and shows how to instrument with X-Ray and CloudWatch Alarms.
What a staff answer adds
- Failure modes – enumerates scenarios (DynamoDB throttling, network partition, SNS delivery failure) and mitigates them with exponential back-off, dead-letter queues, and multi-AZ replication.
- Cost analysis – rough estimate: DynamoDB write capacity of a few thousand WCUs (about 2,300 one-kilobyte writes per second) with a read load of the same order before caching, ~6 TB of message history in DynamoDB plus media in S3, and data transfer via CloudFront. Shows how caching reduces read cost by ~70 %.
- Operational readiness – talks about blue-green deployments using CodeDeploy, canary releases, and chaos testing with AWS Fault Injection Simulator.
- Trade-off defense – defends the choice of DynamoDB over Aurora by citing predictable latency and automatic scaling, while acknowledging Aurora’s richer query capabilities for analytics.
- Security depth – discusses end-to-end encryption (client-side encryption of message payloads) and key management with AWS KMS.
- Scalability beyond the baseline – sketches how to handle a spike to 1 billion messages/day (≈ 12 k msg/s) by adding more partitions, increasing provisioned throughput, and leveraging SQS as a buffer.
Mistakes that sink this question
| Mistake | Why it hurts |
|---|---|
| Ignoring read-after-write latency | Shows no awareness of user experience; chat feels laggy. |
| Over-designing with a relational DB without justification | Adds complexity and cost without clear benefit. |
| Forgetting offline sync or message ordering | Breaks core WhatsApp behavior; interviewers see a gap in fundamentals. |
| No discussion of scaling numbers | Leaves the design ungrounded; interviewers cannot gauge feasibility. |
| Skipping security (TLS, auth) | Critical for a real-world chat app; omission signals lack of production mindset. |
How to practice this
- Study the worked design in the System Design AI library. See how each component is annotated with talking points and pitfalls.
- Draw your own canvas on the practice board. Replicate the request path, then try variations (e.g., replace DynamoDB with Aurora) and note the trade-offs.
- Run through the rubric: ensure you cover functional and non-functional requirements, level-specific depth, and the common mistakes list.
Questions people ask
What is the most important metric for a chat system?
Latency of the send-receive cycle is the primary user-visible metric; aim for sub-200 ms end-to-end for a smooth experience.
Why choose DynamoDB over a relational database?
DynamoDB offers predictable single-digit millisecond latency, automatic scaling, and built-in multi-AZ replication, which are essential for high-throughput chat workloads.
How do you handle message ordering across shards?
Within a single chat, ordering is guaranteed by using a monotonically increasing timestamp (or ULID) as the sort key. Across shards, Kafka/MSK can preserve order for streams that need global sequencing, such as audit logs.
What is a cheap way to test push notification reliability?
Use SNS dead-letter queues and CloudWatch alarms to monitor delivery failures; simulate failures with the Fault Injection Simulator to verify retry logic.