A URL shortener is the classic system design problem because it tests every layer of a modern architecture. You must translate vague requirements into a concrete application programming interface, estimate capacity without a calculator, and defend storage choices under extreme read loads. Here is how to structure an answer that demonstrates technical maturity, from the initial scoping phase through to resolving distributed bottlenecks.
Clarifying requirements and setting the scope
System design interviews begin with an intentionally vague prompt. If you immediately draw boxes on a whiteboard, you fail the first test: proving you know what you are building. You must ask questions to extract the exact requirements and restrict the scope of the problem. First, establish the functional requirements.
These dictate what the system must explicitly do for the user. A URL shortener has two primary functional requirements: taking a long URL to return a short one, and redirecting users who click the short link. You should also ask if users can choose custom aliases. This determines if your design must handle alias availability checks.
Next, define the non-functional requirements. These dictate the structural characteristics of the system. A redirection service must be highly available; if the system goes down, every short link across the internet breaks. It must also have incredibly low latency for redirects so users do not notice the routing hop.
Finally, the system must handle a massive read load, as links are clicked far more frequently than they are created. Always state explicit assumptions to narrow the problem space further before designing. For example, clarify whether URLs expire. Confirming that features like user accounts and billing are out of scope keeps your answer focused entirely on the core engineering challenge.
Capacity estimation and constraints
Before you design a database schema, you must know the volume of data it will hold. Providing a back-of-the-envelope calculation for traffic and storage demonstrates that your technical choices are grounded in mathematical reality. You should always state every figure as an explicit assumption before calculating. For example, assume one hundred million new URLs are generated a month.
You must then assume a high read-to-write ratio, as short links are typically shared publicly. Assume a ratio of 10/1, meaning ten redirects occur for every one creation. With these assumptions stated, show your working in plain text.
First, calculate the write operations per second. Find the number of seconds in a month by multiplying the days, hours, and seconds: 30 × 24 × 3600 = 2,592,000. Divide the monthly URL generation volume by this number: 100,000,000 / 2,592,000 = ~40 writes per second. Because the read-to-write ratio is 10/1, the read volume is simply 40 × 10 = 400 reads per second.
Next, calculate your storage needs. Assume the size of a single database record is 500 bytes. If the system generates one hundred million records a month, you must estimate the total size over a standard five-year lifespan. Five years is sixty months, so the total number of records is: 100,000,000 × 60 = 6,000,000,000.
Multiply six billion records by 500 bytes to find the total data size: 3,000,000,000,000 bytes, which is three terabytes. Knowing the entire dataset fits on a small number of modern hard drives heavily influences your storage design later. You can also estimate network bandwidth to prove thoroughness. Forty writes per second at 500 bytes each is roughly 20 kilobytes per second of incoming data, while 400 reads per second requires 200 kilobytes per second of outgoing bandwidth.
API design for creation and redirection
With the scale established, you must formalise how clients interact with the system. Defining the endpoints required proves you understand how to bridge the gap between network requests and back-end logic. You need one endpoint for creating the short link and one for executing the redirection.
Detail the expected request parameters and response payloads for the creation endpoint. The endpoint might look like an HTTP POST request to /api/v1/urls. The client sends a payload containing the original URL string. Optionally, the payload can include a custom alias string and an expiry date timestamp.
The server processes this request and returns a payload containing the newly minted short link. Documenting this contract shows the interviewer you understand data validation and routing. It also forces you to consider edge cases early, such as what HTTP status code to return if a custom alias is already taken.
For the redirection endpoint, a user visits the short link via an HTTP GET request to /{short_url}. Explain the HTTP response codes involved here, specifically the difference between returning a 301 and a 302 redirect. A 301 is a permanent redirect. It tells the browser to cache the response.
The next time the user clicks the short link, the browser routes them directly to the destination without contacting your servers. This drastically reduces server load but makes it impossible to track click analytics. A 302, conversely, is a temporary redirect. It forces the browser to ask the server for the destination every single time the link is clicked.
This maintains a heavy server load but allows the system to capture analytics for every interaction. For most enterprise URL shorteners, a 302 redirect is chosen despite the hardware cost, because tracking traffic is a primary business requirement. Explaining this trade-off demonstrates product awareness alongside technical competence.
The core challenge: ID generation strategies
The defining technical hurdle of a URL shortener is turning a long string into a unique, very short string without causing collisions. You must walk the interviewer through why naive approaches fail before presenting the optimal solution. A basic sequential ID strategy assigns numbers incrementally: 1, 2, 3. While simple, it creates predictable URLs, allowing malicious users to scrape every link in your database by requesting integers in order.
Another naive approach is hashing the long URL with an algorithm like MD5, which produces a long cryptographic string. If you take the first seven characters of that hash, you inevitably create collisions. Two completely different long URLs might yield hashes that start with the exact same sequence. Handling these collisions requires extra database checks, which slow down the creation process.
Introduce Base62 encoding as the optimal solution for packing a unique identifier into a short string. Base62 uses the twenty-six lowercase letters, twenty-six uppercase letters, and ten numbers. A seven-character Base62 string provides 62^7 combinations, yielding over three trillion unique identifiers. This is vastly more than the six billion records calculated in your capacity estimation.
The difference between a weak and a strong answer
When asked how to generate and assign these identifiers under high traffic, candidates often fall into a trap regarding database write locks. A step-by-step narrative contrasting a weak ID generation answer with a strong one shows exactly what system design interviews grade. A weak answer relies on basic database features to handle the logic on the fly:
"I would use a relational database with an auto-incrementing integer as the primary key. When a user submits a URL, the database assigns the next integer. I would then run a script to convert that base-10 integer into a Base62 string and return it. If two users submit at the exact same time, the database write locks will ensure they get different integers."
This answer fails at scale. Relying on a single database for an auto-incrementing ID creates a severe bottleneck. As your system attempts to process forty writes per second, the database must lock rows, increment the counter, and unlock rows. At peak traffic spikes, this locking mechanism will cause the entire application to slow down, increasing latency for the user.
A strong answer avoids on-the-fly generation entirely by introducing a standalone Key Generation Service:
"I will design a standalone Key Generation Service that runs independently of the main application. It pre-generates random seven-character Base62 strings and stores them in a dedicated database table. When an application server needs to create a short link, it requests an unused key from the memory buffer of this service. Once a key is handed to an application server, the service instantly marks it as used."
What changed here is the removal of the write bottleneck. The application servers do not wait for a database to calculate anything; they pluck a pre-computed key from memory in milliseconds. The risk of collisions is eliminated entirely, and the primary database is free to simply store the association between the pre-made key and the long URL. To handle failure, you can run multiple instances of the Key Generation Service and assign them distinct key ranges.
Data storage and the caching layer
Once the ID is generated, you must store the mapping between the short key and the original URL. Discuss the trade-offs between relational databases and NoSQL databases for this specific problem to demonstrate architectural thinking. A relational database provides strict guarantees for transactions and complex queries involving multiple tables. However, a URL shortener does not need to join tables or perform complex relational queries.
It simply maps one string to another. Conclude that a NoSQL key-value store is ideal because it operates without these unnecessary relational overheads. Key-value stores are designed for rapid lookups and scale horizontally with ease. This allows you to add more database servers as your storage needs cross the three-terabyte threshold over the next five years.
Because the system faces a massive read load, querying the database for every single click will eventually cause a failure. Introduce an in-memory cache to handle the heavy read volume. A cache sits between the application servers and the database, storing data in RAM for near-instant retrieval. Reading from RAM is orders of magnitude faster than reading from a solid-state drive.
Assume that link traffic follows a power-law distribution, where a tiny fraction of viral links generates the vast majority of clicks. By caching the top 1/5 most frequently accessed URLs, you intercept the heaviest traffic before it ever reaches the database. When a user requests a redirect, the server checks the cache first. If the link is present, it routes the user immediately.
If the link is missing, the server queries the database, updates the cache with the new link, and then routes the user. You must also explain your cache eviction policy. Least Recently Used is the standard choice here. When the cache reaches its memory limit, it deletes the URL that has gone the longest without a click to make room for new active links.
Scaling the system and resolving bottlenecks
A complete system design answer finishes by narrating how to scale the initial design to handle increased traffic over time. An interviewer wants to see that you can identify the weak points in your own architecture and add infrastructure to resolve them. Start at the network entry point. Discuss adding load balancers to distribute incoming HTTP requests across multiple application servers.
A load balancer continuously checks the health of each server and routes traffic only to those that are active. If a server crashes, the load balancer reroutes the traffic, ensuring the system remains highly available for end users. Because the application servers are stateless—meaning they do not hold any local data about the user—you can add hundreds of them to handle traffic spikes. This horizontal scaling guarantees your creation and redirection endpoints never drop incoming requests.
Next, explain database replication to resolve the primary bottleneck in a read-heavy system. Even with a cache, a single database will struggle to process four hundred reads a second alongside forty writes. You solve this by separating the read traffic from the write traffic. You deploy a primary database that handles all the write operations from the application servers.
You then spin up several read replica databases. The primary database continuously synchronises its data to the replicas. When a user requests a redirect, the load balancer routes that read query to one of the replicas. This separation means write spikes never interfere with redirection speed, and if read traffic doubles, you simply add more read replicas.
You must acknowledge the latency of replication. There is a fraction of a second where a new link exists in the primary database but has not yet copied to the replicas. If the creator clicks their new link instantly, they might see an error. You can solve this edge case by routing any read requests from the original creator directly to the primary database for the first few minutes, ensuring they always see their newly created link.
Before your next system design round
System design questions are intentionally open-ended. Your job is not to guess a hidden answer, but to impose structure on chaos. Use the URL shortener format as a template for any architecture problem you face. State assumptions explicitly before doing any maths.
- Write out API contracts to show how data moves.
- Weigh the trade-offs of your storage choices aloud.
- Build the simple version first, then scale it by resolving the bottlenecks.
To understand exactly how interviewers grade these choices across different architectures, read the guide on what system design interviews actually grade.
Reading about load balancers and key generation only takes you so far; the real test is defending these choices out loud under pressure. You can use Vrenic on the Free plan to practise the System Design interview type, where an AI interviewer asks questions one at a time and scores your answers out of 100 across four dimensions. Taking the time to narrate your architecture aloud ensures that when you step into the real interview, your delivery is as rigorous as your design.