URL Shortener Project

Overview

A URL shortening service that converts long URLs into short, shareable links. This project used to generate short URLs with Base62 encoding with collision handling.

Features

Architecture

architecture

Main Components

1. Client Layer

Users interact with the system through a web interface where they submit long URLs and receive shortened URLs in return.

2. Load Balancer & Reverse Proxy (nginx)

The entry point to the system. The nginx server acts as a reverse proxy and load balancer that distributes incoming requests across multiple backend servers.

  • Request routing to available servers
  • SSL/TLS termination for secure connections
  • Compression and caching of static assets

3. Rate Limiting Layer (Redis)

A dedicated Redis instance is used for rate limiting. It enforces 100 requests per minute per IP address.

4. Application Servers (Cluster)

Multiple backend servers run the core application:

  • Horizontally scalable
  • Stateless architecture
  • Handle shortening and redirection

5. Caching Layer (Redis Cache)

  • Fast retrieval of popular URLs (O(1))
  • Reduced database queries
  • TTL-based expiration

6. Database Layer (MongoDB)

  • Stores URL mappings
  • Tracks analytics and clicks
  • Stores metadata

Data Flow

Creating a Short URL

  1. Client sends long URL
  2. NGINX receives request
  3. Rate limiter validates request
  4. Server generates short code
  5. Store in MongoDB
  6. Cache in Redis
  7. Return short URL

Accessing a Short URL

  1. User visits short URL
  2. Check Redis cache
  3. If miss → query MongoDB
  4. Cache result
  5. Increment click count
  6. Redirect user

Key Architectural Features

Architecture Benefits

Technologies Used

How to Use

Installation

git clone https://github.com/yourusername/url-shortener.git
cd url-shortener
cd backend
npm install
npm start
    

Usage

  1. Open frontend in browser
  2. Enter long URL
  3. Click shorten
  4. Copy short link

Environment Variables

PORT=3000
MONGO_URI=your_mongo_uri
BASE_URL=http://localhost:3000