Sub topic 5
Actors, use cases and user stories
This chapter assumes you can tell a functional requirement from a non-functional one. It also assumes you have seen how stakeholders are interviewed to gather requirements. Here you turn that raw material into three working artifacts: a list of actors, a set of use cases, and a set of user stories. These are the link between "what people want" and the numbered functional requirements you write down. The running example is the URL shortener from the requirements plan.
Actors: who or what interacts with the system
An actor is anything outside the system that exchanges information with it or asks it to do something. Actors are roles, not individual people. One person can play several roles, and one role can be played by many people.
There are three common kinds:
- Primary actors start an interaction because they want a result. A link creator and a visitor following a short link are primary actors.
- Secondary actors are systems the service calls to finish its work, such as an email provider or a malware-scanning API.
- Time or system actors trigger work without a human, such as a scheduler that purges expired links.
The last two kinds are easy to miss, and missing them hides requirements. A scheduler that deletes expired links implies a retention rule. A malware scanner implies a dependency with its own latency and failure modes.
The actors for the URL shortener:
| Actor | Kind | Goal |
|---|---|---|
| Link creator | Primary | Get a short URL for a long one, and remove it later |
| Visitor | Primary | Reach the original page by following a short URL |
| Expiry scheduler | Time | Remove links past their expiry date |
| Abuse scanner | Secondary | Check destinations against known bad sites |
Test each actor with one question: what does this actor need from the system? If you can't answer, either the actor is not real or you haven't talked to the right stakeholder yet.
Use cases: one goal, many paths
A use case describes how one actor achieves one goal, including what happens when things go wrong. Its value is that it forces you to write the unhappy paths, and those paths are where hidden functional requirements live.
A useful use case has these parts:
- A name that is a verb phrase stating the goal, such as "Follow short link".
- The primary actor.
- Preconditions: what must be true before it starts.
- The main flow: numbered steps for the normal path.
- Alternate flows: numbered variations and failures, each tied to a step in the main flow.
- Postconditions: what is true afterward.
Here is "Follow short link" for the URL shortener:
use_case: UC-2 Follow short link
primary_actor: Visitor
preconditions:
- The short code was created and has not been deleted or expired.
main_flow:
1: Visitor requests the short URL.
2: System looks up the original URL by short code.
3: System responds with a redirect to the original URL.
alternate_flows:
2a: Short code does not exist, so the system responds "not found".
2b: Short code was deleted by its creator, so the system responds "gone".
2c: Short code has expired, so the system responds "gone".
postconditions:
- No data about the link is changed.
derived_requirements:
- FR-2
- FR-4 Deleted or expired short URLs return a "gone" response.Step 2b and 2c produced a new requirement, FR-4, that nobody had listed. This is the main reason to write alternate flows.
User stories: a promise to discuss
A user story is a short statement of value from one actor's view. The usual template is:
As a <actor>, I want <capability> so that <benefit>.The "so that" clause matters most. It records why the capability exists, so that later you can tell whether a different design still serves the goal.
A story is deliberately small. It is a placeholder for a conversation, and the detail lives in its acceptance criteria. These are concrete checks that decide whether the story is done. Many teams write them as Given/When/Then:
Story: As a link creator, I want to delete a short URL
so that a link I shared by mistake stops working.
Given a short URL I created
When I delete it
Then requests to that short URL return "gone"
Given a short URL created by someone else
When I try to delete it
Then the system refuses and the link keeps workingThe second scenario is a security rule that the story title alone would not reveal.
To judge whether a story is well formed, use the INVEST checklist. A good story is Independent, Negotiable, Valuable, Estimable, Small and Testable. "Testable" is the one that matters most for this tutorial. If you can't write an acceptance check, the story is too vague to build.
Use cases versus user stories
The two are not rivals. They work at different levels of detail.
| Aspect | Use case | User story |
|---|---|---|
| Size | One complete goal with all flows | One slice of value |
| Detail | Main and alternate flows written out | Acceptance criteria added as needed |
| Best for | Complex interactions, many failure paths | Planning and prioritizing work |
| Risk | Heavy documents nobody reads | Missing edge cases if criteria are thin |
A practical approach for system design is to write use cases for the core interactions, where failure paths matter, and stories for the rest. One use case often splits into several stories, such as one for the main flow and one for each important alternate flow.
Connecting the artifacts
The goal is traceability: every functional requirement should point back to an actor and a goal, and every actor goal should be covered by at least one requirement.
The diagram shows two useful checks. A requirement with no incoming line, an orphan, has no known purpose and is a candidate for removal. An actor goal with no outgoing line is a gap.
Use cases also feed the non-functional side. "Follow short link" is the most frequent interaction, so it is the one that needs the strict latency and availability targets. Counting how often each use case runs per actor is the first input to the load estimation covered later.
Common errors
- Writing stories about the system instead of an actor. "As the system, I want to cache results" is an implementation choice. Ask who benefits and rewrite it, or move it to the architecture.
- Using "user" for everyone. Collapsing creators, visitors and administrators hides different permissions and different load.
- Skipping alternate flows. Teams that write only the main flow discover errors, expiry and permission cases in production.
- Putting solutions in the story. "I want a dropdown menu" fixes the interface. Say what the actor needs to do.
- Stories that are too large. "As a creator, I want to manage my links" contains create, list, edit and delete. Split it until each piece can be tested on its own.
- Burying quality needs. "Fast redirects" in a story's prose cannot be tested. Move it to a measurable non-functional requirement and reference it from the story.
Exercise
A story reads "As a visitor, I want short links to open quickly so that I don't wait." Name two problems with it and rewrite it so it can be tested.
Show answer
Problems: "quickly" is not measurable, and the quality target is mixed into a functional story. Rewrite the story as "As a visitor, I want to be redirected to the original page when I open a short URL so that I reach my destination." Then add a separate non-functional requirement such as "99% of redirects complete in under 100 ms, measured at the service edge over 30 days," and link the story to it.
Exercise
The use case "Follow short link" has alternate flow 2c, where the short code has expired. Which actor does this flow reveal that was not obvious from the main flow, and what requirement follows?
Show answer
It reveals the expiry scheduler, a time actor that removes or marks expired links. The requirement is that expired short URLs must return a "gone" response, and that expiry dates must be stored with each link.