The client sends the long URL to the API server.
The server generates a unique short code and stores the mapping
between the short code and the original URL in the database.
POST /shorten
Request Body: {"long_url": "https://example.com/articles/system-design"}
Response: {"short_url": "https://short.ly/abc123"}
Redirect to original URL: GET /{short_code}
Response: {"click_count":1024}
This endpoint returns analytics data such as the number of times
a shortened URL has been accessed.
Client → Load Balancer → API Servers → Cache → Database
Clients interact with the system through HTTP requests.
The load balancer distributes incoming traffic across multiple API
servers to ensure scalability and fault tolerance.
API servers process requests for creating and resolving short URLs.
A caching layer (Redis) is used to store frequently accessed
URL mappings to reduce database queries.
The database stores the persistent mapping between short codes
and original URLs.
URL Creation flow:
Client submits long URL
↓
API server generates short code
↓
Mapping stored in database
↓
Short URL returned to client
Redirection flow:
User opens short URL
↓
API checks cache
↓
Cache hit → return original URL
Cache miss → query database
↓
Redirect user
API servers handle incoming requests from clients.
They expose REST endpoints for creating and resolving URLs.
Multiple instances run behind a load balancer to ensure scalability.
Validate incoming URLs
Generate short codes
Interact with cache and database
Return responses to clients
The short URL generator creates unique identifiers
for each long URL.
Advantages: Store frequently accessed URL mappings
Reduce database load
Improve redirect latency
Cache layer: Uses Redis
Store frequently accessed URL mappings
Reduce database load
Improve redirect latency
Database:
Table: url_mapping
short_code (primary key)
long_url
created_at
expiration_date
click_count
Load Balancer:
Improves scalability
Prevents server overload
Provides fault tolerance