guest@portfolio:~/projects/short-url$ topology

CASE STUDY / 02DISTRIBUTED DATA

ShortURL

A distributed redirect service that separates request routing, atomic identifier generation, durable URL mappings, and usage analytics.

  • FastAPI
  • NGINX
  • Redis
  • MongoDB
write-read-path.live requests flowing
ShortURL distributed service topology Clients enter through NGINX and reach stateless FastAPI instances. Redis generates unique identifiers, MongoDB persists URL mappings, and redirect events feed analytics. REQUESTClientPOST / resolve EDGE / 01NGINXload balancing INSTANCE / AFastAPI INSTANCE / BFastAPI ATOMIC IDRedis INCRdistributed lock DURABLE MAPMongoDBcode → URL OBSERVEAnalytics
stateless routingatomic identifiersdurable mappings
← Back to Portfolio

ShortURL - Live Demo

A distributed URL shortening service built with Python, Redis, MongoDB, and NGINX. Experience the power of scalable URL shortening with real-time monitoring.

High Performance
🔒 Secure & Reliable
📊 Real-time Analytics
🚀 Scalable Architecture

Need this service for your use case or want a tailored solution?

Try It Out

shorturl.api / v1

Service standby

POST
Generated short URL

Analytics

analytics.api / v1 GET

Inspect redirect activity and lifecycle data for one shortened URL.

Accepts a short code or a complete ShortURL link.

Implementation

Routing, identifier generation, durable mappings, and observability are separated so each concern can evolve independently.

Core Technologies

Backend

  • • Python 3.9+
  • • FastAPI (Async Framework)
  • • Squid Hashing Library
  • • Pydantic (Data Validation)

Data Storage

  • • Redis (ID Generation)
  • • MongoDB (URL Mapping)
  • • Distributed Locking

Infrastructure

  • • NGINX (Load Balancer)
  • • Docker & Docker Compose
  • • GCP Cloud Run
  • • Kubernetes Ready

Monitoring

  • • Prometheus (Metrics)
  • • Grafana (Dashboards)
  • • Health Check Endpoints
Python

Python FastAPI

High-performance async API server handling URL shortening requests with Squid hashing algorithm

FastAPI

FastAPI

Modern, fast web framework for building APIs with automatic OpenAPI documentation

Redis

Redis

In-memory database using INCR for unique ID generation and distributed locking for thread safety

MongoDB

MongoDB

Persistent storage for mapping short codes to original URLs with high availability

NGINX

NGINX

Load balancer distributing incoming requests across multiple application instances

Prometheus

Prometheus

Metrics collection and monitoring system tracking application performance

Grafana

Grafana

Visualization dashboard providing real-time insights into system metrics

Request Flow

01
Client

Client Request

User submits a long URL through the web interface or API

02
NGINX

NGINX Load Balancer

Request is distributed to one of the available application instances for optimal load distribution

03
Redis

Redis ID Generation

Application uses Redis INCR to generate a unique sequential ID with distributed locking for thread safety

04
Python

Squid Hashing

Python's Squid library converts the ID to a short, URL-safe hash code

05
MongoDB

MongoDB Storage

Short code and original URL mapping is persisted in MongoDB for future lookups

06
Prometheus

Response & Monitoring

Short URL is returned to the client while Prometheus collects metrics for monitoring

Live Service

-
Total URLs Created
-
Total Redirects

Need This Service for Your Use Case?

This ShortURL service is built with enterprise-grade architecture and can handle millions of requests. If you need a similar URL shortening service for your business or want a tailored solution customized to your specific requirements, I'd love to help you build it.

API Reference

The public endpoint, request shape, and two minimal integration examples.

Open API documentation ↗

cURL Example

curl -X 'POST' \
  'https://shorturl.hansraj.me/v1/shorten' \
  -H 'accept: application/json' \
  -H 'content-type: application/json' \
  -H 'headers: {"x-user-data": {"role":"company", "user_name": "portfolio", "user_id": 0}, "role": "company"}' \
  -d '{
  "long_url": "https://www.example.com/very/long/url",
  "group_guid": "demo",
  "qr_code": true,
  "custom_domain": ""
}'

JavaScript Example

const response = await fetch('https://shorturl.hansraj.me/v1/shorten', {
  method: 'POST',
  headers: {
    'accept': 'application/json',
    'content-type': 'application/json',
    'headers': JSON.stringify({
      'x-user-data': {
        'role': 'company',
        'user_name': 'portfolio',
        'user_id': 0
      },
      'role': 'company'
    })
  },
  body: JSON.stringify({
    long_url: 'https://www.example.com/very/long/url',
    group_guid: 'demo',
    qr_code: true,
    custom_domain: ''
  })
});

const data = await response.json();
console.log('Short URL:', data.short_url);

Capabilities

Generate Short URLs

Custom Domain Support

QR Code Generation

Distributed Locking

Health Check Endpoints

Monitoring via Prometheus

Dashboard with Grafana

Load Balanced via NGINX