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
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.
Need this service for your use case or want a tailored solution?
Try It Out
Service standby
POSTAnalytics
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 FastAPI
High-performance async API server handling URL shortening requests with Squid hashing algorithm
FastAPI
Modern, fast web framework for building APIs with automatic OpenAPI documentation
Redis
In-memory database using INCR for unique ID generation and distributed locking for thread safety
MongoDB
Persistent storage for mapping short codes to original URLs with high availability
NGINX
Load balancer distributing incoming requests across multiple application instances
Prometheus
Metrics collection and monitoring system tracking application performance
Grafana
Visualization dashboard providing real-time insights into system metrics
Request Flow
Client Request
User submits a long URL through the web interface or API
NGINX Load Balancer
Request is distributed to one of the available application instances for optimal load distribution
Redis ID Generation
Application uses Redis INCR to generate a unique sequential ID with distributed locking for thread safety
Squid Hashing
Python's Squid library converts the ID to a short, URL-safe hash code
MongoDB Storage
Short code and original URL mapping is persisted in MongoDB for future lookups
Response & Monitoring
Short URL is returned to the client while Prometheus collects metrics for monitoring
Live Service
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.
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