Sub topic 1
Clarifying Requirements and Scope
Every system design starts with a conversation, not a diagram. A URL shortener looks trivial: take a long URL, return a short one, redirect when someone visits it. The design changes a lot depending on the answers to a few questions. This chapter covers how to turn a vague prompt into a list of requirements you can design against, and which decisions those requirements drive in later chapters.
Prerequisites
This chapter assumes you already know:
- Basic HTTP concepts: methods such as GET and POST, status codes, and headers.
- What a relational database and a key-value store are, at the level of "rows with a primary key" and "values looked up by key".
- What hashing is, and that numbers can be written in different bases (binary, decimal, hexadecimal).
- How to read short Python snippets.
No design experience is needed. Later chapters build on the requirements written here.
Why requirements come first
A prompt like "design bit.ly" leaves most of the problem open. Consider how different the systems could be:
- A shortener for an internal company wiki handles a few requests per second and can run on one small server.
- A public shortener handles tens of thousands of redirects per second and needs caching, replication, and abuse controls.
- A shortener that shows click statistics to marketers needs an analytics pipeline that the first two do not.
If you skip clarification, you risk building the wrong system well. The goal is to agree on scope, write down assumptions, and flag what you are deliberately leaving out.
Functional requirements
Functional requirements describe what the system does. For a URL shortener, the core set is small.
- Create a short link. Given a long URL, the service returns a short URL such as
https://sho.rt/aZ3k9Qx. - Redirect. When a client requests the short URL, the service sends it to the original long URL.
These two operations are the heart of the service. Everything else is optional and should be confirmed with whoever set the problem:
- Custom aliases. Can a user pick
sho.rt/spring-saleinstead of a generated code? - Expiry. Can a link stop working after a date? Does it have a default lifetime?
- Click analytics. Does the owner see counts, referrers, or countries?
- Accounts. Are links tied to users who can list or delete them, or is creation anonymous?
- Deletion and editing. Can the destination of an existing short link change?
Each optional feature adds a requirement to the data model or the request path. For example, "the destination can be edited" rules out permanent caching of redirects (see the redirect chapter). A useful habit is to split features into must-have, nice-to-have, and out of scope, and to say that split out loud.
Non-functional requirements
Non-functional requirements describe how well the system does its job. They usually shape the architecture more than the features do.
| Requirement | Typical target for a shortener | Design consequence |
|---|---|---|
| Low latency | Redirect in tens of milliseconds | Cache the read path, keep the lookup to one key |
| High availability | Redirects work even during partial failures | Replication, no single point of failure on reads |
| Durability | A created link is never lost | Persistent storage with backups or replicas |
| Scalability | Handle growth in links and traffic | Partitioning, stateless application servers |
| Uniqueness | No two long URLs share a short code | Careful code generation and collision handling |
| Unpredictability | Codes are hard to guess (if links are private-ish) | Avoid plain sequential codes, or accept the risk |
Not all of these hold equally. Availability matters more for redirects than for creation: a user who cannot create a link retries, but a broken redirect on a printed flyer or a published email fails silently for many people. Stating this asymmetry early lets you spend reliability effort where it counts.
Consistency is a requirement too
Ask what happens if a user creates a link and immediately opens it. Strong consistency means the redirect works at once. Eventual consistency might mean it fails for a second while replicas catch up. For a shortener, most designs accept eventual consistency on reads of old links but want read-your-own-write behavior for the creator. This is a real trade-off, and the later chapters on caching and replication return to it.
The read-heavy shape of the workload
A shortener is read-heavy. One link is created once and then clicked many times. A common planning assumption is a read-to-write ratio of 100:1, meaning 100 redirects for each new link. The ratio is an assumption, not a fact, and you should state it as one.
This single observation drives several decisions:
- The redirect path must be as short as possible: one lookup by key, no joins.
- Reads can be served from a cache, because the same popular links are requested again and again.
- Storage and replicas should be tuned for reads. Writes are rare enough that a single primary can often handle them for a long time.
Stating assumptions and constraints
Requirements gathering ends with a short, explicit list of assumptions. These feed the capacity estimates in the next chapter, so they should include numbers. A reasonable set for a public service:
- 100 million new short links per month.
- Read-to-write ratio of 100:1.
- Links are kept for 5 years unless they expire.
- The average long URL is about 100 bytes.
- Short codes should be short enough to type or print, so around 7 characters.
Write the numbers down even when you are unsure. A wrong but explicit assumption is easy to correct. An unstated one leads to two people designing different systems without knowing it.
Scope boundaries
Say what you are not building. For this tutorial, the scope is:
- In scope: create, redirect, code generation, storage, caching, scaling, expiry, custom aliases, basic analytics, and abuse protection.
- Out of scope: user account management, billing, a link management dashboard UI, and malware scanning pipelines beyond a basic mention.
Boundaries protect you from endless expansion. If someone later asks about the dashboard, you can point to the agreed scope and treat it as a new requirement with its own cost.
Turning requirements into a checklist
A compact way to record the result is a structured summary. The Python below holds the requirements as data and prints which ones affect the redirect path. It is a small illustration of the habit of tying each requirement to a design consequence.
requirements = [
{"name": "create short link", "kind": "functional", "on_redirect_path": False},
{"name": "redirect to long URL", "kind": "functional", "on_redirect_path": True},
{"name": "redirect latency under 50 ms", "kind": "non-functional", "on_redirect_path": True},
{"name": "99.99% redirect availability", "kind": "non-functional", "on_redirect_path": True},
{"name": "no duplicate codes", "kind": "non-functional", "on_redirect_path": False},
{"name": "optional link expiry", "kind": "functional", "on_redirect_path": True},
]
hot = [r["name"] for r in requirements if r["on_redirect_path"]]
print("Requirements that constrain the redirect path:")
for name in hot:
print(f"- {name}")Running it lists four requirements. Expiry appears because the redirect must check whether a link is still valid, which adds work to the hottest path. That kind of link between a feature and the request path is what you are looking for when you review requirements.
Common errors
- Jumping to the architecture. Drawing boxes for load balancers and caches before the numbers are known leads to designs that are either too small or needlessly complex.
- Treating all features as equal. Analytics and custom aliases are optional. Adding them without saying so inflates the problem.
- Ignoring the redirect path. Spending time on creation, which is rare, while the redirect, which is the real load, gets one line.
- Leaving numbers vague. "A lot of traffic" cannot be turned into storage or server counts. "100 million links per month" can.
- Forgetting abuse. A public shortener hides destinations behind opaque codes, which attackers use for phishing and spam. Even if you do not build defenses now, list abuse as a known concern.
What comes next
With a requirements list and a set of numeric assumptions, you can estimate traffic, storage, and the length a short code needs. That is the next chapter. After that, the API design chapter turns the two core functional requirements into concrete endpoints.
Exercise
A teammate says the shortener should "be fast and never go down." Rewrite this as two measurable non-functional requirements, and say which part of the system each one mainly constrains.
Show answer
For example: "95% of redirects complete in under 50 ms" constrains the read path, which pushes toward a cache and a single-key lookup. "Redirects are available 99.99% of the time" also constrains the read path, which pushes toward replication and no single point of failure. Creation can have looser targets because it is far less frequent and users can retry.
Exercise
You are told the workload has 100 times more redirects than link creations. Name two design decisions that follow from this, and one feature request that would work against them.
Show answer
Two decisions: serve redirects from a cache, and keep the redirect lookup to one key with no joins. A feature that works against them is letting owners edit the destination of an existing link, because cached or permanently redirected copies may keep sending users to the old URL.