Requirements
Every design starts with a question: what exactly are we building, and how good does it have to be? Requirements come in two kinds, and you need both before you can make any sensible decision.
| Kind | Answers | Examples for a photo-sharing app |
|---|---|---|
| Functional | What does the system do? | Upload a photo, follow a user, see a feed of followed users' photos, like a photo |
| Non-functional | How well does it do it? | Feed loads in under 200 ms for 99% of requests, 99.95% availability, photos never lost, 50 million daily users |
Functional requirements become your API and data model. Non-functional requirements decide the architecture: whether you need caches, replicas, queues or a CDN.
Functional requirements
Write them as short user actions, and agree on what is out of scope. Scope is the most powerful simplification you have.
In scope
- POST a photo with a caption
- follow / unfollow a user
- GET home feed (newest first, paginated)
Out of scope (for now)
- comments, stories, direct messages
- search, recommendationsNon-functional requirements
These are the "-ilities". Make each one measurable, otherwise it can't guide a decision or be tested.
| Quality | Vague | Measurable |
|---|---|---|
| Latency | "Fast" | p99 feed read < 200 ms |
| Availability | "Always up" | 99.95% monthly (about 22 minutes of downtime) |
| Durability | "Don't lose data" | 99.999999999% of stored objects survive a year |
| Scalability | "Handles lots of users" | 50 M daily active users, 10x headroom |
| Consistency | "Correct" | A user always sees their own new post immediately; others may see it up to 5 s later |
Percentiles matter more than averages. The p99 latency is the value 99% of requests are faster than; it is what your unluckiest regular users feel. A small model shows why the average hides problems:
latencies_ms = [42, 38, 45, 40, 39, 41, 44, 37, 43, 40,
39, 42, 41, 38, 950, 40, 43, 39, 44, 41]
def percentile(values, p):
ordered = sorted(values)
index = max(0, round(p / 100 * len(ordered)) - 1) # nearest-rank method
return ordered[index]
average = sum(latencies_ms) / len(latencies_ms)
print(f"average: {average:.1f} ms")
print(f"p50: {percentile(latencies_ms, 50)} ms")
print(f"p95: {percentile(latencies_ms, 95)} ms")
print(f"p99: {percentile(latencies_ms, 99)} ms")average: 86.3 ms
p50: 41 ms
p95: 45 ms
p99: 950 ms
One slow request in twenty more than doubles the average, yet the median barely notices it. Only the high percentiles reveal the outlier, which is why SLOs are usually written as percentiles.
Turning requirements into a checklist
A requirement list is easier to reason about when it is data. This small helper stores each requirement with a target and checks measured values against it, which is exactly what an automated SLO dashboard does:
requirements = [
# name, measured value, target, "max" means lower is better
("p99 feed latency (ms)", 180, 200, "max"),
("p99 upload latency (ms)", 950, 800, "max"),
("monthly availability (%)", 99.97, 99.95, "min"),
("daily active users (M)", 50, 50, "min"),
]
failed = 0
for name, measured, target, kind in requirements:
ok = measured <= target if kind == "max" else measured >= target
failed += not ok
mark = "PASS" if ok else "FAIL"
print(f"{mark} {name:<26} measured {measured:>6} target {target:>6}")
print(f"{failed} requirement(s) not met")PASS p99 feed latency (ms) measured 180 target 200
FAIL p99 upload latency (ms) measured 950 target 800
PASS monthly availability (%) measured 99.97 target 99.95
PASS daily active users (M) measured 50 target 50
1 requirement(s) not met
Read-heavy or write-heavy?
One of the most useful facts to discover early is the read/write ratio. A news feed is read far more than it is written; a logging pipeline is the opposite. The ratio tells you where to spend effort: caches and replicas help reads, while queues, batching and partitioning help writes.
apps = {
"photo feed": {"reads": 5_000_000_000, "writes": 50_000_000},
"metrics ingest": {"reads": 2_000_000, "writes": 800_000_000},
"chat": {"reads": 600_000_000, "writes": 300_000_000},
}
for name, ops in apps.items():
ratio = ops["reads"] / ops["writes"]
if ratio >= 10:
focus = "read-heavy: caching, read replicas, CDN"
elif ratio <= 0.1:
focus = "write-heavy: queues, batching, partitioned storage"
else:
focus = "balanced: plan for both paths"
print(f"{name:<15} reads/writes = {ratio:8.3f} -> {focus}")photo feed reads/writes = 100.000 -> read-heavy: caching, read replicas, CDN
metrics ingest reads/writes = 0.003 -> write-heavy: queues, batching, partitioned storage
chat reads/writes = 2.000 -> balanced: plan for both paths
Questions to ask
When the requirements are fuzzy (they always are), ask:
- Who are the users and how many? Daily active users, peak vs average.
- What are the core actions? Which one is the hot path?
- How much data per action, and how long is it kept?
- What latency is acceptable for each action? Are some actions allowed to be asynchronous?
- What happens on failure? Is it worse to show stale data or an error?
- Consistency: must every reader see the latest write, or is "eventually" fine?
Note: Requirements change. Write down the assumptions you made ("we assume 10:1 reads to writes") so you know which parts of the design to revisit when they turn out to be wrong.
Test yourself
Which of these is a non-functional requirement?
- Users can follow other users
- Users can upload a photo
- p99 feed latency is under 200 ms
- Users can delete a comment
Why are latency targets usually written as percentiles such as p99?
- Percentiles are easier to compute than averages
- Averages hide slow outliers that real users experience
- Percentiles are always lower
- Monitoring tools can't compute averages
A system has 100 reads for every write. Which techniques help most?
- Write batching and queues
- Caching and read replicas
- Two-phase commit
- Removing indexes