QQ: can anonymous user create shortUrls
Fast follows:
Active Users: 200M
Traffic:
URLs created per user per day: 10 -> 2B writes/day -> 2B/86,400 -> 1/43 Million -> ~20K TPS
URL redirects per day: assume each short url is accessed on an avg 100 times. 100:1 read to write ration
URL redirects: 100 * 20 K ~= 2M TPS
At 10x peak = ~200k writes, 20M TPS reads
Storage:
Realistically, average long URL is ~200 chars and most users create <1 URL/day, bringing storage to ~10-100 GB/day." , per year 4TB-400TB.
POST /shorten
Request:
Response: [201 - created]
GET /{shortCode}
Response: [302 - redirect]
Entry Layer: A Load Balancer distributes incoming traffic across multiple API Gateway instances. The API Gateway handles SSL termination, rate limiting (e.g., 100 req/s per IP), request validation, and routes requests to the appropriate service (POST /shorten → Write Service, GET /{id} → Read Service).
CDN: Visitors hitting GET /{shortId} are routed through a CDN. If the mapping (shortId → longUrl) is cached at the CDN edge, the CDN serves a 302 redirect directly. On cache miss, it forwards to the API Gateway.
Write Path (Create a short URL):
Read Path (Redirect to long URL):
Storage Layer:
Table - URLShortener
shortId: partitionKey
longUrl: string (GSI - hashkey)
timestamp: datetime
ttl: long
userId: string (GSI - sortkey)
Writes use strong consistency, reads use eventual consistency.
URL Write Service: Generates a base62 range based partitioned key generation. This is used in message q to do strong consistent batch commit to dynamdb.
URL Read service: reads from redis cache to dyanmdb.
CDN: Viral shortUrls are handled by CDN and through cache protecting the datbase