pastebin.com/abc123) the user can share.DAU - 5000000
Pastes per day - 1000000
Read to write ratio - 10:1
RPS(write) = 1000000 / 86400 = 12
RPS(read) = 120
Avg paste size = 10 KB
Storage per day = 1000000 * 10 = 10 GB/day
Storage over 5 year = 10 * 365 * 5 = 18 TB
Bandwidth = 120 * 10 KB = 1200
POST /pastes
{
"content": "...",
"expiration": "24h"
}
-> 201 Created
{
"key": "abc123",
"url": " https://pastebin.com/abc123",
"expire_at": "..."
}
GET /pastes/abc123
-> 200 Ok
{
"content": "...",
"created_at": "...",
}
-> 404 Not Found
{
"error": "Paste expired or does not exist"
}
CDN - the client sends a request to the CDN to find cacheable content
Load Balancer - if the required content is not cached, the request is sent to a load balancer to distribute the load.
API Gateway - accepts incoming requests from clients and redirects them to the required microservices
Create Service - service for creating new pastes
Read Service - service for working with client-supplied links to Pastes
Key Generation Service - service for generating unique hash keys for new pastes.
Redis - used as a cache for pastes
PostgreSQL - pastes metadata storage database
S3 - storage directly for pastes content
Expire Cleanup Service - service that tracks expiration dates and removes expired pastes.
PostgreSQL
S3
Key generation service. A separate service pre-generates random keys into a table with used/unused partitions and hands them out in blocks of, say, 1000 to each app server. Keys become an O(1) lookup instead of a computation, collisions are impossible by construction, and keys stay unguessable. The standby replica handles the KGS single-point-of-failure concern; losing a block of in-memory keys on a server crash is acceptable since the space is huge.
Radis holds hot pastes — roughly 20% of daily read volume covers most traffic under a typical 80/20 access distribution. That's about 2 GB/day of hot content, easily fits in memory across a few Redis nodes with LRU eviction. Popular public pastes can also sit behind a CDN, since paste content is immutable once written.
Expire Cleanup Service - two complementary mechanisms: