For this system design question, let's design a URL shortening service like TinyURL or Bitly. The core functionality will involve taking a long URL as input and generating a significantly shorter, unique URL. Users should be able to enter a long URL, receive a short URL, and when accessing the short URL, be redirected to the original long URL.
Here are the main use cases we need to support:
Let's design a URL shortener service like bit.ly or tinyurl. I've built similar systems at Amazon and Google, so I have a good grasp on the tradeoffs involved. This design will focus on scalability, availability, and efficiency.
The system consists of the following components:
Workflow:
Column | Data Type | Description |
---|---|---|
id | BIGINT | Unique identifier for the mapping |
short_url | VARCHAR(255) | The generated short URL |
long_url | TEXT | The original long URL |
created_at | TIMESTAMP | Timestamp when the mapping was created |
expires_at | TIMESTAMP | Timestamp when the mapping expires (optional) |
user_id | BIGINT | ID of the user who created the mapping (optional) |
custom_alias | VARCHAR(255) | User defined short URL (optional) |
POST /api/shorten
Request Body: json { "long_url": "https://www.example.com/very/long/url", "custom_alias": "my-alias" //optional }
Response: json { "short_url": "https://short.url/my-alias" }
GET /{short_url}
short_url
path parameter.