Be Software Architecture Wise
Be Wise Apps

Leer en español · Lire en français · Auf Deutsch lesen

Section 2.3 of 2.8 · Intermediate · 18 min read

Writing quality attribute scenarios that can be tested

Video lesson

5 min · narrated, with captions
Listen only (audio)
Read the transcript

The last lesson gave you the vocabulary of qualities. This one gives you the grammar: a simple shape that turns any quality wish into something you can design for and test.

Telling a builder to make the roof strong gives them nothing to check. Saying the roof must hold fifty centimetres of wet snow during a winter storm does. It names what happens, the snow, and the conditions, a storm. And it says what should happen, no leaks, with a number you can measure: no more than two centimetres of sag. A quality attribute scenario does the same for software.

Every scenario has the same six parts, and together they tell a short story. Let's follow it from left to right. First, the source of the stimulus: the person, system or event that starts things off. Customers, a batch job, a developer, an attacker or a failing disk. Second, the stimulus itself: the event the system must respond to. A burst of requests, a server crash, a change request or a login with stolen credentials. Third, the artifact: the part of the system that's affected. Naming it tells the team where the design work and the measurement must happen. Fourth, the environment: the conditions. Normal operation, peak load, degraded or under attack. The same crash can demand very different responses in different conditions. Fifth, the response: what the system does. And sixth, the response measure: the number that tells you it worked well enough. The stimulus and the measure are the parts people most often leave out. Here's one complete example. Five hundred shoppers a second hit checkout on Black Friday. Orders are confirmed, ninety nine per cent of them in under one point five seconds, and no orders are lost.

There are two kinds of scenario. A general scenario is a template for one quality. For availability, it lists typical stimuli, such as a crash or an incorrect response, and typical measures, such as time to repair. A concrete scenario fills in specific values for one system. The primary order database crashes during normal operation, and writes resume within sixty seconds with no committed order lost. Concrete scenarios are your requirements. So you use the general scenario as a checklist, then write the handful of concrete ones that matter for your system.

Most quality requirements start life as adjectives. The site must be fast becomes: at the evening peak of three hundred searches a second, results return within four hundred milliseconds for ninety five per cent of requests, and one second for ninety nine per cent. Highly available becomes: if one of the three servers fails, bookings continue, no confirmed booking is lost, and users see errors for no more than thirty seconds. Notice it combines a speed number with a correctness number. Easy to change becomes: one developer can add a new delivery option in no more than three days, changing only the delivery module. If you're unsure of the right number, start from evidence and propose one. Asking whether four hundred milliseconds is acceptable produces a far better conversation than asking how fast it should be.

The same mistakes appear again and again. The first is leaving out the response measure. Without a number, a scenario is only a wish. The second is using an average for timing. Averages hide slow outliers, so specify percentiles instead. Section two point four explains why. The third is mixing several stimuli, such as load doubling or a server failing. Split them into separate scenarios. The fourth is the most damaging: writing a solution, such as use a message queue, in place of the need. If someone insists on a technology, ask what problem it solves. The answer is the real scenario. And the fifth is leaving out the environment. Recovers within five minutes, from what, and when?

A well-written scenario is already most of a test. Here is its life. Before release, it becomes an acceptance test. A performance scenario becomes a load test, and an availability scenario becomes a failover drill. Then it becomes a fitness function: an automated check that runs on every change, so the build fails when the quality drifts. Production monitoring watches it all the time, and that evidence flows back to refine the scenario and its numbers.

The full section has the six parts in detail, scenarios for six different qualities and a checklist to tell when a scenario is ready. Next, in Section two point four, we look at performance and scalability. See you there.

What you need to know

Why scenarios

Section 2.2 gave you the vocabulary of qualities; this section gives you the grammar. A quality name on its own, such as performance or security, cannot be designed for or tested. Even a number on its own is not enough: '2 seconds' means nothing until you know for which operation, under what load, measured where and for what share of requests. The quality attribute scenario, developed at the Software Engineering Institute (SEI) and set out by Len Bass, Paul Clements and Rick Kazman in Software Architecture in Practice, solves this by forcing every quality requirement into the same six-part shape.

The idea is simple. Every quality shows itself when something happens to a system: a surge of users, a crash, a change request, an attack. A scenario names that event, the circumstances, the part of the system affected, what should happen and how you will know it happened well enough. It is short (usually one to three sentences), concrete, and testable. And because every quality uses the same shape, scenarios for performance, security and modifiability can sit side by side in one prioritised list.

The six parts

The six parts are the source of stimulus, the stimulus, the artifact, the environment, the response and the response measure. Learn them in that order, since together they tell a short story: someone or something does something to part of the system under certain conditions; the system does something, and we measure it like this. The stimulus and the response measure are the two parts people most often leave out, and they are the two that matter most.

Anatomy of a scenario

The six parts of a quality attribute scenario: a source sends a stimulus to an artifact within an environment, which produces a response judged by a response measure1 Sourcewho or what2 Stimulusthe event4 Environmentnormal, peak, degraded, under attack3 Artifactsystem or part5 Responsewhat it does6 Responsemeasurethe numberExample: 500 shoppers per second (source, stimulus) hit checkout (artifact) on Black Friday (environment);orders are confirmed (response) with p99 under 1.5 s and no lost orders (response measure).
A source produces a stimulus that reaches an artifact within an environment; the artifact's response is judged by a response measure.

The six parts in detail

PartMeaningExamples
Source of stimulusThe person, system or event that generates the stimulus.Customers on mobile phones; an internal batch job; a developer; an attacker; a failing disk.
StimulusThe event the system must respond to.A burst of requests; a server crash; a change request; a login attempt with stolen credentials.
ArtifactThe part of the system that is stimulated: the whole system or a specific component.The checkout service; the order database; the pricing module; the deployment pipeline.
EnvironmentThe conditions under which the stimulus arrives.Normal operation; Black Friday peak; one data centre down; during a deployment; in development.
ResponseWhat the system (or the people around it) does as a result.Processes the order; fails over to the replica; the change is made, tested and deployed; the attempt is blocked and logged.
Response measureHow the response is measured, so the scenario can be tested.p99 below 800 ms; service restored within 60 s with no lost orders; under 2 person-days; 100% of attempts blocked.

The environment deserves special care because the same stimulus can demand very different responses in different conditions. A crashed server during normal operation might require automatic failover within a minute; the same crash during a planned maintenance window might be acceptable with a manual recovery. A change request at design time (before release) costs far less than the same change once data has accumulated in production. Writing the environment explicitly stops people from comparing scenarios that are really about different situations.

The artifact matters for a similar reason. 'The system responds within 200 ms' hides which part is responsible. Naming the artifact (the search service, the API gateway, the mobile client) tells the team where the design work and the measurement must happen. For some qualities, such as modifiability and deployability, the artifact may be code, configuration or the delivery pipeline rather than a running component.

General and concrete scenarios

Bass, Clements and Kazman distinguish two kinds. A general scenario is system-independent: for one quality attribute it lists the typical values each part can take. For availability, for example, the sources might be internal or external, people, hardware, software or infrastructure; stimuli might be a crash, an omission, incorrect timing or an incorrect response; responses might be detecting, recording, recovering, masking or degrading; and measures might be time to detect, time to repair, availability percentage or the proportion of requests handled.

A concrete scenario picks specific values for one particular system: 'the primary order database crashes during normal operation; the replica takes over and writes resume within 60 seconds with no committed order lost'. General scenarios are templates and checklists; concrete scenarios are requirements. You use the general scenario to make sure you have considered the right sources, stimuli and measures, then write the handful of concrete scenarios that matter for your system.

From vague statements to testable scenarios

Most quality requirements start life as adjectives. The skill is to ask the questions that turn each adjective into a scenario: which operation? caused by whom? how often or how much? under what conditions? what should happen? what number tells us it worked? The table shows typical before-and-after pairs. Notice that the 'after' versions sometimes reveal that the stakeholder meant several different things, which then become several scenarios.

Before and after

Vague statementTestable scenario
The site must be fast.During the weekday evening peak of 300 searches per second, product search returns results within 400 ms for 95% of requests and 1 s for 99%, measured at the load balancer.
The system must be highly available.If one of the three application servers fails during normal operation, the booking service continues to accept bookings; no confirmed booking is lost and users see errors for no more than 30 seconds.
The system must be secure.When an attacker submits 10,000 login attempts per minute using leaked credentials, the system blocks the source after 20 failures, alerts the security team within 5 minutes, and genuine users at other addresses can still log in.
The code must be easy to change.When the business asks for a new delivery option, one developer familiar with the code can implement, test and deploy it in no more than 3 days, changing only the delivery module and its configuration.
The app must be user-friendly.A first-time user with no training can register and place an order in under 4 minutes; 90% of test participants succeed at the first attempt.
Deployments must be easy.A developer can release a change to the ordering service to production in under 30 minutes after merge, with no downtime, and roll it back within 5 minutes if error rates rise.

Scenario examples across six qualities

The examples below use one online shop so you can see how different qualities look in the same format. Each is written compactly with all six parts labelled; in practice teams often write them as one or two sentences.

Concrete scenarios for an online shop

QualityScenario (source, stimulus, artifact, environment, response, measure)
PerformanceSource: logged-in customers. Stimulus: 2,000 order submissions per minute. Artifact: checkout service. Environment: Friday evening peak. Response: orders validated, stored and confirmed. Measure: p95 ≤ 1.5 s, p99 ≤ 3 s, zero orders lost.
AvailabilitySource: internal hardware. Stimulus: the primary database node crashes. Artifact: order database. Environment: normal operation. Response: replica promoted automatically, in-flight requests retried. Measure: writes resume within 60 s; no committed order lost (RPO = 0).
ModifiabilitySource: product owner. Stimulus: request to add a new payment method. Artifact: payment component. Environment: design time, after initial release. Response: change made, tested and deployed. Measure: ≤ 5 person-days; no change outside the payment component; no regression in existing methods.
SecuritySource: a logged-in customer acting maliciously. Stimulus: attempts to read another customer's orders by changing an ID in the URL. Artifact: orders API. Environment: normal operation. Response: request denied and logged with the caller's identity. Measure: 100% of such requests rejected; alert raised within 1 minute after 5 attempts.
UsabilitySource: first-time customer. Stimulus: wants to change a delivery address after ordering. Artifact: web and mobile front ends. Environment: runtime, no help available. Response: completes the change unaided. Measure: 90% of usability-test participants succeed within 2 minutes.
DeployabilitySource: developer. Stimulus: a merged change to the catalogue service. Artifact: deployment pipeline and catalogue service. Environment: business hours, normal load. Response: built, tested and rolled out progressively. Measure: in production within 45 minutes; zero downtime; automatic rollback within 5 minutes if error rate exceeds 1%.

Two features of these examples are worth noticing. First, scenarios are not only about running software. Modifiability and deployability scenarios have developers and product owners as sources, and their measures are effort, elapsed time and the scope of change. Second, good measures often combine a speed number with a correctness number: 'within 60 seconds' and 'no committed order lost'. A fast failover that loses data is not what the business wanted.

Common mistakes

Reviewing hundreds of scenarios written by teams reveals the same mistakes again and again. Each makes a scenario untestable or misleading.

Mistakes and how to fix them

MistakeExampleFix
No response measure'Under peak load the checkout responds quickly.'Add a number and a statistic: 'p95 ≤ 1.5 s, p99 ≤ 3 s'.
Average instead of percentile'Average response time under 300 ms.'Averages hide slow outliers; specify percentiles (Section 2.4).
Several stimuli in one scenario'When load doubles or a server fails or a deployment runs, the system stays fast.'Split into three scenarios, each with its own environment and measure.
Solution disguised as requirement'The system uses Redis to cache product pages.'State the need ('product pages load in under 300 ms for 95% of views at 1,000 views per second') and leave the cache as a design option.
Missing environment'The service recovers within 5 minutes.'Say from what and when: 'after a single zone outage during normal operation'.
Unmeasurable words'Gracefully', 'seamlessly', 'robustly', 'user-friendly'.Replace each with an observable behaviour and a number.
Impossible absolutes'The system never goes down.' '100% of attacks blocked.'Use realistic targets and say what happens when they are missed.

Decision guide

Decision guide: is this scenario ready?

Run each draft scenario through these questions before it goes into the architecture document or the backlog.

  1. Does it describe a single stimulus with a named source?
    YesContinue.
    NoSplit it, or name who or what causes the event.
  2. Does it state the environment (normal, peak, degraded, during deployment, at design time)?
    YesContinue.
    NoAdd the conditions; otherwise the measure cannot be interpreted.
  3. Does it name the artifact, the part of the system responsible?
    YesContinue.
    NoName the component, interface or pipeline so the team knows where to design and measure.
  4. Is the response an observable behaviour rather than a technology choice?
    YesContinue.
    NoRewrite the need and move the technology into a design decision or a constraint.
  5. Does the response measure contain a number, a unit and, for timing, a percentile?
    YesThe scenario is testable: add a priority and an owner.
    NoAdd the measure; without it the scenario is a wish.

From scenarios to acceptance tests and fitness functions

A well-written scenario is already most of a test. The source and stimulus tell you what load or event to generate, the environment tells you how to set up the test, the artifact tells you what to observe and the response measure gives the pass condition. A performance scenario becomes a load test; an availability scenario becomes a failover drill or a chaos experiment; a modifiability scenario becomes a review of how much code a sample change touched and how long it took; a security scenario becomes a penetration test case.

The next step is to keep checking. A fitness function, a term popularised by Neal Ford, Rebecca Parsons and Patrick Kua in Building Evolutionary Architectures, is any automated or repeatable check of how well the system meets an architectural goal. Run in the delivery pipeline or against production telemetry, it turns a scenario from a one-off acceptance test into a permanent guard: the build fails, or an alert fires, when the quality drifts. Chapter 11 covers fitness functions in depth in Fitness functions and evolutionary architecture.

The life of a scenario

A quality scenario becomes an acceptance test before release and a fitness function that keeps checking it afterwards, with production monitoring feeding back into the scenarioQualityscenarioAcceptancetestFitness functionin the pipelineProductionmonitoringevidence refines the scenario and its numbersbefore releaseon every changeall the time
A scenario drives an acceptance test, then a fitness function that runs on every change, and production evidence feeds back to refine the scenario.
# A performance scenario expressed as an automated check (illustrative)
# Scenario: at 300 searches/s, p95 <= 400 ms and p99 <= 1000 ms.
import statistics

def check_search_latency(latencies_ms, p95_target=400, p99_target=1000):
    cuts = statistics.quantiles(latencies_ms, n=100)  # 99 cut points
    p95, p99 = cuts[94], cuts[98]
    assert p95 <= p95_target, f"p95 {p95:.0f} ms exceeds {p95_target} ms"
    assert p99 <= p99_target, f"p99 {p99:.0f} ms exceeds {p99_target} ms"
    return p95, p99

# latencies_ms comes from a load test that replays 300 searches per second
# for ten minutes against a production-like environment.
A performance scenario turned into a simple automated check of p95 and p99 latency.

How professionals use scenarios

In practice, teams rarely write long tables of six-part scenarios for everything. They write a small number, often ten to thirty for a substantial system, for the qualities that are architecturally significant, and they keep them where everyone can see them: in the architecture document (arc42 section 10 asks for exactly this), in the backlog as acceptance criteria, or in a shared quality board. Some teams use a shorter form; Gernot Starke's Q42 project, for instance, recommends a compact structure of context, trigger and acceptance criteria. The shape matters less than the discipline: every important quality has a stimulus, a context and a number.

Scenarios also power evaluation methods. The Quality Attribute Workshop and the Architecture Tradeoff Analysis Method (ATAM), both from the SEI, collect and prioritise scenarios with stakeholders and then test the architecture against the most important ones. Section 2.8 shows how scenarios are gathered and ranked in a utility tree.

Check your understanding

Name the six parts of a quality attribute scenario in order.

Source of stimulus, stimulus, artifact, environment, response and response measure.

What is wrong with 'the system uses a CDN so that pages load fast'?

It states a solution, not a need, and has no measure. The requirement should describe the load, conditions and target response time; the CDN is one possible design to meet it.

Who is typically the source of stimulus in a modifiability scenario?

A person who wants a change, such as a product owner, a developer or a regulator; the stimulus is the change request.

How does a scenario differ from a fitness function?

A scenario is a statement of a requirement; a fitness function is an automated or repeatable check that measures whether the system meets it, run continuously.

Next · 2.4Performance and scalabilityLatency and throughput, percentiles and tail latency, Little's law, queueing and the utilisation cliff, Amdahl's law and the Universal Scalability Law, with worked calculations and an overview of performance tactics.Continue →

Sources and further reading

Have a question about this section? ArchitectBot, the course’s AI study assistant, answers from the course first.

Ask: “Can you help me turn 'the API must be highly available and fast' into proper quality attribute scenarios for a food-delivery app?”