Back to Projects

Microservice-based URL Shortener

NextjsTailwindCSSHeroUiAxiosNodeJsExpressJsPrismaPostgreSQLRedisDockerNginx

About this Project

A modern Microservice-based URL Shortener built with Next.js, Node.js, Express, Prisma, Neon PostgreSQL, Upstash Redis, and Docker. The architecture focuses on scalability, loose coupling, high performance, and production-ready deployment.





πŸ”— Live Demo





πŸ› οΈ Tech Stack

Frontend (User Interface)

  • Framework: Next.js 16 (App Router)

  • Styling: Tailwind CSS v4 + HeroUI (formerly NextUI)

  • HTTP Client: Axios with automatic JWT token injection via interceptors

  • Deployment: Vercel (Production Static Optimization)





Backend (Microservices Core)

  • Runtime: Node.js + Express + TypeScript

  • ORM: Prisma (v6 & v7)

  • Database: Neon PostgreSQL

    • user_schema

    • url_schema

  • Caching: Upstash Redis (Serverless Distributed Cache)

  • API Gateway: Dockerized Nginx

    • Reverse Proxy

    • SSL Handshaking

    • Custom CORS Preflight

    • Native Rate Limiting (HTTP 429)





Infrastructure & DevOps

  • Containerization: Docker

  • Optimized Builds: Multi-stage Dockerfiles

  • Local Orchestration: Docker Compose

  • CI/CD: GitHub Actions

  • Deployment Strategy:

    • Backend β†’ Render

    • Frontend β†’ Vercel





✨ Features

πŸ” JWT Authentication

Secure user registration and login handled by the dedicated user-service.

πŸ”— Logical Foreign Keys

Independent microservices communicate using loose-coupled userId string references without enforcing physical database foreign keys.

⚑ Distributed Caching

URL lookups first query Upstash Redis (O(1)), then fall back to PostgreSQL, significantly reducing database load.

🌐 API Gateway

Single centralized gateway powered by Nginx, hiding downstream services behind one public endpoint.

πŸ›‘οΈ DDoS Protection

Built-in Nginx rate limiting automatically returns HTTP 429 Too Many Requests during excessive traffic.

πŸš€ Monorepo CI/CD

GitHub Actions deploy only affected applications based on commit prefixes.


Commit Prefix

Action

backend:

Build & Deploy Backend to Render

frontend:

Build & Deploy Frontend to Vercel





πŸ“‚ Project Structure

lily-link/


β”‚


β”œβ”€β”€ .github/


β”‚   └── workflows/


β”‚       └── ci-cd.yml


β”‚


β”œβ”€β”€ gateway/


β”‚   β”œβ”€β”€ nginx.conf


β”‚   └── Dockerfile


β”‚


β”œβ”€β”€ services/


β”‚   β”œβ”€β”€ url-service/


β”‚   β”‚   β”œβ”€β”€ src/


β”‚   β”‚   └── Dockerfile


β”‚   β”‚


β”‚   └── user-service/


β”‚       β”œβ”€β”€ src/


β”‚       └── Dockerfile


β”‚


β”œβ”€β”€ frontend/


β”‚


β”œβ”€β”€ docker-compose.yml


β”‚


└── .env.sample





πŸš€ Local Development

Prerequisites

  • Docker

  • Docker Compose

  • Node.js

  • pnpm





1️⃣ Clone the Repository

git clone https://github.com/meheraj786/microservice-url-link-shortener.git


cd url-shortener





2️⃣ Configure Environment Variables

Create a .env file in the project root by following the .env.sample template.





3️⃣ Start All Services

docker compose up --build





4️⃣ Verify API Gateway

The Nginx API Gateway runs on Port 80.


Health Check:


curl http://localhost/health





πŸ“¦ Microservices

Service

Responsibility

user-service

Authentication, User Management, JWT

url-service

URL Shortening, Redirects, Redis Cache

gateway

Reverse Proxy, CORS, Rate Limiting





βš™οΈ Architecture Highlights

  • Microservice Architecture

  • Dockerized Infrastructure

  • Shared PostgreSQL with Isolated Schemas

  • Distributed Redis Cache

  • Centralized API Gateway

  • JWT Authentication

  • Conditional GitHub Actions CI/CD

  • Production Ready Deployment

  • Loose Coupling Between Services





πŸ›‘οΈ Security

  • JWT Authentication

  • Secure Password Hashing

  • Nginx Rate Limiting

  • Custom CORS Handling

  • Reverse Proxy Isolation

  • Environment Variable Configuration





πŸš€ Deployment

Service

Platform

Frontend

Vercel

Backend

Render

Database

Neon PostgreSQL

Cache

Upstash Redis

Gateway

Docker + Nginx





πŸ‘¨β€πŸ’» Author

Meheraj Hosen






πŸ“„ License

This project is licensed under the MIT License.



Β© 2026 Mehraj Hosen. All rights reserved.