Sub topic 16
How requirements drive architecture decisions
This chapter assumes you can write measurable non-functional requirements (NFRs) and estimate load. It shows how those numbers lead to concrete design choices. Functional requirements (FRs) tell you which components must exist. NFRs tell you how those components must be built.
From numbers to decisions
An architecture decision is a choice between designs that you can justify with a requirement. If you can't point to a requirement behind a choice, the choice is a guess.
Use this loop for each decision:
- Pick the requirement that is hardest to meet.
- Compare your estimate with the target.
- Add the cheapest mechanism that closes the gap.
- Record which requirement the mechanism serves.
A worked mapping
Take the URL shortener from the earlier example. Its estimated peak load is about 6,900 requests per second, with a redirect target of 99% under 100 ms.
| Requirement | Pressure on design | Decision |
|---|---|---|
| FR-2: redirect | Reads far outnumber writes | Separate read path from write path |
| NFR-1: p99 under 100 ms | A database lookup on every redirect is too slow at peak | Put a cache in front of the store |
| NFR-2: 99.9% availability | One server is a single point of failure | Run several stateless servers behind a load balancer |
| NFR-3: no lost URLs | An acknowledged write must survive a crash | Write to durable storage before replying, with replication |
Keeping the link visible
Record each decision next to the requirement it serves. A small structure is enough.
decisions = [
{"requirement": "NFR-1", "decision": "Add cache for redirect lookups",
"reason": "p99 target of 100 ms cannot rely on a database read per request"},
{"requirement": "NFR-2", "decision": "Run 3 stateless servers behind a load balancer",
"reason": "A single server would be a single point of failure"},
{"requirement": "NFR-3", "decision": "Replicate writes before acknowledging",
"reason": "Acknowledged URLs must never be lost"},
]
requirements = {"FR-1", "FR-2", "FR-3", "NFR-1", "NFR-2", "NFR-3"}
covered = {d["requirement"] for d in decisions}
print(sorted(requirements - covered)) # ['FR-1', 'FR-2', 'FR-3']The printed list shows requirements with no recorded decision yet. Here that is the three functional requirements, which this table has not addressed. An empty list means every requirement has some decision behind it.
Common errors
- Designing without a target. "Add a cache" with no latency number gives you no way to tell whether it was needed or whether it worked.
- Over-building. Designing for 100 times the estimated peak adds cost and complexity that no requirement asks for.
- Ignoring conflicts. A cache helps latency but can serve stale data. If a requirement demands fresh reads, the cache decision must be revisited. The trade-offs chapter covers this.
- Letting FRs vanish. Teams often tune NFRs and forget that every FR needs an API and an owner component.
Exercise
A requirement says 99.99% availability over 30 days, and your design has one database server. Which requirement-driven decision follows, and what number from the requirement justifies it?
Show answer
Add redundancy, such as a replica with automatic failover, because a single server is a single point of failure. The 99.99% target allows only about 4.3 minutes of downtime in 30 days, which a single server that needs manual recovery cannot reliably meet.