Non-functional Requirements
Functional requirements state what the system does, while non-functional requirements state how well it must do it. For a URL shortener, "create a short link" and "redirect to the long URL" are functional requirements. "Redirects must be fast", "the service must stay up", and "the system must hold billions of links" are non-functional requirements.
Two systems with the same features can require very different designs. A URL shortener for one team runs on one server with one database. Serving the same features to hundreds of millions of users requires a cache, replicas, and shards. Because the functional requirements are identical, the differing non-functional requirements decide most of the architecture.
Stating a Requirement as a Number
Saying "the system must be fast" does not guide a design because every system wants to be fast. A useful requirement specifies a number, a measure, and a scope:
- Weak: "Redirects must be fast."
- Strong: "The p99 latency of a redirect is under 100 ms at the expected peak traffic."
The strong version identifies the operation, the measure (the 99th percentile), and the load. It also shows that the design must protect the redirect path rather than the link-creation path. In an interview, state requirements in this form and confirm them with the interviewer. The numbers come from the scale of the problem, which the estimation lessons show how to calculate.
Most systems are judged on five requirements: availability, scalability, latency, consistency, and durability. Each one drives a different part of the design.
Availability
Availability is the share of time that the system answers requests, stated in nines. A target of 99.9% allows about 8.8 hours of downtime per year, and 99.99% allows about 53 minutes. A target of four nines or more requires automatic recovery because one manual fix can use the whole yearly budget. The design reaches this target with copies of each part, health checks that find a failed copy, and failover that moves traffic to a healthy one. The Availability lesson covers the math and the mechanisms.
Move the slider below to change the target, and watch the allowed downtime per year, month, and day. Then change how long one manual fix takes.
Each extra nine divides the downtime budget by ten. At four nines, one 30-minute fix uses more than half of the yearly budget.
Scalability
Scalability is the ability to handle more load by adding resources without redesigning the system. A design scales when each part can grow independently. App servers that keep no session data in memory can grow by adding servers behind a load balancer. The database usually becomes the next limit. A cache and read replicas add read capacity, a queue absorbs bursts of writes, and shards add write capacity. The How to Scale a System lesson covers these techniques in order.
In an interview, state scalability requirements as load: daily active users, peak requests per second, and data stored after some years.
Latency
Latency is the time that one request takes. Engineers state latency as a percentile, such as p99, because an average hides slow requests. Latency drives the read path in particular. A cache serves frequent reads from memory, a CDN serves static files from servers near the user, and spare capacity keeps requests from waiting in a queue. The Latency and Throughput lesson shows how load and latency interact.
The diagram below places two requests on the same timeline, starting at the same moment. The median request finds its data in the cache. The slow request waits in a queue, misses the cache, and pauses for garbage collection, so its response arrives much later.
Averaging these two requests describes neither one. The p99 value captures the slow request, which is the one that users notice.
Consistency
Consistency describes whether a read returns the latest write. With strong consistency, a read after a write returns that write. With eventual consistency, a read can return older data for a short time, and all copies agree after the changes reach them.
The choice depends on the cost of a stale read. A bank balance must not allow the same $100 to be spent twice. A withdrawal therefore checks the balance and subtracts the amount in one transaction on the primary, confirming the write only after storing it. Because a like count that is a few seconds old harms no one, it can come from a cache or a replica. Many systems choose consistency per operation. Amazon's Dynamo, for example, was designed to accept "add to cart" even during failures, accepting that a deleted item can sometimes reappear (Dynamo paper, 2007).
Durability
Durability is the promise that once the system confirms a write, the data is not lost. Availability asks whether the system answers now, whereas durability asks whether the data still exists. A system can be down for an hour and lose nothing, or stay up and lose a write. Systems achieve durability by writing to more than one disk or machine before confirming the write, and by keeping backups.
Here, the system confirms the write only after two machines store it. When the disk on machine 1 fails, machine 2 still holds the order. If the system confirmed the write after one copy, a failure before copying finished would lose a confirmed write.
Requirements Conflict
The five requirements pull against each other. Strong consistency either sends reads to the primary or makes a write wait for the replicas. Reading from the primary puts all read load on one machine. Waiting for replicas adds latency, and if a replica is unreachable, the write must wait or fail, which lowers availability. A cache lowers latency but can return stale data. Extra copies raise availability and durability, but they cost money and add work on every write.
A design therefore cannot maximize every requirement; it prioritizes the requirements that matter most for each operation. A payment prioritizes consistency and durability. A news feed prioritizes availability and latency, accepting posts that appear a few seconds late. Stating this trade-off and the reason behind it is a large part of a strong interview answer.
Choose an operation below and change the three settings. Press Step to follow one write and then one read, and see if the read is stale. Then take the replica down. A red outline marks a setting that is wrong for the operation.
No single setting works well for both operations. The payment settings make every post wait for the replica and stop all posts when the replica is down. The feed settings let a payment read an old balance and lose a confirmed write.
Key idea. State each requirement with a number, a measure, and a scope, such as a p99 redirect latency under 100 ms at peak traffic. Because the five requirements conflict, choose per operation: payments prioritize consistency and durability, while feeds prioritize availability and latency.