The URL Shortener is a system designed to create shortened versions of long URLs, facilitating easy sharing and reducing the likelihood of mistyped links. When users access these shortened URLs, they are seamlessly redirected to the original, longer URLs.
- URL Shortening: Generate unique, shortened aliases for long URLs.
- Redirection: Redirect users from the shortened URL to the original URL.
- Link Expiry: Set default expiration times for links to ensure they are temporary.
- High Availability: Ensure the service is consistently available with minimal latency.
- Scalability: Efficiently handle increasing numbers of users and requests.
- Security: Maintain a secure environment for both users and data.
- Analytics: Record and analyze metrics for each redirection to monitor usage patterns.
The system employs a microservices architecture, dividing the application into smaller, manageable services to enhance availability and fault tolerance:
- UserService: An ASP.NET Core v8 API responsible for user registration and authentication.
- URLService: An ASP.NET Core v8 API that handles URL shortening, analytics computation and provides access to shortened URLs.
- APIGateway: An ASP.NET Core v8 API serving as the central point of communication between the UI and backend services, managing authentication and routing.
- URL-Shortener: An Angular 19 Single Page Application (SPA) offering a user interface for login, signup, URL shortening, and viewing previously created URLs.
- URL-Shortener-Access: An Angular 19 SPA dedicated to accessing long URLs based on their shortened counterparts, handling redirection seamlessly.
- Route:
/Users/Register - Method:
POST - Request Body:
{ "FirstName": "Ravi", "LastName": "Makwana", "Email": "ravikumar.m@gmail.com", "PhoneNumber": "", "UserName": "URL", "Password": "URL@1234" } - Response Body:
{ "FirstName": "Ravi", "LastName": "Makwana", "Email": "ravikumar.m@gmail.com", "PhoneNumber": "", "Message": "User Created Successfully" } - Status Codes:
201 Created,400 Bad Request
- Route:
/Authenticate - Method:
POST - Request Body:
{ "UserName": "URL", "Password": "URL@1234" } - Response Body:
{ "AccessToken": "", "RefreshToken": "", "UserName": "URL", "FirstName": "Ravi", "LastName": "Makwana", "Email": "ravikumar.m@gmail.com", "PhoneNumber": "" } - Status Codes:
200 OK,401 Unauthorized
- Route:
/Authenticate/RefreshToken - Method:
POST - Request Body:
{ "RefreshToken": "" } - Response Body:
{ "AccessToken": "", "RefreshToken": "" } - Status Codes:
200 OK,400 Bad Request
- Route:
/URLs/Shorten - Method:
POST - Headers:
Authorization: Bearer {AccessToken} - Request Body:
{ "LongURL": "" } - Response Body:
{ "LongURL": "", "ShortenURLPath": "", "ExpiredOn": "" } - Status Codes:
201 Created,400 Bad Request
- Route:
/URLs - Method:
GET - Headers:
Authorization: Bearer {AccessToken} - Response Body:
[ { "LongURL": "", "ShortenURLPath": "", "ExpiredOn": "" } ] - Status Codes:
200 OK,401 Unauthorized
- Route:
/URLs/Access?shorten={shorten} - Method:
GET - Response: Redirects to the original long URL.
- Status Codes:
200 OK,404 Not Found
- Route:
/Analytics/{urlId} - Method:
GET - Headers:
Authorization: Bearer {AccessToken} - Response Body:
[ { "LongURL": "", "ShortenURLPath": "", "AccessedOn": "" } ] - Status Codes:
200 OK,401 Unauthorized
This system uses Base62 encoding to generate short URLs. The number of unique URLs depends on the length of the generated short URL.
| Short URL Length | Max Unique URLs (62^L) |
|---|---|
| 1 character | 62 |
| 2 characters | 3,844 |
| 3 characters | 238,328 |
| 4 characters | 14.7 million |
| 5 characters | 916 million |
| 6 characters | 56.8 billion |
| 7 characters | 3.52 trillion |
| 8 characters | 218 trillion |
Since this system starts URL generation from a minimum of 5 characters, it can generate at least 900+ million unique URLs before requiring longer short URLs.
- Structured Database: Microsoft SQL Server (MSSQL)
- User logs in via API Gateway.
- API Gateway sends an authentication request to
UserService. UserServicevalidates credentials and issues an access token.- API Gateway forwards the token to the user.
- The user application stores the token and uses it for subsequent requests.
- API Gateway verifies tokens and issues internal microservice JWT tokens.
URLServicevalidates the internal token and processes requests.
To ensure high availability and fault tolerance:
- Deploy multiple application instances.
- Use a suitable load balancer.
- Utilize Redis caching for performance improvements.
- Implement Azure Search for optimized search capabilities.

This system provides a robust, secure, and scalable solution for URL shortening.







