**assuming 1 million DAU, 1:1 W/R ration, Peak QPS = 2 * QPS **
2 million pastes / day = 2*10^9 / 10^5 = 2*10^4
= 20,000 QPS (writes)
2 mill * 30 days = 60 million / month
**assuming 1KB file limit**
60 * 10^9 * 1KB = 60 * 10^12 = 60TB storage requirement / month
**assuming average of 5 paste reads / day**
5 million reads / day = 5 * 10^9 / 10^5 = 50,000 QPS
POST /api/v1/uploadText
content-type: application/json
args: body
ret: UUID
GET /api/v1/getText?uuid=UUID
content-type: plain/text
args: UUID
ret: uploaded text (browser will render into the page)
Database is a key value store where the key is unique to the paste and the value is the text stored at that link.
60TB storage requirement isn't out of the realm of possibility for a single machine, so single leader replication could be a good fit. 20,000QPS = 1KB * 2 * 10^4 = 20MB is almost too high for one write node but is theoretically possible on high-end servers. If we needed to scale we could use a weakly consistent sharding scheme, partitioned on user_id or even grographical location if user_id doesn't exist. we can use read replicas or hash indexes to speed up reads. LSM or B-tree based indexes would be a waste as we don't need to do range queries.
That being said let's choose a document based data base, the data won't benefit from relations. Also noSQL are easier to set up sharding when needed. Let's pick cassandra for it's feature rich offerings including a consistent hashing type algorithm to distribute load evenly among commodity hardware (through the use of virtual nodes and other methods) this provides support for heterogeneity which reduces costs and mitigates the hot shard / celebrity problem.
Write:
We need to allow the customer to upload their content. Besides uploading the file using HTTP, we also need a unique identifier to serve as the key. There are multiple ways of going about this: we can use a hash function + linear probing or buckets for collisions, unsuring uniqueness of the keys. We can also use the snowflake UUID method, where we combine information about the request to form a composite key of sorts which together uniquely identify any paste. This often includes an offset to a predetermined start time (since we are only storing for 30 days this can be T-30 days), as well as either the user_id or perhaps a checksum / hash of the content. If we use the hash of the content we can stop users from duplicating texts which would be good.
Read:
Mostly just checks if the content is caches, returns it if so, checks if the UUID is present in the DB, returns the value or an error.
Write:
Read:
Above
Above
Above
Above