Final Project: Build a Cached URL Shortener API
Put everything together in a URL shortener API that demonstrates production-grade caching. The read path (resolve a short code to a URL) should be extremely fast — this is 100x more frequent than the write path (create a short URL). Implement cache-aside with Redis as L2 and an in-process LRU as L1. Set TTL on cached URLs (1 hour) plus event-based invalidation when a URL is updated or deleted. Add jittered TTLs to prevent thundering herd on popular links. Use HTTP Cache-Control headers on the redirect response for CDN and browser caching of stable URLs. Benchmark with k6 or a simple load test script: run 1000 concurrent requests against /:code with an empty cache (cold start), then with a warm cache. You should see 10–50x latency improvement and near-zero database queries at high hit ratios. Track hit ratio, p99 latency, and Redis memory usage throughout.