Question: Design a service like bit.ly.
Requirements: Shorten URLs, redirect to originals, track click analytics. Read-heavy: : read/write ratio.
Architecture: API Gateway, URL Service (generates short codes), Redirect Service (looks up and redirects). Database: DynamoDB for key-value lookups. Cache layer (ElastiCache) for hot URLs.
Short code generation: Base- encoding of an auto-incrementing counter. characters gives trillion unique URLs.
Scale: Billions of URLs, low-latency redirects. Cache the most popular % of URLs. Partition the database by short code prefix. TTL for expired links. Analytics pipeline writes to a separate datastore.