Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
Traffic Estimation: assume 100 million URLs created per month and read-to-write ratio of 100:1
Storage Estimation:
Storage Needed:
Bandwidth:
Request:
{ "long_url": "https://www.example.com/very/long/url/here", "custom_alias": "myalias" // optional}
Response (201 Created):
{ "short_url": "http://tinyurl.com/abc123", "long_url": "https://www.example.com/very/long/url/here", "created_at": "2024-01-15T10:30:00Z"}
GET /{short_key}
Redirects the user to the original long URL. Returns a 301 (permanent redirect) — good for SEO/caching, or 302 (temporary) if you want to track analytics per click.
Response (301/302):
Location: https://www.example.com/very/long/url/here
DELETE /{short_key}
Removes a short URL. Requires auth.
Response: 204 No Content
1. Client → DNS → CDN → Load Balancer → API Gateway (Entry Layer)
2. Write Path — Shortener Service
POST /shorten requests3. Read Path — Redirect Service
GET /{short_key} requestsLocation header4. ID Generation Service
5. Caching Layer (Redis)
6. Database (Storage Layer)
short_key → long_url, created_at, expiryflowchart TD Client[User / Browser] DNS[DNS] CDN[CDN] LB[Load Balancer] GW[API Gateway] subgraph Write[Write Path] Svc[Shortener Service] IDGen[ID Generator] end subgraph Read[Read Path] Redirect[Redirect Service] Cache[(Redis Cache)] end DB[(Database)] Client --> DNS --> CDN --> LB --> GW GW -->|POST /shorten| Svc Svc --> IDGen Svc --> DB GW -->|GET /{key}| Redirect Redirect --> Cache Cache -->|miss| Redirect Redirect --> DB DB --> Redirect Redirect -->|30
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.