Sub topic 1
Clarifying requirements and scope
Every chat system design starts with questions, not boxes and arrows. "Design a chat system" can mean a two-person messenger, a team workspace like Slack, or a global app with billions of users. Each one leads to a different architecture. This chapter shows how to turn a vague request into a short, agreed list of requirements that the rest of the design can rely on.
Prerequisites
This chapter assumes you already know the following:
- Basic client-server and HTTP concepts, such as requests, responses, and status codes.
- How databases and key-value stores differ at a high level.
- What a persistent connection is, and the basics of TCP.
- How to read short JavaScript and Python snippets.
You do not need to know any chat-specific protocols yet. Later chapters cover them.
Why requirements come first
A design is only "good" relative to a set of goals. Consider two answers to the same prompt:
- A startup with 5,000 users can run one server and one relational database. Adding Kafka, sharding, and a multi-region deployment would waste money and slow the team down.
- A consumer app with 500 million users cannot do that. A single database would fail within hours.
The prompt is the same in both cases, but the correct designs are very different. Requirements give you the numbers and constraints to decide between them. They also stop you from building features nobody asked for.
A useful habit is to split requirements into three groups:
- Functional requirements: what the system does.
- Non-functional requirements: how well it does it (speed, reliability, scale).
- Out of scope: what you deliberately do not build.
Functional requirements
Functional requirements describe user-visible behavior. For a chat system, start by asking which of these features are needed.
| Question to ask | Why it matters |
|---|---|
| One-to-one chat only, or group chat too? | Group chat adds fan-out, where one message must be delivered to many recipients. |
| What is the maximum group size? | 10 members and 100,000 members need different delivery strategies. |
| Mobile, web, or both? | Mobile clients lose connectivity often and need push notifications. |
| Text only, or images, video, and files? | Media needs separate upload, storage, and CDN paths. |
| Do users need to see who is online? | Presence adds heartbeat traffic and extra state. |
| Is message history kept, and for how long? | Retention drives storage size and the choice of database. |
| Can one user be logged in on several devices? | Multi-device sync needs per-device delivery tracking. |
| Is end-to-end encryption required? | It limits what the server can do with message content, such as search. |
Suppose the interviewer or product owner answers like this. This is the running example for the rest of the tutorial:
- One-to-one chat and group chat, with groups of up to 500 members.
- Text messages in the first version, with media added later.
- Web and mobile clients, and one user may have several devices.
- Online presence indicator.
- Push notifications for users who are offline.
- Message history stored permanently and loadable on any device.
Notice that these answers are concrete. "Group chat" alone is vague. "Groups of up to 500 members" is something you can calculate with.
Non-functional requirements
Non-functional requirements describe quality. For chat, a handful matter most.
- Low latency. Messages between online users should arrive in well under a second. People notice delays in conversation quickly.
- Reliability. A message that the system accepted must not be lost. If the server confirms a send and then crashes, the message must still exist.
- Ordering. Messages in one conversation must appear in the same order for all participants.
- Availability. Users expect chat to work at any hour. Losing a single server should not take down the service.
- Scalability. The system should grow by adding machines, not by rewriting.
- Consistency of history. Every device of a user should eventually show the same conversation.
Some of these pull against each other. Strict global ordering is expensive, and low latency across regions is hard to combine with strong consistency. Writing the priorities down lets you make these trade-offs on purpose. In this chapter's example, the priorities are:
- Never lose an accepted message.
- Keep order consistent within each conversation.
- Keep latency low for online users.
- Allow brief delays in presence and in cross-device sync.
Priority 4 is a deliberate relaxation. Showing a user as "online" two seconds late harms no one, so presence can use cheap, approximate mechanisms. A lost message harms users, so message delivery gets stronger guarantees.
Setting the scope
Scope is a boundary. Anything inside it gets a real design. Anything outside it is named and set aside. Saying so explicitly prevents long arguments later.
For the running example, a reasonable scope is:
- In scope: one-to-one messaging, group messaging, delivery guarantees, ordering, presence, push notifications, multi-device sync, message history.
- Simplified: media is handled with a short chapter, and security with the main points only.
- Out of scope: voice and video calls, message search, bots and integrations, end-to-end encryption protocols, and moderation tooling.
Each excluded item is a good project on its own. For example, end-to-end encryption changes the whole system, because the server can no longer read messages. Including it here would hide the core ideas.
Turning requirements into design decisions
Requirements are only useful if they change what you build. The table below shows how the answers above steer later chapters.
| Requirement | Design consequence | Chapter topic |
|---|---|---|
| Sub-second delivery | Server can push messages to clients, so polling is a poor fit | Polling, long polling, and WebSocket |
| Never lose an accepted message | Persist before acknowledging, and retry until acknowledged | Acknowledgements, retries, and deduplication |
| Order within a conversation | Per-chat sequence numbers | Ordering messages and generating IDs |
| Groups up to 500 | Fan-out per message is affordable, but still needs a strategy | Group chat and fan-out strategies |
| Several devices per user | Track delivery and read position per device | Syncing multiple devices and loading history |
| Offline users | Push notification path outside the live connection | Notifying offline users |
A diagram of this flow can help when you present requirements to others.
Common mistakes
- Starting with technology. Saying "we'll use Kafka" before you know the message rate is a guess dressed up as a decision.
- Leaving numbers vague. "Many users" is not a requirement. "50 million daily active users" is.
- Skipping the failure cases. Ask what happens when a user is offline, when a server dies, or when a client resends a message.
- Treating all requirements as equal. Without priorities you cannot resolve conflicts.
- Silently expanding scope. Each added feature (search, calls, bots) multiplies the work. Add it only when you agree to it.
- Forgetting to confirm. State your assumptions out loud, such as "I'll assume groups are capped at 500", so others can correct you early.
A short requirements checklist
Use this list at the start of any chat design:
- Who are the users, and how many are active each day?
- Which conversation types exist (one-to-one, group, channel), and what are the size limits?
- Which clients are supported, and are multiple devices allowed?
- Which message types exist, and what is the maximum message size?
- What delivery guarantee is needed, and what happens to messages for offline users?
- How long is history kept?
- Which features are explicitly out of scope?
The answers feed straight into the next chapter, where you will convert them into numbers for traffic, connections, and storage.
Exercise
A product owner says, "We want a chat app like WhatsApp." List three clarifying questions you would ask, and for each one, name a design area it affects.
Show answer
Possible answers: (1) "What is the maximum group size?" This affects fan-out strategy and group chat design. (2) "Should one account work on several devices?" This affects multi-device sync and per-device delivery tracking. (3) "Are images and video included in the first version?" This affects media storage, upload paths, and CDN use. Other valid questions: how many daily active users (estimation and scaling), how long history is kept (storage choice), and whether end-to-end encryption is needed (security and server capabilities).
Exercise
Your requirements say "never lose an accepted message" and "show online status." Which of the two can tolerate a delay or occasional inaccuracy, and how should that shape the design effort spent on each?
Show answer
Online status can tolerate delay and slight inaccuracy, since a status that is a few seconds stale harms no one. It can use simple, approximate mechanisms such as heartbeats with a time-to-live. Message delivery cannot lose data, so it needs durable storage before acknowledgement, retries, and deduplication. More design effort belongs on message delivery.