url shortener is a high-throughput, low-latency microservice-based link shortening system. It focuses on lightning-fast redirections and reliable visit count analytics.
URL shorteners look simple, but they are read-heavy systems where database lookups can quickly become a bottleneck. I wanted to build a service that scales reads horizontally. The core concept was simple: write to database, invalidate or write-through to cache, and read strictly from memory (Redis). If Redis fails, fall back to MongoDB. This taught me a lot about multi-tier caching architectures and cache synchronization strategies.
The primary challenge was managing "hot keys"—short URLs that suddenly get viral traffic. This could lead to a cache stampede or overload the Redis node hosting that key. I solved this by implementing a localized micro-cache on the API server instance for extremely hot keys, and utilizing locking mechanisms to ensure only one request repopulated the cache upon expiry.