Sub topic 5
Actors, use cases and user stories
This chapter assumes you can tell a functional requirement from a non-functional one and have a list of stakeholders. It shows how to turn that list into actors, use cases and user stories. These three tools make functional requirements specific enough to design against.
Actors
An actor is anyone or anything outside the system that interacts with it. Actors are roles, not individual people. One person can play several roles, and a role can be played by software.
For the URL shortener, the actors are:
- Link creator: submits long URLs and deletes short URLs.
- Visitor: follows a short URL.
- Operator: deploys and monitors the service.
A scheduled cleanup job that expires old links is also an actor, because it triggers behavior from outside the core service.
Use cases
A use case describes one goal an actor wants to reach, plus the steps and the failures along the way. It names the main path and the alternatives.
Use case: Delete a short URL (FR-3)
- The link creator sends a delete request for a short URL.
- The system checks that the requester created the link.
- The system removes the mapping.
- The system confirms the deletion.
Alternative paths:
- The requester did not create the link: the system rejects the request.
- The short URL does not exist: the system reports that it was not found.
The alternative paths matter most. They expose requirements that the happy path hides, such as authorization checks and error responses.
User stories
A user story is a one-sentence need written in a fixed form, followed by acceptance criteria. The form is: "As a role, I want capability, so that benefit."
- As a link creator, I want to delete a short URL, so that a mistaken or outdated link stops working.
- As a visitor, I want a short URL to open the original page, so that I reach the content without typing a long address.
Acceptance criteria turn a story into something testable:
- Given a short URL I created, when I delete it, then later requests for it return "not found".
- Given a short URL created by someone else, when I try to delete it, then the request is rejected and the link still works.
Use cases versus user stories
| Aspect | Use case | User story |
|---|---|---|
| Detail | Steps, alternatives, failures | One sentence plus criteria |
| Best for | Complex flows with many branches | Planning and prioritizing work |
| Risk | Becomes long and goes stale | Hides edge cases if criteria are thin |
Use stories to plan and use cases to explore the flows that are risky or have many failure paths. Neither replaces the other.
Connecting to design
Each actor and use case implies design questions. The visitor's redirect is the most frequent action, so it drives the performance targets. The creator's delete action needs identity and ownership, so it affects the data model. Listing use cases for every actor also helps you check that no functional requirement is missing.
Exercise
A story says "As a visitor, I want fast redirects." What is wrong with it as a requirement, and how would you fix it?
Show answer
"Fast" is not testable, and it is a quality target rather than a capability. Keep the story for the capability (follow a short URL) and move the speed into a non-functional requirement with a number, such as "99% of redirects complete in under 100 ms, measured at the service edge over 30 days."