Functional Requirements:
Non-Functional Requirements:
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
POST /shorten — User sends their long URL, you return a short codeGET /{shortCode} — User visits the short URL, you redirect them to the originalDescribe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
Components:
Write Flow (Create Short URL):
POST /shorten with { "long_url": "https://..." }shortCode → longURL) to database (master){ "short_url": "tinyurl.com/abc123" }Read Flow (Redirect):
tinyurl.com/abc123abc123Key Design Decisions:
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...
Table: url_mappings
| Column | Type | Constraints |
| id | BIGINT | PRIMARY KEY, AUTO_INCREMENT |
| short_code | VARCHAR(7) | UNIQUE, NOT NULL, INDEXED |
| long_url | TEXT | NOT NULL |
| created_at | TIMESTAMP | NOT NULL, DEFAULT NOW() |
| expires_at | TIMESTAMP | NULLABLE |
Indexes:
UNIQUE INDEX idx_short_code ON url_mappings(short_code) — for fast redirect lookupsINDEX idx_created_at ON url_mappings(created_at) — for analytics/cleanup of old recordsPartitioning (at scale):
short_code hash (e.g., 16 partitions) for even data distributioncreated_at (e.g., monthly) for time-based archivalWhy SQL?
Consistency: Strong consistency for writes (code must be unique and durable). Eventual consistency is fine for redirect reads — a brief delay is acceptable.
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
1. ID Generation (short code creation)
We generate random 6-character base62 strings (a-z, A-Z, 0-9 = 62^6 ≈ 56 billion combinations).
2. Caching (Redis)
3. Database Partitioning
url_mappings table by hash(short_code) % 16 — 16 database shards.4. Rate Limiting
Retry-After header when exceeded.