Sub topic 1
Clarifying Requirements and Scope
Prerequisites
This chapter assumes you know basic HTTP (methods, status codes, headers) and have used a relational or key-value database. You should also be able to read simple Python. No code is needed in this chapter. The later chapters use it.
Why start with requirements
A URL shortener looks trivial: store a long URL, hand back a short one, and redirect when someone visits it. The hard parts appear only when you ask how many links, how many clicks, how long links live, and what happens when the service is down. Answering these questions first keeps you from building the wrong system, so every later choice in this tutorial traces back to the list you write here.
In an interview or a design review, spend the first few minutes asking questions. State your assumptions out loud and get them confirmed.
Functional requirements
Functional requirements describe what the system does. For this tutorial, the core set is:
- Create: given a long URL, return a short URL.
- Redirect: given a short URL, send the visitor to the original long URL.
- Custom alias (optional): let a user choose the short code, such as
/spring-sale. - Expiry (optional): let a link stop working after a set date.
- Analytics (optional): count clicks on each link.
Mark each item as core or optional. Creating and redirecting are core. The rest are extensions that later chapters add around the redirect path.
Non-functional requirements
Non-functional requirements describe how well the system must work. They usually drive the architecture more than the feature list does.
| Requirement | Target for this design | Consequence |
|---|---|---|
| Latency | Redirects respond in tens of milliseconds | The read path needs a cache |
| Availability | Redirects keep working during partial failures | Replication and no single point of failure |
| Durability | A created link is never lost | Data is stored on durable, replicated storage |
| Scale | Many more reads than writes | Optimize reads first |
| Unpredictability | Codes are hard to guess | Avoid plain sequential codes (see the abuse chapter) |
The most important observation is the read-to-write ratio. People create a link once and click it many times. A ratio of 100 reads for every write is a common assumption. It makes the system read-heavy, which is why caching and read replicas appear so often in later chapters.
Scope: what is out of scope
State what you will not build. Typical exclusions for a first design are user accounts and billing, link previews, a full analytics dashboard, and editing the target of an existing link. Naming exclusions protects you from scope creep and tells reviewers which gaps are deliberate.
Common errors
- Skipping the ratio. Without a read-to-write estimate, you cannot justify a cache or decide how to scale storage.
- Treating optional features as core. Custom aliases and expiry change the data model and collision handling. Decide early whether they are in.
- Vague targets. "Fast" and "highly available" cannot be checked. Write numbers, such as "99.9% of redirects under 100 ms".
- Ignoring abuse. A public link creator is a target for spam and phishing. Put it on the requirements list now.
How requirements feed the design
The next chapter turns the read-heavy assumption into numbers: requests per second, storage per year, and how many characters a short code needs.
Exercise
A teammate says, "The system should be fast and reliable." Rewrite this as one non-functional requirement for the redirect path that can be tested, and name one design choice it pushes you toward.
Show answer
For example: "99.9% of redirects complete in under 100 ms, and redirects continue to work if one database node fails." The latency target pushes you toward a cache on the read path. The failure requirement pushes you toward replication. Any measurable target with a matching design consequence is correct.
Exercise
Why does the read-to-write ratio matter more than the total number of links when choosing where to optimize?
Show answer
Reads happen on every click, while a write happens once per link. If reads outnumber writes by about 100 to 1, the read path carries most of the load, so caching and read replicas give the largest benefit.