A production-style URL shortening service inspired by systems like Bitly. Built to demonstrate backend system design concepts such as caching, rate limiting, and id generation.
- Shorten long URLs → compact Base62 codes
- Redirect using short links
- PostgreSQL persistence (existing schema integration)
- Redis caching with TTL (cache-aside pattern)
- Rate limiting (Token Bucket algorithm via Bucket4j)
- URL validation and normalization
- Idempotent API (same URL → same short code)
- Click tracking (analytics)
- Swagger API documentation
- Unit + Controller + Integration tests
Client → API → Redis (cache) → PostgreSQL (source of truth)
- Cache-aside pattern for fast reads
- Database fallback on cache miss
- TTL ensures memory efficiency
- Java + Spring Boot
- PostgreSQL
- Redis
- Bucket4j (rate limiting)
- JPA / Hibernate
- Swagger (OpenAPI)
- JUnit + Mockito
POST /api/shorten
Request: { "url": "https://google.com" }
Response: { "shortUrl": "http://localhost:8080/abc123" }
GET /{code}
- 302 → Redirect to original URL
- 404 → Not found
- Cache-aside pattern
- Id generation (Base62 encoding)
- Rate limiting (token bucket)
- Idempotent APIs
- Clean architecture (Controller → Service → Repository)
- Environment-based configuration (no secrets in repo)
- Set environment variables:
DB_URL=... DB_USER=... DB_PASSWORD=... REDIS_URL=...
- Run app:
mvn spring-boot:run
- Open Swagger:
http://localhost:8080/swagger-ui/index.html
- Distributed ID generation (Snowflake)
- Redis-based distributed rate limiting
- Docker + CI/CD
- Custom aliases for URLs
- Monitoring & logging