Sub topic 1
Why requirements come before design
Prerequisites
This chapter assumes you know the following:
- How a client-server application works, and what a web API request and response look like.
- What a database and a cache are, and why a service uses both.
- How to read short Python snippets. No other programming skill is needed.
You do not need prior experience with system design. This chapter sets up vocabulary and habits that the later chapters build on.
What a requirement is
A requirement is a statement about what a system must do, or about how well it must do it. It is written before the design exists, and it can be checked after the system is built. A statement that nobody can check is a wish, not a requirement.
Requirements fall into two groups:
- Functional requirements describe behavior: what the system does. "A user can submit a long URL and receive a short URL" is functional.
- Non-functional requirements describe quality: how well the system does it. "99% of redirects complete in under 100 ms" is non-functional. These are also called quality attributes.
The next two chapters cover each group in detail. Here the goal is to see why both must exist before you choose any component.
Why design cannot start without them
A design is a set of choices: which database, whether to add a cache, how many servers, whether to replicate across regions. Every choice is a trade-off, and a trade-off only makes sense relative to a goal. Without requirements, you have nothing to measure a choice against.
Consider a question that sounds simple: "Should we use a relational database or a key-value store?" It has no answer on its own. It depends on the following:
- Whether you need multi-row transactions (a functional need).
- How many reads per second you must serve (a performance target).
- Whether losing an acknowledged write is acceptable (a durability target).
The same question gets different answers for a banking ledger and for a click counter. The requirements decide, not the technology.
What goes wrong without requirements
Teams that skip requirements fail in a few predictable ways.
- Over-building. Without a stated load, a team designs for "internet scale" and pays for sharding, multi-region replication and operational complexity that a few thousand users will never need.
- Under-building. Without a stated latency or availability target, the first design is a single server with a single database. It works until it does not, and the fix is a redesign.
- Unfalsifiable success. If nobody wrote "99.9% of requests succeed", then "the service is reliable" is an opinion. Engineers, product managers and customers will each hold a different one.
- Late discovery. A missing requirement found after launch costs far more than one found in a planning meeting. Adding durability guarantees or data-residency rules to a finished system often means changing the storage layer.
The common cause is the same each time. The design answered a question nobody had asked precisely.
Where requirements sit in the design process
Requirements are the first step of a loop, not a one-time document. Design work uncovers new questions, and those questions feed back into the requirements.
The rest of this tutorial follows this loop. You will learn to gather requirements from stakeholders, separate functional from non-functional ones, make quality targets measurable, estimate load, weigh trade-offs, and check the result.
A small example of the difference
Here is a requirements document for a URL shortener, kept deliberately small. It separates three kinds of content: what the system does, how well it does it, and what it will not do.
service: url-shortener
functional:
- id: FR-1
text: A user can submit a long URL and receive a short URL.
- id: FR-2
text: Requesting a short URL redirects to the original long URL.
- id: FR-3
text: A user can delete a short URL they created.
non_functional:
- id: NFR-1
quality: latency
text: 99% of redirects complete in under 100 ms, measured at the service edge over 30 days.
- id: NFR-2
quality: availability
text: Redirects succeed for 99.9% of requests over a 30-day window.
- id: NFR-3
quality: durability
text: A created short URL is never lost once creation has been acknowledged.
out_of_scope:
- Click analytics
- Custom domainsNotice three habits in this document:
- Each requirement has an identifier. Later chapters, tests and design notes can refer to "NFR-1" without ambiguity.
- Each non-functional requirement names a number, a window and a measurement point. "Fast" would not pass that test.
- The out-of-scope list is part of the requirements. It tells the team what not to design for.
Now see how much the non-functional lines already constrain the design. NFR-2 sets a downtime budget, which a few lines of Python can compute.
def downtime_budget_minutes(availability, days=30):
"""Minutes of allowed downtime for an availability target over a window."""
return (1 - availability) * days * 24 * 60
print(round(downtime_budget_minutes(0.999), 1)) # 43.2
print(round(downtime_budget_minutes(0.9999), 1)) # 4.3A 99.9% target allows about 43.2 minutes of downtime in 30 days. A 99.99% target allows about 4.3 minutes. That is a tenfold difference, and it changes the design. With 43 minutes you can tolerate a manual failover and a careful deployment. With 4 minutes you need automated failover and deployments that cause no downtime. One extra digit in a requirement changes what you build.
Requirements as a shared contract
Requirements also serve people, not only designs. Several groups depend on them:
| Group | What they use requirements for |
|---|---|
| Product owners | Confirm the system solves the stated problem |
| Engineers | Choose components and set capacity |
| Testers | Derive acceptance tests and load tests |
| Operations | Set alerts and on-call expectations |
| Customers | Understand what is promised |
When these groups read different documents, or none, they diverge. A single numbered list gives them a common reference.
Edge cases and cautions
Some situations make requirements harder than the tidy example suggests.
- Requirements change. Early requirements are estimates. Treat them as versioned, and record the date and reason for each change.
- Requirements conflict. "Always consistent" and "always available during a network partition" cannot both hold. The trade-offs chapter covers this. The point here is that conflicts should surface during requirements work, not during an outage.
- Some qualities are hard to number. Usability and maintainability resist simple metrics. Write the best testable proxy you can, such as "a new engineer can deploy a change within one day of joining", and accept that it is imperfect.
- Do not over-specify. A requirement should state the need, not the solution. "Use Redis" is a design decision. "Redirects complete in under 100 ms at the 99th percentile" is a requirement that several designs could meet.
- Numbers need a source. A target of 99.99% is meaningless if no stakeholder needs it. Each number should trace to a user need, a contract or a cost limit.
Summary of the habits to carry forward
- Write requirements before choosing components.
- Separate what the system does from how well it does it.
- Give every quality a number, a window and a measurement point.
- Record what is out of scope.
- Treat the document as living, and revisit it when design raises new questions.
Exercise
A team writes two requirements for a photo-sharing service: (a) "Users can upload a photo and add a caption" and (b) "The service should be fast and reliable." Classify each as functional or non-functional, and say which one is not yet a usable requirement and how you would fix it.
Show answer
(a) is functional: it describes behavior. (b) is non-functional, but it is not usable because "fast" and "reliable" cannot be checked. Rewrite it with numbers, windows and measurement points, for example: "99% of photo uploads complete in under 2 seconds, measured at the service edge over 30 days" and "Uploads succeed for 99.9% of requests over a 30-day window."
Exercise
A stakeholder asks for 99.99% availability instead of 99.9% over 30 days. Using the downtime formula, how many minutes of downtime does each target allow, and name one design change the stricter target is likely to force.
Show answer
99.9% allows (1 - 0.999) x 30 x 24 x 60 = 43.2 minutes. 99.99% allows about 4.3 minutes. With only about 4 minutes, a human cannot detect and fix a failure in time, so the design likely needs automated failover and deployments that do not interrupt service.