DB:
Assuming the Size of text on average =50kb per paste
Assuming 100,000 pastes per day * 50 kb =5GB per day of storage
5GB *365 = 1.825TB of storage for text files in our data base.
Traffic:
Writes:
(100,000/(24*360))=1.16 pastes per second
1.16* 50 kb, roughly 60 kb per second for writes.
Reads:
Assuming 1:1000 read to write ratio:
60 kb*1000= 60 MB
Cache:
1.825TB * 0.2= 256 gb
We will use REST API's
Since we assume the pastes are anonymous we don't need a users table. We will have one table for pastes as such:
Paste Info Table
Paste Table: (Key value store such as S3)
Since this is a heavy read operation we will use single leader replication. To address concurrency
We will repopulate the table with paste_key and paste_url. This will be created using MD5 hashing. We can take the first eight values of the hash as paste_key and the second 8 as paste_url. In concurrent writes, each write can grab a lock for each index, ensuring its thread is safe. We will not be creating the hash values upon write but prepopulating them.
To address deadlocks the locks will only lock the primary index which also serves as the paste_key and then move to paste_url so there is a lock_ordering. We can also add timeouts
To address expired rows we have created an index on the created_at field and can run a job every given period to detect old rows.
We will use file storage such as Amazon S3 for the paste themselves. The paste_key will serve as the key to the content of the paste. We are confident that we can horizontally scale a S3 service if needed.
To address latency between the leader node and follower nodes, we can use a quorum strategy to address the delay between followers not being updated.
Scalability and fault general tolerance:
Caching:
Writes:
Reads:
Same as above high level design
Same as above