DEV Community

Cover image for Week 1: Dockerised URL Shortener with Redis Caching & CI/CD – Live Demo
Lukest Mensah
Lukest Mensah

Posted on

Week 1: Dockerised URL Shortener with Redis Caching & CI/CD – Live Demo

As an ex-Uber driver grinding 1.5-hour mornings and full Thursdays, I’m on a 20-week mission to land a £100k+ AWS role. I wanted to move beyond "Hello World" tutorials and build something that felt production-ready. Week 1–2 of my "AWS Portfolio Battle Plan" is officially complete: Docker Fundamentals & Deep Dive, capped off with a live, high-performance URL shortener.

I built LukestAWS URL Shortener, a service that doesn't just shorten links, it handles them with a performance-first mindset using Redis caching and PostgreSQL.

The Architecture
I chose a modern, asynchronous stack to ensure the app could handle high concurrency without breaking a sweat:

  • FastAPI: For high-performance, async routing and automatic Swagger documentation.
  • PostgreSQL (15-alpine): Reliable persistent storage for URL mappings.
  • Redis (Upstash): A serverless cache layer that prevents unnecessary database hits.
  • Docker: Multi-stage builds to keep production images lean and secure, running as a non-root user.
  • Fly.io: Deployed on the edge to keep latency low.

Performance in Action: Redis Caching
The Redis integration is the star of the show. By caching both the long-to-short and short-to-long mappings, we bypass the database for repeat requests.

· First Request: Database write + Cache set.
· Second Request: Instant Cache Hit.
First Request: Database write + Cache set

Second Request:  Instant Cache Hit

The Code: How it Works
Here is a look at the shortener handler. Notice how it checks the cache first before even touching the database:
Python Code

The "Aha!" Moments (Challenges Overcome)
The most educational part of this build wasn't the code that worked, but the code that didn't.
· The SQLAlchemy Dialect Trap: While deploying, I hit a NoSuchModuleError. I learned the hard way that SQLAlchemy 2.0 dropped support for the postgres:// prefix. A quick regex fix to swap the environment variable to postgresql:// saved the day.

Try it Out
Check out the project in action:

  • Live Demo: aws-url-shortener.fly.dev
  • Interactive Docs: /docs (Authorize with your API key to test!)
  • Health Check: Check Status

Next week: Serverless SaaS with AWS CDK. Follow for the journey as I battle through the next 18 weeks!

Top comments (0)