Beginner LevelSystem Design & Architecture
How do you design a high-throughput URL Shortener (like Bitly)?
β Interview Prompt: Explain designing a URL Shortener, Base62 encoding, auto-increment IDs vs MD5 hashing, Redis caching, and HTTP 301 vs 302 redirects.
Designing a high-throughput URL Shortener service (e.g. Bitly):
Key Components:
1
Short Code Generation: Convert auto-incrementing integer IDs into Base62 strings ('[0-9, a-z, A-Z]'). A 7-character Base62 string supports $62^7 \approx 3.5 \text{ Trillion}$ unique short URLs!
2
Redirect Types:
β’
'HTTP 301 Permanent': Browser caches redirect locally (reduces server load, loses click analytics).
β’
'HTTP 302 Temporary': Browser requests short URL every time (enables click analytics tracking).
3
Caching: Cache top 20% hot short URLs in Redis.
Code Implementation Example
typescript
const BASE62_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// Converting Auto-Increment ID to Base62 Short Code
export function idToBase62(id: number): string {
let code = '';
while (id > 0) {
code = BASE62_ALPHABET[id % 62] + code;
id = Math.floor(id / 62);
}
return code.padStart(7, '0');
}π‘Encoding database sequence IDs into 7-character Base62 short codes.
π― Interview Key Takeaway
Design URL shorteners by converting auto-increment IDs to Base62 strings and caching hot mappings in Redis.
#System Design#URL Shortener#Base62#System Architecture#Beginner
Back to all System Design & Architecture Questionsβ