Sub topic 3
Non-functional requirements: how well it does it
This chapter assumes you know what a functional requirement is, can read short Python snippets, and have basic familiarity with web APIs, databases, and caching.
What a non-functional requirement is
A functional requirement says what the system does. A non-functional requirement (NFR) says how well it does it. NFRs are also called quality attributes. They describe qualities such as speed, uptime, safety of data, and ease of operation.
Compare two statements about a URL shortener:
- Functional: requesting a short URL redirects to the original long URL.
- Non-functional: 99% of those redirects complete in under 100 ms.
Both describe the same feature. The first says the feature exists. The second says how good it must be.
Common categories
| Quality | Question it answers | Example target |
|---|---|---|
| Latency | How fast is one request? | 99% of redirects under 100 ms |
| Throughput | How much work per second? | 7,000 requests per second at peak |
| Availability | How often is it up? | 99.9% over 30 days |
| Durability | Is acknowledged data ever lost? | No loss after creation is acknowledged |
| Consistency | Do readers see the latest write? | A new link works immediately |
| Security | Who may do what? | Only the creator can delete a link |
| Operability | How easy is it to run and change? | A rollback takes under 10 minutes |
Later chapters cover each category in detail. Here the goal is to learn to write them.
Why vague NFRs fail
"The system should be fast" cannot be tested. Two engineers will read it differently, and nobody can say whether the design meets it. A usable NFR names four things:
- The quality, for example latency.
- A number, for example 100 ms.
- A statistic, for example the 99th percentile.
- A measurement point and window, for example at the service edge over 30 days.
The statistic matters because averages hide slow requests. In the sample below, the median looks healthy while the 99th percentile shows the outlier.
import math
def percentile(samples, p):
"""Nearest-rank percentile: the smallest value with at least p% of samples at or below it."""
ordered = sorted(samples)
rank = math.ceil(p / 100 * len(ordered))
return ordered[rank - 1]
latencies_ms = [12, 15, 14, 18, 20, 22, 25, 30, 40, 250]
print(percentile(latencies_ms, 50)) # 20
print(percentile(latencies_ms, 99)) # 250NFRs in a requirements document
Keep NFRs in their own numbered list, apart from functional requirements and out-of-scope items. Numbered IDs let you refer to a requirement in reviews, tests, and design notes.
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 domainsEach NFR here names a quality, a number, and a window. NFR-3 is an absolute rule rather than a percentage, which is a deliberate choice you should be able to defend.
Common errors
- Writing an adjective instead of a number, such as "fast" or "highly available".
- Quoting an average latency instead of a percentile.
- Leaving out the measurement window, so "99.9%" has no meaning.
- Treating every quality as maximal. Each target costs money and complexity, and some conflict with each other.
Exercise
Classify this requirement and rewrite it if needed: "Search should respond quickly." Which parts are missing?
Show answer
It is non-functional (it describes speed, not behavior). It lacks a number, a percentile, and a measurement point and window. A rewrite: "99% of search requests complete in under 300 ms, measured at the service edge over 30 days."