cd /news/ai-tools/building-a-url-shortener-designed-fo… · home › topics › ai-tools › article
[ARTICLE · art-176154] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

Building a URL shortener designed for 1.2M requests per second

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.

recommendation

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.

more in playbook: Running AI in production
by read3 min views1 publishedNov 25, 2026

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! 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.

attribute_not_exists(code)). If the code already exists a new one is generated instead Why 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.

If you look at the repo's decision records 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. The 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.

The 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.

By 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.

The 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).

In 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.

Thank 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.

If you'd like to see what I build next, you can follow me on X.

── more in #ai-tools 4 stories · sorted by recency
── more on @github 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/building-a-url-short…] indexed:0 read:3min 2026-11-25 · —