A scalable, high-performance URL shortener backend API built with modern technologies. This system is designed for low-latency redirects, real-time analytics, and resilience under heavy load, leveraging Redis for caching and MongoDB for flexible data storage.
./run_all.shThis starts 3 FastAPI instances to simulate a load-balanced backend.
./run_stress_test.shOr manually:
locust -f app/locustfile.py \
--headless \
-u 2000 \
-r 500 \
--run-time 3m \
--csv=results/loadtest \
--host=http://localhostOutputs will be saved in results/:
loadtest_stats.csvloadtest_failures.csvloadtest_stats_history.csv
pytest tests/- FastAPI – high-speed async web server
- MongoDB – stores long-to-short URL mappings
- Redis – caches hot URL entries and tracks view counts
- Locust – load testing framework for HTTP users
- Uvicorn – ASGI server with multiple workers
- Pytest – test framework for backend APIs
| Method | Endpoint | Description |
|---|---|---|
| POST | /shorten |
Shorten a long URL |
| GET | /{short_id} |
Retrieve the original long URL |
| GET | /analytics/{short_id} |
View access stats for a short URL |
- User authentication and rate limiting
- QR code generation
- Geo-based analytics
- Full deployment with Docker and reverse proxy
- Horizontal scaling with MongoDB + Redis clustering
