A production-ready URL shortening service built with Spring Boot (Kotlin) that converts long URLs into short, shareable links.
- URL Shortening: Convert long URLs to short url
- Redirection: 301 redirects from short URLs to original destinations
- Metadata Lookup: get original URL without redirection
- Duplicate Handling: Returns existing short URL if URL was previously shortened
- Race Condition Protection: Handles concurrent requests gracefully
- Distributed ID Generation: Uses Sonyflake for unique ID generation
- Base62 Encoding: Generates compact, human-friendly short codes
- Caching: Improves performance for frequently accessed URLs
- Backend: Spring Boot (Kotlin)
- Database: JPA/Hibernate (mysql used)
- Cache: Spring Cache abstraction
- ID Generation: Sonyflake
- Encoding: Base62 for short code generation
- UrlValidation: Apache Commons Validator
- API Docs: OpenAPI(Swagger)
POST /api/v1/urls
Content-Type: application/json
{
"longUrl": "https://example.com/very/long/url"
}
Response:
json
{
"shortKey": "abc123",
"shortUrl": "https://domain/abc123"
}
http
GET /{shortKey}
Returns 301 redirect to original URL
GET /{shortKey}/meta
Response:
json
{
"originalUrl": "https://example.com/very/long/url"
}- install docker
- navigate to project root then run:
docker compose up --build
- navigate to:
http://localhost:8080/swagger-ui.html
- connect to MYSQL database and update DB connection in application properties
- this project uses java 17, make sure it's installed
- run :
./gradlew bootRun
./gradlew test
- to configure the short url domain, go to application.properties and change:
app.domain= <Your Domain>
- add Redis to cache frequently requested Urls
- Rate Limiting