Design and implement a RESTful API for a URL shortening service, similar to Bitly, with a focus on scalability and analytics. The core functionality requires three main endpoints. The first accepts a POST request to create a short link, expecting a JSON body with the original URL and optional fields for a custom alphanumeric alias and an expiration date; this endpoint must generate a unique six to eight character code, validate that any provided alias is not already in use, and return the full shortened URL. The second endpoint handles GET requests with the short code as a path parameter, performing a permanent HTTP redirect to the original URL only if the link has not expired. The third endpoint retrieves statistics for a given code, returning metadata such as creation date, expiration, total click count, and the last access time.
From a technical standpoint, you must persist data using a relational or NoSQL database with a clear schema and provide migration scripts. A caching layer, such as Redis or an in-memory store, is required for the redirect endpoint to minimize database load and ensure high throughput, as this operation will receive the majority of traffic. You need to implement rigorous input validation, structured JSON error responses with appropriate HTTP status codes, and ensure that code generation and alias assignment are thread-safe to prevent race conditions during concurrent requests.
Optional but impressive additions include implementing rate limiting on the creation endpoint, offloading click count updates to an asynchronous background queue to avoid slowing down redirects, containerizing the application with Docker and Compose, and providing an OpenAPI specification. Your submission will be evaluated on code modularity, separation of concerns, production-ready logging and configuration management, database indexing strategies, and unit as well as integration test coverage. Please share your code via a public repository and include a detailed README with setup instructions, key architectural decisions, and curl examples for testing the API. We recommend limiting your time on this assignment to approximately four to six hours, focusing on quality and documenting any tradeoffs or unfinished improvements.

A great freelancer, quickly responded and was really fast at performing the task in high quality! Recommend him definitely
Post the same Task