A scalable, ready-to-deploy URL shortener service built using Go. This project is designed to offer an easy-to-set-up URL shortening service with analytics infrastructure. It leverages Docker, PostgreSQL, ClickHouse, MongoDB, and Redis to ensure a robust and scalable system.
- Shorten URLs: Generate unique and short aliases for URLs.
- Analytics: View analytics and metrics via Metabase dashboards.
- Scalable Architecture: Designed to scale horizontally to handle increased load.
- Docker Compose Setup: Easy setup and deployment using Docker Compose.
This project follows a monorepo structure containing two main services:
-
URL-Shortener Service:
- Saves aliases to storage and cache (for the first 24 hours).
- Retrieves the full URL based on the alias and redirects to it.
-
Alias-Gen Service:
- Uses a counter-based approach to generate aliases for full URLs.
- Employs PostgreSQL to maintain the counter value.
-
Create Alias:
POST /url
- Example Request Body:
{"url": "https://github.com/"}
- Example Response:
{'status': 'OK', 'alias': 'alias'}
-
Redirect to Full URL:
GET /{alias}
- Redirects to the corresponding full URL.
-
Delete Alias:
DELETE /{alias}
- Response:
HTTP 200 OK
on success,HTTP 200 OK
witherror
message in response if the alias doesn't exist. - Removes the full URL and alias from the storages.
- Docker and Docker Compose installed on your machine.
- Set up Cloud MongoDB and update its URI in the config file
services/main/config/production.yaml
.
- Clone the repository:
git clone https://github.com/raisultan/url-shortener.git
- Navigate to the project directory:
cd url-shortener
- Build and run the Docker Compose setup:
docker-compose up --build -d
- Set up Metabase on
localhost:3000
with the following credentials to create dashboards and monitor metrics:- Host:
clickhouse
- Port:
8123
- Username:
default
- Password: (leave empty)
- Host:
- Access the URL shortener service at http://localhost:8080.
- For analytics and metrics dashboards, access Metabase at http://localhost:3000.
- The service tracks
clicks
, which include information like:- Redirect Timestamp
- Alias
- User IP address
- User Agent
- Referrer
- Latency of Redirect
- Error If Exists
- The service tracks
Follow the steps in the Local Development Setup document to set up the project for local development.
Contributions are welcome! Here's how you can contribute:
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request