In the previous lesson we saw that good architecture brings benefits such as scalability, performance, or maintainability, and we translated them into euros. But to design, it is not enough to say that the system must be “fast” or “reliable”: we have to specify how much, under what conditions, and how it will be checked. In this lesson you will learn to define a system's quality attributes, to measure them, to write them as verifiable scenarios, and to prioritize them together with the business. They are the raw material of every architectural decision.
Functional Requirements and Non-Functional Requirements
A system's requirements fall into two large families:
- A functional requirement describes what the system does: a function or behavior it offers its users.
- A non-functional requirement describes how well it does it: a quality it must meet while performing its functions.
| Functional requirement | Related non-functional requirement |
|---|---|
| The customer can search for plants by name | The search responds in under one second |
| The customer can pay by card | Card data is never stored at Verdalia |
| The system sends an email when the order is confirmed | The email arrives in under five minutes |
| Staff can update the stock | The store keeps working while it is being updated |
Two differences are of special interest to whoever designs the architecture:
| Aspect | Functional requirements | Non-functional requirements |
|---|---|---|
| Where they are solved | Usually, in one specific part of the code | In the structure of the whole system |
| Who asks for them | The business asks for them explicitly | Almost nobody asks for them until they fail |
| How they are added later | Relatively easily, function by function | With great difficulty if the structure does not allow them |
| Influence on the architecture | Moderate | Decisive |
That last row is the key. Two online stores with the same functions may need completely different architectures if one receives a hundred visits a day and the other a hundred thousand. It is the non-functional requirements, not the functional ones, that determine the architecture.
The name “non-functional” is unfortunate, because it seems to suggest something secondary. That is why we prefer to talk about quality attributes.
What a Quality Attribute Is
A quality attribute is a measurable property of the system that indicates to what degree it satisfies a need of its stakeholders, beyond its functions.
Two words in the definition deserve attention:
- Measurable. If it cannot be measured, it cannot be checked, and if it cannot be checked, it is an opinion. “The website must be fast” is not a well-defined quality attribute; “95% of catalog pages are served in under 800 milliseconds” is.
- Stakeholders. Each person values different attributes. Andrés cares that the store does not go down; Íker, that the code is easy to change; Lucía, that the system is easy to operate.
In this course we will work with seven attributes:
| Attribute | Question it answers |
|---|---|
| Performance | How long does the system take to respond? |
| Scalability | Can it handle more load if it is given more resources? |
| Availability | What fraction of the time is it working? |
| Security | Does it withstand improper access and misuse? |
| Maintainability | How much does it cost to change it without breaking it? |
| Operability and observability | Is it easy to deploy, monitor, and understand what is happening to it? |
| Cost | How much does it cost to build and keep running? |
Performance: Latency, Percentiles, and Throughput
Performance is how fast the system does its work. It is measured with two complementary quantities:
| Quantity | Definition | Usual unit | Example at Verdalia |
|---|---|---|---|
| Latency | Time elapsed between a request and its response | Milliseconds | A product page takes 220 ms |
| Throughput | Amount of work completed per unit of time | Requests per second | The server handles 30 requests per second |
Why the Mean Misleads
The intuitive way to summarize latency is to calculate the mean, but it is a bad idea. Imagine that out of ten customers, nine receive the page in 200 ms and one in 5,000 ms. The mean is 680 ms, a value that describes the experience of none of the ten: nine are much better off and one is far, far worse off.
Percentiles
That is why percentiles are used. The p-th percentile is the value below which p percent of the measurements fall.
| Percentile | Read as | Meaning |
|---|---|---|
| p50 | “p-fifty” or median | Half of the requests take this long or less. It represents the typical experience |
| p95 | “p-ninety-five” | 95% take this long or less. One in 20 requests does worse |
| p99 | “p-ninety-nine” | 99% take this long or less. One in 100 does worse |
High percentiles matter more than they seem, for two reasons:
- One customer makes many requests. A visit to the store involves dozens of requests. If one in 20 is slow, almost every customer will suffer some long wait.
- The most valuable customers tend to be in the tail. A cart with many products or a history with many orders makes the system work harder. The slowest requests usually belong to those who buy the most.
Current Situation and Target at Verdalia
| Measure | Normal day | Campaign | Target |
|---|---|---|---|
| p95 of the catalog page | 1.2 s | More than 6 s | Under 800 ms |
| p99 of the catalog page | 3 s | No response | Under 2 s |
A performance target must always state the load it applies to. Meeting 800 ms with 40 users is easy; with 1,000, it is not. That brings us to the next attribute.
Scalability
Scalability is the system's ability to handle a greater load when resources are added to it, while maintaining its performance targets.
It should not be confused with performance:
| Attribute | Question | Example |
|---|---|---|
| Performance | How long does it take under the current load? | The catalog takes 1.2 s with 40 users |
| Scalability | What happens when the load grows? | Will it keep responding with 1,000 users if we add resources? |
A system can be fast and not scalable, or scalable but slow. Scalability is measured with indicators such as these:
| Indicator | Verdalia today | Target |
|---|---|---|
| Maximum load while meeting the performance targets | About 250 concurrent users | 1,000 concurrent users |
| Time needed to add capacity | Days, because another server has to be rented and migrated to | Under 15 minutes |
| Need to stop the service in order to expand | Yes | No |
The ways to achieve scalability are studied in Module 4.
Availability and the “Nines”
Availability is the proportion of time during which the system is in a condition to provide service. It is calculated like this:
It is expressed as a percentage, and since the usual values are very close to 100%, people often talk about “nines.” The following table shows how much downtime each level allows:
| Availability | Colloquial name | Allowed downtime per month (30 days) | Allowed downtime per year |
|---|---|---|---|
| 99% | Two nines | 7 h 12 min | 3 days 15 h 36 min |
| 99.5% | 3 h 36 min | 1 day 19 h 48 min | |
| 99.9% | Three nines | 43 min 12 s | 8 h 46 min |
| 99.95% | 21 min 36 s | 4 h 23 min | |
| 99.99% | Four nines | 4 min 19 s | 52 min 34 s |
| 99.999% | Five nines | 26 s | 5 min 15 s |
Several lessons can be drawn from this table:
- Each additional nine divides the allowed downtime by ten. And, as a general rule, it multiplies the cost and the complexity.
- 99% sounds very good and is very little. It allows more than three and a half days of downtime a year.
- From four nines onward there is no room for human intervention. With 4 minutes a month, nobody has time to receive an alert, log in, and fix anything: recovery has to be automatic.
Necessary Clarifications
An availability target is only useful if it clarifies three things:
| Question | Why it matters | Decision at Verdalia |
|---|---|---|
| Which period is measured | 99.9% per year allows an 8-hour outage in one go; 99.9% per month does not | Measured per calendar month |
| Whether planned downtime counts | For the customer, a closed store is a closed store, whether because of a failure or a deployment | Everything counts |
| What “working” means | The home page may load even though paying is impossible | The store is working if a customer can complete a purchase |
Current Situation and Target at Verdalia
In May of last year, the store was down for 180 minutes because of the incident on the day before Mother's Day, and for 40 more minutes because of the month's two deployments. In total, 220 minutes, which is equivalent to an availability of 99.51%.
The agreed target is 99.9% per month. There is a revealing detail: the two monthly deployments alone consume 40 of the 43 allowed minutes. With the current way of deploying, the target is practically unattainable even if there is no failure at all.
The techniques for achieving high availability are covered in Module 4.
Security, Maintainability, Operability, and Cost
The four remaining attributes are harder to reduce to a single figure, but they can and must be measured too.
Security
Security is the system's ability to protect information and functions from unauthorized access or use. It is usually broken down into three properties:
| Property | Meaning | Example at Verdalia |
|---|---|---|
| Confidentiality | Only those who should access the information do | A customer cannot see another customer's orders |
| Integrity | The information is not altered improperly | Nobody can modify a product's price from outside |
| Availability | The information is accessible when needed | An attack does not take the store out of service |
Since there is no such thing as a “security percentage,” indirect indicators are used:
| Indicator | Verdalia today | Target |
|---|---|---|
| Credentials written in the code repository | 2 | 0 |
| Time to apply a critical security update | Undefined | Under 72 hours |
| People with direct access to production data | The whole technical team | Only those who need it |
Security is developed in Module 5.
Maintainability
Maintainability is how easily the system can be modified to fix bugs, add functions, or adapt to changes, without introducing failures.
| Indicator | Verdalia today | Target |
|---|---|---|
| Time to deliver a typical change | 9 days | 3 days |
| Deployments that cause an incident | 1 in 3 | Fewer than 1 in 10 |
| Modules that must be modified for a change in one area | Several, unpredictably | One, barring justified exceptions |
Operability and Observability
Operability is how easily the system can be deployed, configured, and kept running. Observability is the ability to understand what is happening inside it from the information it emits. They go hand in hand: you cannot operate well what you cannot observe.
| Indicator | Verdalia today | Target |
|---|---|---|
| Time to detect an outage | 25 minutes, via a customer's report | Under 5 minutes, via an automatic alert |
| Downtime per deployment | 20 minutes | 0 minutes |
| Deployment frequency | 2 a month | At least 1 a week |
| People able to deploy | 1, Lucía | Any member of the technical team |
Observability is covered in depth at the end of Module 6.
Cost
Cost is one more quality attribute, and often the one that limits all the others. It is worth distinguishing between:
- Build cost. What it costs to develop or modify the system.
- Operating cost. What it costs to keep it running every month.
| Indicator | Verdalia today | Target |
|---|---|---|
| Monthly infrastructure cost | €120 | Up to €500 on an annual average |
| Infrastructure cost per order | €0.06 | Under €0.25 |
The cost per order is more informative than the total cost, because it relates spending to the business. Paying more is reasonable if more is sold.
Measuring With Python: Percentiles and Allowed Downtime
Let us calculate the most important measures of this lesson to understand them without any mystery.
Latency Percentiles
Lucía collected the response times of 20 requests to the catalog page:
import math
latencies_ms = [
180, 210, 190, 250, 230, 205, 310, 220, 195, 240,
260, 215, 225, 2900, 200, 235, 245, 1200, 185, 270,
]
def percentile(values, p):
"""Return the p-th percentile (between 0 and 100) of a list of values,
using the nearest-rank method."""
sorted_values = sorted(values)
position = math.ceil(p / 100 * len(sorted_values))
position = max(position, 1)
return sorted_values[position - 1]
mean = sum(latencies_ms) / len(latencies_ms)
print(f"Mean: {mean:.0f} ms")
print(f"p50: {percentile(latencies_ms, 50)} ms")
print(f"p95: {percentile(latencies_ms, 95)} ms")
print(f"p99: {percentile(latencies_ms, 99)} ms")Output:
Explanation:
import mathloads the module of mathematical functions, from which we useceil, which rounds up.sorted(values)returns a copy sorted from smallest to largest. A percentile only makes sense on sorted data.positioncalculates which place in the sorted list corresponds to the percentile. For the p95 of 20 values: 95% of 20 is 19, so the value in the 19th place is taken.max(position, 1)avoids a position of 0 if someone asks for the 0th percentile.- 1 is subtracted when accessing the list because Python numbers positions starting from zero.
Interpretation of the results:
- The mean of 408 ms represents nobody: 18 of the 20 requests took less than 320 ms.
- The p50 of 225 ms indicates that the typical experience is good.
- The p95 of 1,200 ms reveals the problem that the mean and the median hide: one in 20 requests is very slow.
- The p99 coincides with the maximum value because there are only 20 samples. For the p99 to be reliable, at least several hundred measurements are needed.
Checking a Target
def meets_target(values, p, limit_ms):
"""Report whether the p-th percentile of the values stays within the limit."""
return percentile(values, p) <= limit_ms
print("Meets p95 < 800 ms:", meets_target(latencies_ms, 95, 800))Output:
The function returns True or False. A well-defined quality attribute can always be turned into a check of this kind, with a yes-or-no answer.
Allowed Downtime
def allowed_downtime_minutes(target, days=30):
"""Minutes of downtime that an availability target (as a percentage)
allows over a period of 'days' days."""
total_minutes = days * 24 * 60
return total_minutes * (1 - target / 100)
def actual_availability(downtime_minutes, days=30):
"""Availability achieved, as a percentage, over a period."""
total_minutes = days * 24 * 60
return (total_minutes - downtime_minutes) / total_minutes * 100
for target in [99.0, 99.5, 99.9, 99.95, 99.99]:
monthly = allowed_downtime_minutes(target, days=30)
yearly = allowed_downtime_minutes(target, days=365)
print(f"{target}% -> {monthly:.1f} min per month, {yearly / 60:.1f} h per year")
may = actual_availability(downtime_minutes=220, days=31)
print(f"May availability: {may:.2f}%")Output:
99.0% -> 432.0 min per month, 87.6 h per year 99.5% -> 216.0 min per month, 43.8 h per year 99.9% -> 43.2 min per month, 8.8 h per year 99.95% -> 21.6 min per month, 4.4 h per year 99.99% -> 4.3 min per month, 0.9 h per year May availability: 99.51%
Explanation:
total_minutesconverts the period into minutes: days times 24 hours times 60 minutes. A 30-day month has 43,200 minutes.- In
allowed_downtime_minutes, the expression1 - target / 100is the fraction of time during which downtime is tolerated. For 99.9% it is 0.001, one thousandth of the time. actual_availabilitygoes the opposite way: from the minutes of downtime, it calculates the percentage achieved.- The loop reproduces the table of “nines,” and the last line confirms May's 99.51%.
Quality Attribute Scenarios
Having a figure is not enough. “99.9% availability” does not say against what kind of failure, and “p95 under 800 ms” does not say under what load. To remove the ambiguity, we write quality attribute scenarios: brief, verifiable descriptions of how the system must behave in a specific situation.
The Four Parts of a Scenario
flowchart LR
stimulus["Stimulus: what happens"] --> system["System in a given environment"]
system --> response["Response: what the system does"]
response --> measure["Measure: how it is checked"]
| Part | Question | Example |
|---|---|---|
| Stimulus | What happens? | A customer requests a catalog page |
| Environment | Under what conditions is the system? | During the campaign, with 1,000 concurrent users |
| Response | What must the system do? | It returns the complete page |
| Measure | How will we know it did it well? | In under 800 ms in 95% of cases |
Verdalia's Scenarios
Marta wrote six scenarios, which will serve as a reference throughout the course:
| Code | Attribute | Stimulus | Environment | Response | Measure |
|---|---|---|---|---|---|
| QS-1 | Performance | A customer requests a catalog page | Campaign, 1,000 concurrent users | The system returns the complete page | p95 under 800 ms and p99 under 2 s |
| QS-2 | Scalability | Traffic goes from 40 to 1,000 concurrent users in 30 minutes | An email campaign is sent | Capacity is added without stopping the store | Capacity expanded in under 15 minutes, meeting QS-1 |
| QS-3 | Availability | A server or an application process stops working | Spring campaign | The store keeps accepting orders | Interruption under 5 minutes; monthly availability of 99.9% or higher |
| QS-4 | Security | An unauthorized person obtains a copy of the code repository | Normal operation | They obtain no credentials and no access to data | 0 credentials in the repository |
| QS-5 | Maintainability | The business asks to add a new shipping method | Normal development | The change is implemented, tested, and published without affecting other areas | 3 days or less, modifying a single module |
| QS-6 | Operability | Íker publishes a new version | Tuesday at 12:00, with the store open | The version is deployed without interrupting purchases | 0 minutes of downtime; rollback to the previous version in under 10 minutes |
Notice that no scenario says how to achieve it. They mention neither additional servers nor technologies. A scenario describes the desired outcome; the solution is the architecture's job, and we will build it over the following modules.
Prioritizing the Attributes With the Business
Not everything can be maximized at once. The attributes compete with each other: more security usually means less convenience, more availability means more cost. That is why we have to prioritize, and that priority cannot be set by the technical team alone.
The Conversation Between Marta and Andrés
When Marta asked Andrés which attributes were the most important, the first answer was the usual one: “all of them.” To get out of that, Marta used a simple technique: distributing 100 points.
The rules are:
- There are 100 points to distribute among the seven attributes.
- They cannot be distributed in equal parts.
- Each score must be justified with a business goal.
Giving points to one attribute forces you to take them away from another, and that forces the conversation that would otherwise be avoided.
The Result
| Priority | Attribute | Weight | Agreed justification |
|---|---|---|---|
| 1 | Availability | 25 | An outage during the campaign costs almost €6,000 in one morning |
| 2 | Maintainability | 20 | The cost of each change has quadrupled and is holding back launches |
| 3 | Security | 15 | A data leak would put customers' trust at risk |
| 3 | Performance | 15 | Slowness reduces sales, though less than an outage does |
| 5 | Scalability | 10 | It matters for a few weeks a year, but they are the weeks with the highest sales |
| 5 | Cost | 10 | There is room to spend more, as long as it is justified |
| 7 | Operability | 5 | It is above all a means to achieve availability and maintainability |
Some observations on the result:
- A low weight does not mean the attribute is ignored. It means that, when it conflicts with another, it will give way.
- The priorities are Verdalia's and this moment's. Another company, or the same one two years from now, would have different ones.
- The minimum targets are always met. Priority decides where to invest the additional effort, not whether to comply with the law.
These weights are not decorative: in Lesson 01-05 we will use them to compare architecture alternatives in a reasoned way.
Common Mistakes and Tips
- Writing attributes without a measure. “The system must be scalable” cannot be checked. Always add a figure and a condition.
- Using the mean for latency. It hides precisely the cases that bother customers the most. Use percentiles.
- Setting targets without knowing the current situation. Before promising a p95 of 800 ms, you need to know what today's is. Measuring is the first step.
- Asking for five nines because it sounds good. Each additional nine makes the system considerably more expensive. Ask for the availability the business needs and can pay for.
- Excluding planned downtime. The customer does not care why they cannot buy.
- Letting the technical team prioritize alone. It will tend to prioritize what it finds most interesting. Priority is a business decision, made with technical information.
- Practical tip. If a stakeholder cannot tell you what figure they need, present them with two scenarios and their approximate cost. It is much easier to choose between options than to invent a number.
Exercises
Exercise 1: Functional or Non-Functional
Classify each of Verdalia's requirements as functional or non-functional. For the non-functional ones, state which quality attribute they correspond to.
- The customer can save products to a favorites list.
- The home page must load in under one second on 95% of visits.
- The system must generate the shipping label when the order is confirmed.
- Customers' passwords must be stored in a way that cannot be read.
- A new developer must be able to publish their first change during their first week.
- The customer receives an email when their order leaves the warehouse.
Exercise 2: From Vague Sentence to Scenario
Andrés wrote this requirement: “The checkout process has to be fast and never fail.” Rewrite it as two quality attribute scenarios, with their four parts. Keep in mind that the charge depends on PagoRaíz, an external service.
Exercise 3: Measure
With the lesson's functions, solve the following:
- Calculate by hand the mean, the p50, and the p90 of these latencies in milliseconds: 120, 340, 150, 95, 410, 130, 2200, 160, 145, 180.
- In a 30-day month, the store suffered two incidents, of 25 and 30 minutes. Is the 99.9% target met? What availability was achieved?
Solutions
Solution to Exercise 1
| Requirement | Kind | Attribute |
|---|---|---|
| 1. Favorites list | Functional | |
| 2. Home page load | Non-functional | Performance |
| 3. Shipping label | Functional | |
| 4. Password storage | Non-functional | Security |
| 5. First change in the first week | Non-functional | Maintainability and operability |
| 6. Warehouse departure email | Functional |
Requirement 5 is the least obvious: it does not describe anything the system does for the customer, but a quality of the system seen from the team's point of view. Stakeholders are not only customers.
Solution to Exercise 2
| Part | Performance scenario | Availability scenario |
|---|---|---|
| Stimulus | A customer confirms payment for their order | PagoRaíz stops responding |
| Environment | Campaign, 1,000 concurrent users | Normal operation |
| Response | The system shows the order confirmation | The system keeps the cart, informs the customer, and lets them retry the payment later |
| Measure | p95 under 3 s, including PagoRaíz's time | No cart lost; message shown in under 10 s |
Two important ideas. First: “never fail” is impossible, and even more so when depending on a third party. A good scenario does not promise that nothing will fail; it defines what must happen when something does fail. Second: the specific figures are a proposal that would have to be validated with Andrés; what matters in the exercise is that they are checkable.
Solution to Exercise 3
-
The values are sorted: 95, 120, 130, 145, 150, 160, 180, 340, 410, 2200.
- Mean: the sum is 3,930, divided by 10 gives 393 ms.
- p50: 50% of 10 is 5, so the fifth value is taken: 150 ms.
- p90: 90% of 10 is 9, so the ninth value is taken: 410 ms.
The mean, at 393 ms, is more than double the median because of a single extreme value.
-
The total downtime is 55 minutes. The 99.9% target allows 43.2 minutes in a 30-day month, so it is not met.
Output:
Common mistake: rounding 99.87% to “99.9%” and considering the target met. At these levels of demand, the hundredths matter: the difference between 99.87% and 99.9% is 12 minutes of closed store.
Conclusion
In this lesson you have learned to distinguish functional requirements from non-functional ones and to understand why it is the latter that determine the architecture. You have seen seven quality attributes with their definitions and measures, you have calculated latency percentiles and allowed downtime, and you have learned to write verifiable scenarios with stimulus, environment, response, and measure.
Verdalia now has something it did not have before: six scenarios, QS-1 through QS-6, that define what “working well” means, and a list of priorities agreed with the business, headed by availability and maintainability.
We know where we want to get to. The next question is what shapes a system can take to get there. In the next lesson, “Types of Systems Architectures,” we will go through the main architectural styles and see which of them Verdalia is in today.
