Single entry:
Total: 132 bytes, rounding to 144 bytes.
Create RPS: 200 req/sec => 2.5GB/day
Storage per day: 2.5GB
Storage per year: 1TB
Network bandwidth:
Create: 28kb/s
Read: 2.8Mb/s
There is bandwidth for HTTP requests and DB queries, hence doubling:
Create 56kb/s, Read: 6MB/s
If peak load doubles, total bandwidth is ~13MB/s
POST `/v1/users`
Body:
{
"first_name": string,
"last_name": string,
"email": string
}
Response:
201 Created
{
"first_name": string,
"last_name": string,
"email": string,
"id": string
}
POST `/v1/links`
Accepts a body with url, user_id, and optional custom_short_url to create a new short link.
Body:
{
"url": string,
"user_id": string,
"custom_short_url": string,
"expiration": UNIX timestamp
}
"url": string, starting with `http://` or `https://`, with max length 512 bytes.
"user_id": alpanumerical user ID
"custom_short_url": custom link ID - 8 chars. If custom_short_url is not provided, ID is generated automatically.
Response:
201 Created
{
"id": ID,
"short_url": SHORT_URL,
"long_url": LONG_URL,
"user_id": USER_ID
}
400 Bad Request - for invalid URL (invalid scheme, missing domain, exceeding max length, etc).
409 Conflict - if provided `custom_short_url` is already used.
When a user attempts to generate a short URL for an already existing long URL, already existing short URL is returned.
GET `/v1/links/{ID}`
GET /v1/links/{ID}: Takes a short_url ID and returns the corresponding long URL with additional metadata, if applicable.
Response:
200 OK
{
"id": ID,
"short_url": SHORT_URL,
"long_url": LONG_URL
}
404 Not found
GET `/v1/users/
Allows fetching all links associated with a given user_id, with pagination support (e.g., limit and cursor).
Response:
[
{
"id": ID,
"short_url": SHORT_URL,
"long_url": LONG_URL
},
...
]
short_url in URL_MAPPING for quick retrieval by short URLuser_id in URL_MAPPINGfor quick retrieval of links by user ID.Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?