Skip to content

huymatthew/FastLink

Repository files navigation

High Performance URL Shortener

Overview

A cutting-edge URL shortener designed for speed and scalability, leveraging Django, Gunicorn, Redis, and PostgreSQL to deliver exceptional performance under heavy load.

This project handles 1000+ concurrent users and sustains 30,000+ requests per minute with minimal latency.

Badges

CI/CD Docker Python Redis Nginx PostgreSQL

Performance Concurrency

Tech Stack

  • Django: Robust web framework for rapid development and clean design
  • Gunicorn: High-performance WSGI server for concurrent request handling
  • Redis: In-memory caching to reduce response times
  • PostgreSQL: Reliable relational database for URL mappings
  • Nginx: Reverse proxy for traffic routing and static file serving

System Architecture

Microservice architecture with containerized components (Django API, Redis cache, PostgreSQL database, Nginx gateway) enabling horizontal scaling, independent deployment, and optimal resource utilization.

graph TD
    User[User / Client] -->|HTTP Request| Cloudflare[Cloudflare DNS/Proxy]
    Cloudflare -->|Load Balancing| Nginx[Nginx Reverse Proxy]
    Nginx -->|Proxy Pass| Gunicorn[Gunicorn WSGI]
    Gunicorn -->|Application Logic| Django[Django Backend]
    Django -->|Read/Write| Redis[Redis Cache]
    Django -->|Persist Data| DB[(PostgreSQL)]
    
    subgraph Compose["Docker Compose Infrastructure"]
        Nginx
        Gunicorn
        Django
        Redis
        DB
    end
Loading

Performance & Stress Testing

Test Infrastructure

The system was stress tested using K6 on Azure Standard_F8s_v2 infrastructure:

  • vCPUs: 8 cores
  • RAM: 16 GB
  • Concurrency: 1,000 Virtual Users (VUs)
  • Duration: 60 seconds

Test Results

Metric Value Status
RPS (Requests per Second) ~1,200 req/s
P95 Latency < 50ms
Error Rate 0%
CPU Usage 60-70% (Stable)

Key Performance Features

  • Redis Caching: P95 latency maintained under 50ms thanks to efficient Redis caching strategy
  • Zero Errors: 100% success rate under 1,000 concurrent users
  • Optimal Resource Usage: CPU usage remained stable at 60-70%, indicating good headroom for scaling
  • High Throughput: Sustained 1,200+ requests per second over 60-second test duration

Performance Screenshots

Performance metrics from K6 dashboard during stress testing: Performance Metrics

Docker container stats during peak load (1000VUs): Docker Stats

Key Features

  • High Performance Cache: Redis caching layer to minimize database hits and reduce latency
  • Rate Limiting: Using Nginx to protect against abuse and block spam requests
  • Dockerized Deployment: Containerized architecture for easy deployment and scalability
  • CI/CD Pipeline: Automated testing and deployment using GitHub Actions
  • Security: Use third-party services Cloudflare for DDoS protection and Turnstile for bot protection
  • Base62 Encoding: Compact and user-friendly short URLs using Base62 algorithm
  • PostgreSQL Database: Reliable data persistence with connection pooling
  • Horizontal Scalability: Stateless architecture allows easy scaling with load balancers

Usage

Creating Short URLs

  1. Navigate to /s0/create/
  2. Complete the Cloudflare Turnstile verification
  3. Enter your long URL
  4. Receive your shortened URL

Accessing Short URLs

Simply visit /<short_code> to be redirected to the original URL. The system automatically:

  • Checks Redis cache first (cache hit = <10ms response)
  • Falls back to PostgreSQL if cache miss
  • Updates cache for subsequent requests

API Endpoints

Endpoint Method Description
/s0/create/ GET/POST Create shortened URLs
/<short_code> GET Redirect to original URL
/s0/huyvoadmin GET Django admin panel

Conclusion

FastLink is a production-ready, high-performance URL shortener that demonstrates enterprise-level engineering practices and scalability. Built with modern technologies and battle-tested under extreme load conditions, this system proves that efficient architecture and intelligent caching can deliver exceptional results even on modest hardware.

Key Achievements

  • 🚀 Exceptional Performance: Sustained 1,200 req/s with P95 latency under 50ms
  • 💪 Rock-Solid Stability: Zero errors under 1,000 concurrent users during 60-second stress test
  • ⚡ Efficient Resource Usage: 60-70% CPU utilization with 30-40% headroom for traffic spikes
  • 🔒 Security First: Cloudflare DDoS protection and Turnstile bot verification
  • 📈 Scalable Architecture: Stateless design enables horizontal scaling on demand
  • 🎯 Production Proven: Tested on Azure Standard_F8s_v2 infrastructure

Future Enhancements

Potential improvements for even greater performance:

  • Custom domain support for branded short links
  • Analytics dashboard for click tracking and metrics
  • Rate limiting per user/IP for abuse prevention
  • Geographic load balancing for global deployments
  • Auto-scaling based on traffic patterns
  • Link expiration and scheduling features

Star this repository if you found it useful!

📧 Questions or feedback? Open an issue or reach out!

About

A cutting-edge URL shortener designed for speed and scalability. This project handles 1000+ concurrent users and sustains 30,000+ requests per minute with minimal latency.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors