Skip to content
SD-3 · Back to the write-up

Design a Pastebin

Keep a small row per paste, put the text in object storage, and let a CDN serve reads, since a paste never changes.

Follow a request

Clients
Edge
Services
Data
UserBrowser or CLI
CDNEdge copies
Load balancerSpreads traffic
App serversStateless, many
Abuse scannerAsync workers
Expiry sweeperBackground job
Object storagePaste text
Metadata DB8 shards by key
1user → cdn · GET /p/Ab3dE9xQA reader opens a paste this edge has not seen yet.1 / 7

The numbers, at a glance

For every paste saved……it is read about 10 times
1 write ≈ 116/s10 reads ≈ 1,160/s
Storage grows fast10M pastes a day × 10 KB
Metadata is tiny200 bytes of row per 10 KB of text
So the text goes to object storage, and the database keeps the rest.

A read, in order

CDN miss shown. On a hit, the edge answers and steps 2 to 9 disappear.

User
CDN
Load balancer
App server
Metadata DB
Object storage
1 GET /p/Ab3dE9xQ
2 forward
3 route
4 GET row (follower)
5 row, ready, not expired
6 GET object
7 text
8 200 + s-maxage
9 200
10 200 page
RequestResponseAsync, does not block

Where the paste text lives

The decision this question is really about.

In the database row
Too heavy
POST /pastes
INSERT key, 10 KB text
DB: 183 TB
+ One store, one write.− Huge rows slow every query; 183 TB of database disk.
Files on app servers
Breaks scaling
server Aserver B
Ab3d…txt on A only
read via B → 404
+ Fast local reads.− Each paste lives on one machine.
Object storage + row
Our pick
POST /pastes
PUT text → storageINSERT 200 B row
CDN caches the text
+ Cheap, durable, unlimited; small database.− Two writes: text first, then the row.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 100 reads/sMake it work
User
App server
SQL database
One server, text stored in database rows. Fine for a demo.
Stage 2 · ≈ 3,500 reads/sSplit out the text
User
Load balancer
App × N
Object storageMetadata DB
100 GB a day of text: move it to object storage, keep small rows.
Stage 3 · ≈ 200,000 reads/sServe the world
User
CDN
Load balancer
App × NExpiry sweeper
Object storageSharded metadata
Edge copies for 90% of reads, background cleanup, 8 metadata shards.
Stage 4 · 200,000 reads/s + abuseKeep it safe
User
CDN + rate limits
Load balancer
App × NExpiry sweeperAbuse scanner
Object storageSharded metadata
Rate limits at the edge, signed uploads for big pastes, a scanner off the write path.
Was this walkthrough useful?Your vote tells us what to improve next.