Sub topic 15
Trade-offs between competing requirements
This chapter assumes you can write measurable non-functional requirements (SLIs, SLOs and percentiles) and read short Python snippets. You should also know the basics of databases and caching.
Why requirements collide
Non-functional requirements rarely fit together for free. Improving one quality often costs another. If every requirement is marked "highest priority", the design has no direction. A trade-off is a deliberate choice to give up some of one quality to gain more of another.
Common collisions:
| Want more of | Often costs | Why |
|---|---|---|
| Availability | Consistency, cost | Extra replicas can serve stale data and add servers to pay for |
| Durability | Latency | Waiting for several disks or nodes to confirm a write takes time |
| Low latency | Consistency, cost | Caches and replicas near users may hold old data |
| Security | Latency, operability | Encryption, checks and audit logging add work to each request |
| Fast delivery | Maintainability | Shortcuts raise future change cost |
A worked collision
Take the URL shortener from the sample requirements. NFR-1 asks for 99% of redirects under 100 ms. NFR-3 says an acknowledged short URL is never lost.
To meet NFR-3, the service could wait until a write is stored on two nodes before replying. That adds a network round trip to each creation. To meet NFR-1, redirects could be served from a cache. A cache can return an answer after the URL was deleted (FR-3).
Neither conflict is a mistake in the requirements. Each one needs a decision.
Resolving a trade-off
- Name the two requirements and the mechanism that makes them conflict.
- Ask which failure hurts stakeholders more. A lost URL breaks links people have already shared. A redirect that is 50 ms slower is barely noticed.
- Look for a design that limits the cost. Wait for replication only on creation, which is rare. Serve redirects from a cache, which is common.
- Quantify the price. State the extra write latency and the longest time a deleted URL may still redirect.
- Record the decision and its reason, so later readers do not undo it.
Making the cost visible
Trade-offs are easier to argue about with numbers. This snippet compares the availability of a service that depends on two components in series. Both must work for a request to succeed.
def serial_availability(*components):
"""Availability of a chain where every component must be up."""
result = 1.0
for a in components:
result *= a
return result
app = 0.999
database = 0.999
print(round(serial_availability(app, database), 6)) # 0.998001Two components at 99.9% give about 99.8%, so adding a dependency lowers availability. A requirement for 99.9% overall forces either a more reliable database or redundancy. Both cost money and add complexity.
Common errors
- Treating every requirement as equally important.
- Stating a target such as "strong consistency" with no scope. Often only some operations need it.
- Ignoring cost as a requirement of its own.
- Leaving the decision in a conversation instead of a document.
Exercise
A team requires "99.99% availability" and "every read returns the latest write across three regions". Name the quality in conflict, explain the mechanism, and suggest one way to narrow the conflict.
Show answer
Availability conflicts with consistency. To return the latest write, a read may have to contact other regions. If a region is unreachable, the system must either refuse the read, which lowers availability, or answer with possibly stale data, which breaks consistency. To narrow it, require latest-write reads only for operations that need them, such as account balance changes, and allow slightly stale reads elsewhere.
Exercise
Two components, each with 99.95% availability, are in series. What is the combined availability, rounded to four decimal places?
Show answer
0.9995 × 0.9995 = 0.99900025, which rounds to 0.9990, or 99.90%.