Design URL Shortener

Design URL Shortener

Medium Programming Interview System Design 18 views
Explanation Complexity

Problem Statement

Design a URL shortener like bit.ly. Focus on APIs, storage, and scaling.

Example Solution (Public)

Programming Interview
API: POST /shorten(longUrl), GET /{code}. Store mapping code->longUrl with createdAt and optional expiry. Generate codes with a monotonically increasing ID + base62. Cache hot mappings in Redis. Use redirects (301/302). For scale: partition by code prefix, add read replicas, and run analytics asynchronously.

Official Solution Code

API: POST /shorten(longUrl), GET /{code}. Store mapping code->longUrl with createdAt and optional expiry. Generate codes with a monotonically increasing ID + base62. Cache hot mappings in Redis. Use redirects (301/302). For scale: partition by code prefix, add read replicas, and run analytics asynchronously.
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.