Sub topic 1
Clarifying requirements and scope
Prerequisites
This chapter assumes you know basic client-server and HTTP concepts. You should also be familiar with databases and key-value stores, and understand what a persistent connection over TCP is. Later chapters use short JavaScript and Python snippets, so you should be able to read both.
Why start with requirements
"Design a chat system" can mean a small team messenger or a global app with billions of users. The two need very different designs. Before you draw any boxes, ask questions that fix the scope. Every later choice depends on the answers: the connection protocol, the storage model, and how many servers you need.
A good interview or design review starts with a short list of questions, then writes the answers down as requirements.
Functional requirements
Functional requirements describe what the system does. For this tutorial we assume the following:
- One-to-one chat between two users.
- Group chat with a small to moderate member limit, for example 100 members.
- Online presence, so users can see who is available.
- Push notifications for users who are offline.
- Multiple devices per user, with the same history on each.
- Message history that can be loaded later.
- Text messages first. Media is a smaller topic covered later.
Features we leave out, such as voice calls, message editing, and end-to-end encryption, are stated explicitly as out of scope. Saying what you will not build is part of the scope.
Non-functional requirements
Non-functional requirements describe how well the system works. They often drive the design more than the feature list does.
| Requirement | Target used in this tutorial | Design impact |
|---|---|---|
| Latency | Delivery to an online user in well under a second | Persistent connections instead of repeated requests |
| Availability | Chat keeps working if single servers fail | Replication and no single point of failure |
| Durability | A message that was acknowledged is never lost | Write to storage before acknowledging |
| Ordering | Messages in one chat appear in the same order for everyone | Per-chat sequence numbers |
| Delivery | At-least-once, with no visible duplicates | Acknowledgements, retries, idempotent writes |
| Scale | Millions of concurrent connections | Horizontal scaling of connection servers |
Ordering is only promised within one chat. Global ordering across all chats is expensive and nobody needs it.
From questions to decisions
The table shows how each answer narrows the design.
Common mistakes
- Starting with technology ("use Kafka") before the requirements are known.
- Leaving the group size unbounded. Fan-out cost grows with group size, so you need a limit.
- Promising global ordering or exactly-once delivery without checking the cost.
- Skipping the out-of-scope list, which lets the scope grow during the design.
Summary of scope
We will design a chat system for one-to-one and moderate group messaging, with presence, push notifications, multi-device sync, and per-chat ordering. It provides durable, at-least-once delivery. The next chapter turns these requirements into rough numbers.
Exercise
A teammate proposes guaranteeing a single global order for all messages across all chats. Why is this usually the wrong requirement, and what should you require instead?
Show answer
A global order forces every message through one ordering point, which limits throughput and availability. Users only compare messages inside the same chat, so ordering within each chat, using per-chat sequence numbers, is enough.
Exercise
Name two non-functional requirements from this chapter and one design decision each one drives.
Show answer
Durability drives writing a message to storage before sending the acknowledgement. Latency drives using persistent connections instead of repeated polling requests. Other valid pairs come from the table.