System design interview questions
Show answer
Clarify scale first. Generate short codes (random base62 or an encoded counter), store code → URL with a unique index, and serve redirects (301 vs 302) from a cache because reads dominate writes. Discuss collisions, custom aliases, expiry, analytics written asynchronously, and abuse prevention for malicious links.
Show answer
Browser cache (Cache-Control headers), CDN for static assets and public pages, an application cache (in-memory or Redis) for expensive queries, and database-level caching. Each layer needs an invalidation plan: short TTLs, cache keys that include a version, or purging on write.