I Built a URL Shortener From Scratch When Bitly Exists for Free

Bitly doesn't teach you how Bitly works. That's exactly what I needed to learn — so I built one, properly, and let caching break my brain for an evening.

By Akshay More · 2026-09-05 · 5 min read · Backend Engineering

I Built a URL Shortener From Scratch When Bitly Exists for Free

Before you say anything — I know. I know.

Bitly exists. It's free. It works. Nobody asked for another URL shortener.

But Bitly doesn't teach you how Bitly works. And that's exactly what I needed to learn. So I built one. Properly. Production grade. Node.js, TypeScript, Express, Postgres, Redis.

Here's what actually broke my brain: caching.

The part that sounds simple

Store the short URL to long URL mapping in Redis. Done. Ship it.

That's what I thought too.

Reality: I spent an entire evening figuring out why my cache wasn't invalidating properly. The redirect was serving stale URLs. Confidently. To nobody, because it's a test project — but confidently nonetheless.

A user updates or re maps a short link, and the redirect keeps sending people to the old destination. The database has the right answer. Redis doesn't know that yet, and it doesn't care. It just serves what's cached, fast and wrong.

That one bug taught me more about caching than any tutorial ever did.

What actually broke and why

The naive mental model of caching is: store it, read it, move on. What I hadn't internalized is that a cache is not just a faster copy of your data — it's a second source of truth that can silently disagree with the first one.

Redis isn't just "fast storage." It's a whole strategy:

TTL (time to live) — how long a mapping stays cached before it's forced to re check the database. Set it too long, and stale data lives longer than it should. Too short, and you're hitting Postgres on every redirect, defeating the point of caching at all. Eviction policies — what happens when Redis runs out of memory and has to decide what to throw away. Least recently used, least frequently used, random — each one changes which links stay fast and which ones quietly go cold. Cache warming — pre loading frequently accessed mappings instead of waiting for the first request to populate the cache. Without it, your most popular links pay the "cold cache" penalty right when it matters most.

None of this shows up when you write redis.set(shortCode, longUrl) for the first time. It shows up the first time you update a mapping and forget the cache doesn't know that happened.

Rate limiting: harder than it looks

The second thing that humbled me was rate limiting. On paper: count requests per user, block them past a threshold. Simple counter, right?

Except the moment you run more than one instance of your API — which you will, if this thing is meant to survive real traffic — a counter sitting in memory on one server doesn't know what happened on the other server. Two instances, two independent counters, and your rate limit silently doubles.

That's the moment "simple" rate limiting becomes a distributed systems problem. You need a shared, atomic counter — which is, again, exactly the kind of thing Redis is built for, but exactly the kind of thing that's invisible until you actually need it.

A "simple" project stopped being simple the moment I asked it to behave correctly under real conditions instead of ideal ones.

Why build the thing that already exists

Here's the actual point, and it's not about URL shorteners.

Using Bitly teaches you nothing about caching, TTLs, eviction policies, or distributed rate limiting. It teaches you how to fill out a form and click "Shorten." That's a completely different skill from understanding why Bitly needs Redis, why it needs a distributed counter, why "just cache it" is a sentence that hides half the actual engineering.

The project isn't the point. The problems you hit while building it — that's the whole point.

What I'd tell someone about to skip this exercise

It's tempting to only build things that don't already exist. New idea, new problem, more interesting portfolio piece. But some of the best engineering lessons live inside "solved" problems, because the solution is deceptively simple to describe and genuinely hard to implement correctly .

A URL shortener sounds like a weekend toy project. It's actually a compressed lesson in: Cache invalidation (one of the two genuinely hard problems in computer science, and everyone finds that out the hard way, including me) Distributed state (rate limiting doesn't work the same on one server vs. many) The gap between "it works on my machine" and "it works under real, concurrent, adversarial load"

Takeaway

Build something that already exists. Break it in ways the original creators already solved for. Fix it yourself, badly at first, then better. Repeat.

You won't out engineer Bitly. That was never the goal. But you'll understand, in your hands, why every "obvious" system design decision in a tool like it was actually a hard won answer to a bug exactly like the one that cost me an evening.

What's the most painful bug you've ever spent too long on?