Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
The API will need read and write endpoints. For the write endpoints, we will need to find a way to make a create request, which we can use POST method. For the read paste, we can use the GET method. Upon deletion, we can use the DELETE method.
Create paste — POST /api/pastes Body: { "content": "...", "expiration": "1day"} Response: 201 Created + { "key": "aB3xY9", "url": "pastebin.com/aB3xY9" }
Read paste — GET/api/pastes/{key} Response: 200 with content, 404 if expired/not found
Delete paste — DELETE /api/pastes/{key} (requires owner token for anonymous users) Response: 204 No Content
There will be two flows. For the write flow, the user will submit a text, system will generate a key, stores that into the database and the system will return url. Let that service be called the URL generator application. For the read, the user will be able to look up the key from the database and fetch the text. Let that service be called text fetcher application.
In order to horizontally scale and to ensure that there is no single point of failure, we will add a load balancer between the client and the API gateway. The load balancer spread incoming traffic to multiple servers. We have assumed that there will be around 1M pastes a day and that the paste is 10KB. This means that 10GB/day, within a year this will be 36 TB/year. Wwe can have a relational database e.g. PostgreSQL for metadata. The actual text content can be stored in the object storage. Object storage scales to petabytes at cents/GB. This enables independent scaling and for managing the costs independently.
The database should be postgres.