URL shortener backend built in Go with a PostgreSQL backend and Redis for caching
Example deployment with a simple frontend available at personal.davidenberg.fi/url-shortener
- Cache-Aside Pattern for managing data caching between Redis and PostgreSQL
- Async Analytics via Goroutines to offload analytics tracking from request handling
- Docker-compose for setting up entire stack
- Backend: Go (Standard library + pgx PostgreSQL driver and Go-Redis)
- Database: PostgreSQL + Redis
- Orchestration Docker, Docker Compose
- Clone the repository
git clone https://github.com/davidenberg/URL-shortener.git- Build and run the stack
docker compose up --buildPOST /urls
Generates a unique 8-character identifier for the URL
Request body:
{
"original_url": "https://www.google.com"
}Success response:
{
"short_url": "<domain>/urls/:identifier"
}GET /urls/:identifier
Success Response: 302 Found
Get /urls/stats/:identifier
{
"creation_time": Timestamp,
"hits": <Number of hits>
}