{"slug": "building-a-url-shortener-designed-for-1-2m-requests-per-second", "title": "Building a URL shortener designed for 1.2M requests per second", "summary": "A developer built an open-source URL shortener designed to handle 1.2 million requests per second, publishing the implementation and architecture decision records on GitHub. The final design pairs Lambda and DynamoDB behind a CDN with a 90% cache hit rate, dropping Redis and a Postgres counter in favor of 7-character codes generated with conditional writes, and uses 302 redirects so links can be revoked via cache invalidation. The developer estimates origin costs of roughly $1.2k a month on Lambda plus DynamoDB versus $0.6–0.9k on ECS plus RDS, dwarfed by an estimated $39k monthly CDN bill at full scale.", "body_md": "I have been brushing up on my system design skills and I thought to myself \"what if I just build a URL shortener myself?\". So I did and the result is [on GitHub](https://github.com/curiousdirection/url-shortener)! I translated the classic interview-style system design question from something abstract into something concrete. With a coding agent this was feasible in a short amount of time.\n\n`attribute_not_exists(code)`). If the code already exists a new one is generated instead\nWhy a 302 and not a 301? A 301 is permanent, so browsers can keep it indefinitely and you can't easily take the link back. With a 302 that only the CDN caches, taking down a link is just a cache invalidation.\n\nIf you look at the [repo's decision records](https://github.com/curiousdirection/url-shortener/tree/main/docs/decisions) you will see how I arrived at the final design. I've listed the more interesting ones below. For each one I've linked the decision record if you are interested in more detail, which justifies each decision including consequences, alternatives and when to revisit.\n\nThe original design had a counter, which was used to generate the short code. The idea was that you increment the counter every time a URL is created. For the counter Redis was chosen. One of the first decisions I made was to replace Redis with a simple Postgres sequence. It was simpler to manage and reduced the points of failure. Although I hadn't fully thought through recovery at this point, having two separate DBs that can go out of sync would have been a challenge to solve.\n\nThe original design was deployed with a Network Load Balancer and EC2 with auto scaling. This could have likely been a viable end solution, and it would probably be the cheapest at full scale, but it was a lot of infrastructure to manage so I switched to ECS Express Mode instead.\n\nBy this point I was planning to use a CDN to cache URLs. What I hadn't realised was that using a CDN to cache URLs is the only way I know of to handle a 100x spike in the load. When my LLM compared the pricing of ECS Express Mode + RDS vs Lambda + DynamoDB I realised the difference is negligible at full scale, assuming the CDN is being hit 90% of the time. Behind the CDN, the origin would cost about $1.2k a month on Lambda + DynamoDB against $0.6–0.9k on ECS + RDS. Compared to the CDN itself, which would be about $39k a month, that difference disappears. So, I decided to switch to Lambda + DynamoDB instead. Using Lambda and DynamoDB simplified the infrastructure even further and the practice deployment dropped from about $50 a month to about $0 because nothing bills while idle. I had to drop the counter, but generating a 7-character code was good enough. If clashes start happening we can just increase to 8 characters. Some consequences of switching to Lambda + DynamoDB were deeper vendor lock-in and cold starts.\n\nThe final design doesn't involve Redis at all. With DynamoDB reads already taking single-digit milliseconds and assuming a 90% CDN cache hit rate it was hard to justify adding Redis (inside a VPC).\n\nIn the end I decided against separate functions for reads and writes. While the system is a lot more read than write heavy, the CDN already separates most of the traffic so it was hard to justify the extra complexity. I could imagine the original design with long-running servers benefiting from the separation.\n\nThank you for coming along for the ride. The part that I found most interesting was that the optimal solution involved not using Redis. Having a coding agent help me to iterate on the architecture, do research (e.g. pricing) and be a sparring partner is a game changer. Feel free to scrutinise the final implementation [on GitHub](https://github.com/curiousdirection/url-shortener).\n\nIf you'd like to see what I build next, you can follow me [on X](https://x.com/learnitmyway).", "url": "https://wpnews.pro/news/building-a-url-shortener-designed-for-1-2m-requests-per-second", "canonical_source": "https://dev.to/learnitmyway/building-a-url-shortener-designed-for-12m-requests-per-second-18o2", "published_at": "2026-11-25 14:34:33+00:00", "updated_at": "2026-11-25 14:42:37.936592+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents"], "entities": ["GitHub", "Redis", "Postgres", "DynamoDB", "AWS Lambda", "Amazon ECS", "Amazon RDS"], "also_reported_by": [], "takeaway": "Caching short-link redirects at the CDN with a 90% hit rate absorbs 100x load spikes, making the origin choice (Lambda plus DynamoDB at ~$1.2k/month versus ECS plus RDS at $0.6–0.9k) negligible next to a ~$39k/month CDN bill.", "recommendation": {"advice": "Put a CDN in front of read-heavy redirect endpoints and serve 302s so links stay revocable; at a 90% hit rate the origin database choice barely affects total cost.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/building-a-url-shortener-designed-for-1-2m-requests-per-second", "markdown": "https://wpnews.pro/news/building-a-url-shortener-designed-for-1-2m-requests-per-second.md", "text": "https://wpnews.pro/news/building-a-url-shortener-designed-for-1-2m-requests-per-second.txt", "jsonld": "https://wpnews.pro/news/building-a-url-shortener-designed-for-1-2m-requests-per-second.jsonld"}}