Design a Pastebin service
easy 45 minStore a piece of text, hand back a short link, and delete the text on time.
See it run
Every flow, one hop at a time: create, read, make keys, filter through caches, sweep, and choose a home for the text.
Operations
Create a paste
A 40 KB paste: checked, stored as an object, recorded, and then worked on in the background.
Step 1 of 15
The client sends text
size
40 KB
visibility
unlisted
expiry
1 day
With optional title, language, expiry, visibility and password.
Step 1: The client sends text
def create(req): limiter.check(req.client) # 429 if over check(1 <= len(req.content) <= 10 * MB) # 400 or 413 key = random_key(8 if req.public else 12) packed = gzip(req.content) path = None if len(req.content) > 8 * KB: path = f"content/{key[:2]}/{key}" objects.put(path, packed) # object first db.insert_if_free(key, path, packed if not path else None) queue.send("scan", key); queue.send("highlight", key) return 201, key, new_delete_key(key)- Latency
- p99 < 500 ms
- Load
- 12/s
- Peak (3x)
- 35/s
- Anonymous limit
- 10 a minute
The paste exists from the moment the row is committed. Everything after that may fail and be repeated.
In the real world
The same paste service doing real jobs. Pick one and step through it.
Both press the button in the same second.
Step 1 of 4
Both see a button
GET reveals nothing, so a chat preview is harmless.
Step 1: Both see a button
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Serving until the sweeper comes
criticalThe paste lives minutes or hours past its time.
Wrongrow = db.get(key)return row.textRightrow = db.get(key)if row.deleted or now() >= row.expires_at: return 410Burning on GET
criticalA link preview opens it first and the person finds nothing.
WrongGET /KEY # shows the text and deletes itRightGET /KEY # shows a buttonPOST /KEY/reveal # one conditional updateRow before object
majorA crash leaves a link with no text.
Wrongdb.insert(key, path)objects.put(path, text)Rightobjects.put(path, text)db.insert(key, path)private and a CDN hit
majorprivateforbids shared caches from storing it.Wrong# public pasteCache-Control: private, max-age=300Right# public pasteCache-Control: public, max-age=60, s-maxage=300One lifecycle rule for all
criticalPastes that should live for ever disappear after 90 days.
Wrongexpire everything after 90 daysRightexpire prefix exp/ after 90 dayskeep prefix keep/The password in the address
majorAddresses are written to logs and histories.
WrongGET /v1/pastes/KEY?password=...RightPOST /v1/pastes/KEY/unlock{ "password": "..." }
Interview tips
Start simple
- One server and one database, said with numbers.
- 1M pastes, 10 KB, 12 writes a second.
- Then storage, cache, edge, front door.
Clarify early
- Largest size? Default expiry?
- Public, unlisted or private?
- May the server read the text?
Talk about trade-offs
- Object storage adds delay and requests.
- Caches add copies to delete.
- Longer keys add characters.
Mention safety
- Escape, second domain, nosniff.
- Limits, scan, report, takedown.
- Passwords hashed with Argon2id.