This project provides a URL shortening service that converts long URLs into shorter ones.
- Users submit a long URL to receive a shortened URL.
- Users can use the shortened URL to redirect to the original URL.
- URL Shortening : Users submit a long URL to receive a shortened URL.
- URL Redirection : Users can use the shortened URL to be redirected to the original URL.
- High Scalability: Load balancer, DB replication, Redis cluster.
- High Availability: Load balancer, Auto scaling, DB replication, Redis cluster, Health check
- Low Latency: Hybrid cache, DB replication, Message Queue
- Uniqueness Guarantee: Base58, ID Generator
- Java 21
- Kotlin 1.9.25
- Spring Boot 3.4.1
- PostgreSQL 17
- Redis 8
- Caffeine
- Docker
- JUnit 5
Run using Docker:
make run
URL shortening API to shorten a long URL
POST /api/v1/shorten
Request Body:
{
"longUrl": "https://example.com/long-url",
"userId": 1
}
Response:
Status: 201
Status:
201
Create: Successfully created a shortened URL.400
Bad Request: Invalid URL input.
API for redirecting to the original URL with the shortened URL
GET /{hash}
Response:
HTTP/1.1 301 Moved Permanently
Location: "https://example.com/long-url"
Find the shorten and original URLs that user have
GET /api/v1/users/{userId}/urls
Response:
[
{
"id": 1,
"longUrl": "http://amazon.com",
"shortUrl": "http://localhost:8080/3gXe",
"hash": "3gXe",
"userId": 1,
"createdAt": "2025-01-06T00:14:12.429006",
"updatedAt": "2025-01-06T00:14:12.429006"
},
]
URL Table
Field Name | Type | Description |
---|---|---|
id | SERIAL | Primary key |
long_url | VARCHAR | Original URL |
short_url | VARCHAR | Shortened URL |
hash | VARCHAR | Hash for short URL |
userId | BIGINT | User Identity |
createdAt | TIMESTAMP | Creation date time |
updatedAt | TIMESTAMP | Modification date time |
Run tests using JUnit 5:
make test
High-level design of current architecture
High-level design of future architecture
- Response Code
- Unique URL
- Database
- Cache
- ID Generator
- Message Queue
- Rate Limiter
- Asynchronous, Non-Blocking
Test Machine Specifications
- Processor: Apple M3 Pro
- Cores: 11 cores
- Memory: 36GB
Load Test APIs
- URL Shortening API: generate a shortened version of a provided URL
- Short URL resolution API: resolves a shortened URL and redirect the user to the origin URL