Skip to content
Theory · Requirements and estimates · lesson 3 of 8

Non-functional requirements

Back to the restaurant. The menu says what is cooked here. But a guest cares as much about something else. Will the soup arrive in ten minutes or in an hour, is the restaurant open on Sunday, will the order be mixed up? That is no longer about what the restaurant does, but about how well.

A non-functional requirement is a property of the system that can be measured: response speed, the share of time without failures, data freshness, data safety. The main rule is to turn words into numbers. "The feed must be fast" does not change the design. "99% of feed opens under 200 ms" does: a target like that calls for a cache.

Latency

Latency is set as a percentile. The 99th percentile is the time within which 99 requests out of 100 finish.

The average is misleading here. Say 95 responses out of 100 arrive in 50 ms and 5 in 2 seconds. The average comes out at about 150 ms and looks fine, although every twentieth user waits two seconds.

For the photo feed the requirement reads: 99% of feed opens under 200 ms. In an interview, name the percentile and the number together: "p99 under 200 ms", where p99 is short for the 99th percentile.

Availability

Availability is the share of time the system answers. It is counted in nines:

AvailabilityDowntime a year
99%3.65 days
99.9%8.8 hours
99.99%53 minutes
99.999%5 minutes

Each extra nine cuts the allowed downtime tenfold and makes the system noticeably more expensive. 53 minutes a year is less than it takes to replace a broken disk and restart the database. So one copy of the database cannot give 99.99%: you need a second one, ready to take over from the first.

Try to fix a diagram that ignores this.

Sketch

The feed must be served 99.99% of the time — about 53 minutes of downtime a year. Replacing a broken disk and restarting the database takes about an hour, and one such failure eats the whole year's allowance. Fix the diagram.

A replica is either synchronous or asynchronous. A synchronous one loses no confirmed writes, but every write waits for its reply. An asynchronous one is faster, but when the primary fails it may lose the last few seconds of writes. The databases course explains both modes in detail, in the lesson Synchronous and asynchronous replicas. In an interview it is enough to name the choice and its cost.

Consistency

Consistency answers whether a user may see stale data. There are two options.

Strong consistency

Every read sees the latest write. An account balance must work this way: after a transfer the old amount must never show. The cost is that a read waits until the copies agree, and if the link between them breaks, the system may not answer at all.

Eventual consistency

The copies catch up with each other within seconds. A feed can work this way: if a new post reaches a follower three seconds later, nobody is hurt. In return a read goes to the nearest copy and answers fast.

Ask the interviewer where the system may show stale data, and write down the bound: "a new post is visible to followers within 5 seconds".

Durability

Durability is the guarantee that confirmed data does not disappear. For the photo feed the requirement is: a published photo must never be lost. Two things follow:

  • photos are kept in at least three copies;
  • the author gets "done" only after the photo is written.

The view count of a post, by contrast, may lose its last few seconds before a failure: its requirements are softer, and it can be counted more cheaply.

Common mistake

Writing non-functional requirements down as words: "fast", "reliable", "always available". Twenty minutes later the interviewer asks why the diagram has a second database copy, and there is nothing to justify it with. With a number the answer is ready: "99.99% is 53 minutes a year, and replacing a disk takes an hour".

Key points

  • Non-functional requirements say how well the system works and are written down as numbers.
  • Latency is set as a percentile: 99% of responses under 200 ms.
  • 99.99% is 53 minutes of downtime a year, less than restoring one database, so a second copy is needed.
  • For every part of the system, ask whether it may show stale data and whether it may lose data.