SnapURL is a scalable, modular, and containerized microservice-based URL shortening system similar to Bit.ly or TinyURL. It provides a simple and efficient way to shorten long URLs and redirect to the original link using FastAPI and Docker.
- 🔗 Shorten Long URLs using a base62 algorithm
- ↪️ Redirection Service for resolving shortened URLs
- 🗃️ Persistent Storage via Redis
- 🧱 Microservice Architecture with Docker Compose
- 🌐 API Gateway for unified access
- 💡 Health Check Endpoints for all services
- ⚙️ Pluggable Slug Strategy (Base62, Random, Hash, etc.)
SnapURL/
├── api-gateway/ # API Gateway that forwards requests to services
│ └── main.py
│
├── shortener/ # Microservice to generate short codes
│ ├── main.py
│ ├── service/
│ │ └── shortner_service.py
│ └── strategies/
│ ├── base.py
│ └── base62.py
│
├── redirector/ # Microservice to redirect shortened codes
│ └── main.py
│
├── url-storage/ # Microservice to interact with Redis for storing links
│ └── main.py
│
├── docker-compose.yml # Docker setup for all services
└── README.md # Project documentation
- Python 3.11
- FastAPI
- Redis
- Docker + Docker Compose
- HTTPX for service communication
All microservices are isolated in their own containers and communicate via Docker's internal DNS.
-
User hits
/shorten?url=<long-url>
via API Gateway -
API Gateway forwards it to
shortener
service -
shortener
generates a slug and callsurl-storage
to persist the mapping -
The shortened code is returned to the user
-
When user visits
/R3v1ON
, API Gateway routes it toredirector
-
redirector
fetches the original URL fromurl-storage
and redirects
+----------------+
| Client |
+--------+-------+
|
▼
+------------+------------+
| API Gateway |
+------------+------------+
|
+-----------------------------+-----------------------------+
| |
▼ ▼
+-------------------+ +----------------------+
| Shortener Svc | ----> Generates slug | Redirector Svc |
+-------------------+ +----------------------+
| |
| Store slug:url in Redis |
▼ ▼
+--------------------------+ +--------------------------+
| URL Storage Svc | <-- GET/POST --> Redis | URL Storage Svc |
+--------------------------+ +--------------------------+

Prerequisites
- Docker
- Docker Compose
Run All Services
docker compose up --build
Then open:
API Gateway: http://localhost:8001
🔌 Example Usage 🔸 Shorten a URL
curl -X POST "http://localhost:8001/shorten?url=https://github.com"
🔹 Redirect
curl -I http://localhost:8001/{short_code_of_above_link}
❤️ Credits Developed by Santosh Varma Addala
📜 License This project is licensed under the MIT License.