Requirements
Functional Requirements:
- Create a short URL for a given long URL.
- Return the long URL associated with a given short URL.
Non-Functional Requirements:
- List the key non-functional requirements (eg low latency, scalability, reliability, etc.)...
API Design
GET domain.io/link/{uuid}
Request Body: None
HTTP Response: 301 to actual URL
Response Body: None
POST domain.io/link - Creates a unique link
Request Body: { "url": "url to create a short link for" }
HTTP Headers may or may not contain a JWT.
HTTP Response: 200
ResponseBody: { "link": "domain.io/link/{uuid}"}
Update domain.io/link/{uuid} - Updates an link origin URL
Headers require a valid JWT
Request Body: None
HTTP Response: 200
ResponseBody: { "link": "domain.io/link/{uuid}"}
Delete domain.io/link/{uuid} - Deletes an link origin URL
Headers require a valid JWT
Request Body: None
HTTP Response: 200
ResponseBody: { "link": "domain.io/link/{uuid}"}
We will also have correct error codes for malformed requests. Update and delete APIs will only be useable if the user creating the link was auth'd into the platform.
High-Level Design
Frontend can be whatever library we choose. Asynchronous API calls will be made to the backend server. This server will store the creators, original links, and the short links in the database.
This design will take a standard CRUD approach where by the read / GET API will just return a 301 redirect to the actual full link. For create, anyone can create a link however, if they would like to delete this link or update it in the future they need to be logged into the platform. If a user is auth'd, the user ID as the creator of the link will be stored in the database and associated with the link itself. Any future requests to delete/update the link will check the calling user against the creator and either complete the request or deny it.
Detailed Component Design
GET domain.io/link/{uuid}
When the server gets this request, it will not check auth, it will immediately query the database for the corresponding uuid. Should a match be found in the database the server will respond immediately with a 301 for the original link.
POST domain.io/link - Creates a unique link
When creating a link, auth will be checked. An original URL is expected on the request body. When the request is received, a UUID will be created. The UUID, creating user (if one logged in exists), and the original link will all be stored in the database. Using a UUID will help to ensure scalability as there wont be collisions.