A URL shortener is a service that converts a long URL into a shorter, more manageable version. These short links typically contain a short domain name and a unique identifier (e.g., bit.ly/abc123) that maps back to the original long URL.
Loading simulation...
Popular services like TinyURL, Bitly, and t.co (used by Twitter) rely on URL shorteners to:
In this chapter, we will explore the low-level design of an url shortener in detail.
Let's start by clarifying the requirements:
Before starting the design, it's important to ask thoughtful questions to uncover hidden assumptions, clarify ambiguities, and define the system's scope more precisely.
Here is an example of how a conversation between the candidate and the interviewer might unfold:
Candidate: Should the system automatically generate short URLs, or should users be able to specify custom aliases?
Interviewer: The system should support both. By default, it should generate a unique short URL automatically, but users can also provide a custom alias if they prefer.
Candidate: Should the short URLs have an expiration policy, or should they remain valid indefinitely?
Interviewer: By default, short URLs should not expire. But we should allow users to specify an expiration date if needed.
Candidate: Do we need to support analytics, like tracking click counts and timestamps?
Interviewer: For now, basic click count tracking will suffice.
Two of these requirements, custom aliases and expiration dates, are layered onto the core design rather than built into it from the first pass. The base design focuses on automatic key generation, deduplication, and click tracking, and section 7 shows how aliases and expiration slot in without changing that core.
Keeping the first version small makes the design easier to follow, and it doubles as a test of whether the abstractions hold up when requirements grow.
With the requirements settled, the next step is to identify the core entities and the algorithm that will power our design.