System will provide 2 APIs. One endpoint to receive the text to be stored, and a second endpoint to receive a code and return the text.
Backend is decoupled from front-end developed as RESTful API.
# Save text endpoint
POST /text {text: "my-text"}
Response:
HTTP Status Code: 201
Payload: {url: "https://my-pastebin.com/:unique-code", expires_at: "timestamp"}
# Get text endpoint
GET /text/:code
Response:
HTTP Status Code: 200
Payload: {text: "my-text"}
Store data on postgres with replicaset. Setup connection pool on app connections.
texts table:
Save text endpoints generates a unique code to build the URL to be returned to client. Code must be unique, that's why we use a global Redis counter incremented for every new data stored. The code is a base62 hash based on the counter+current timestamp, used as key on redis mapping to the text, with a TTL of 1 hour. On database we define a bigger expiration time of 1 month.
Client uses the returned URL with the unique code. Lookup on redis with the code and fallback on database excluding data by expired_at column.
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.