List functional requirements for the system (Ask the chat bot for hints if stuck.)...
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
Assume we have 1000 initial users, and an average user would create 3 pastes per day. That makes 3 * 1000 / 100000 = 0.03 write request / second in the initial month.
Everyday 3 * 1000 = 3000 pastes would be created initially, assuming each paste would be accessed 5 times in its lifetime, the read traffic could be estimated as 3000 * 5 / 100000 = 0.15 read request / second.
Initially, the traffic is very small, however, we should assume the number of users would grow gradually at 10% per month. The read / write traffic should grow linearly according to this.
Assume each text and its metadata would take 1KB in storage, the highest storage we need initially would be 3000 * 30 * 1KB = 90MB
Again the storage needed initially is small, but as the number of customers grow over time, we will need greater storage.
Define what APIs are expected from the system...
storeText API:
request: customerId (string), textToStore (string)
response: uriOfText
fetchText API:
request: uriOfText
response: text (string)
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
Table: Text
Id (varchar): id of text
ownerId (varchar): customerId of the creator of the text.
textToStore (varchar): the text to store
uri: uriOfText
insertTime (DateTime)
expireTime (DateTime)
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
The system should consist of a client, a server, a database to serve the basic requests. In order to remove the expired texts from the database, there should be a seperate cronjob that is executed daily.
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...
The Client should issue a storeText API call on behave of a customer. This API call contains the customerId of the owner and the actual text to store.
The server should then calculate the expiry time of the text based on the current date, as well as generate a uri to fetch this text. The server then inserts all these information as a new record in the database.
After database insertion succeeded, the server should then returns the uri to fetch the text to the client.
The client should issue a fetchText API call to the server. The server then use this uri to query database to get the text. After the text is retrieved, it returns the text to the client.
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...
In the design of random url generators, we choose to generate the url completely randomly. There are to other way to do this.
Try to discuss as many failure scenarios/bottlenecks as possible.
If one of the servers fails, the clients could call other servers and get their requests served.
If one of the databases replication fails, and it is a slave machine, the other slaves machine can come in and serve the requests.
If the master database replication fails, one of the slaves can be elected as the master.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?
As mentioned above, since there will be more and more users joining the platform, database sharding should be introduced.