Create paste:
POST /{version}/paste
body: { text: str,
ttl: Optional[datetime]
}
response: { state: ENUM,
url_id: str
}
Get paste:
GET /version/paste/{url_id}
reponse: { status: ENUM,
paste_text: str
}
ID generation:
the id will be alphanumeric string with length = 8
using secure random algorithm
Data storage:
database used will be noSQL db (Key Value Database to be specific) as we just need to map each paste text (value) to the unique_url (id)
Gen UID Service:
For paste id, we will use secure random to generate alpha numeric string whose length equal to 8 (1/62^8 probability for collision). In case of collision happen we will random string again.
Data consistency:
as we will use multiple database instance for high availability, we will need to ensure that the data is sync between every instance. In this case, we will apply raft algorithm to manage multiple instance of database. We will elect one of the instance to be a leader which will handle all the write operation and the rest will become follower that will try to sync the data with the leader. In case of leader has become unhealthy, we will select number of follower as candidates of new leaders.
Paste expiration:
As we allow the user to set expiration condition for every paste we need efficient way to invalidate a balk of paste. For time condition we just need to map expiration_date with the id. If there is request after expiration timestamp we can easily know that this paste is invalid and delete it. In addition we can have the cron job that will periodically check if at the current time are there any paste that is expired if so we can delete them all for reducing storage cost.
Cache:
Scalability:
We will deploy stateless service on container orchestration service such as AWS ECS. In this case we can scale up/down our container on a whim. We can also set up condition for scaling such as when the request amount of certain service exceed our predefine value. They will add more instance to serve the upcoming load. Also we can adopt fault tolerant architecture by using spot instance to save the cost of infrasturcutre.