Fundamentals · Beginner

Pastebin

Immutable text snippets under random short keys, served mostly from a CDN.

Every part, and why it is there

Users

People pasting text and, far more often, people opening a shared link. Reads outnumber writes roughly 10 to 1, which shapes everything else.

CDN

A paste never changes once written, so it can be cached at the edge for a long time. Popular links are served without touching your servers at all.

Load balancer

Spreads new-paste requests over the write servers and removes unhealthy ones. Writes bypass the CDN because they must reach the origin.

Write API

Takes the text, gets a fresh key, stores the body and the metadata, and returns the short URL. Kept separate from reads so a read surge cannot slow down creating pastes.

Read API

Handles CDN misses: looks up the key, checks it has not expired, and returns the text. Scales independently of writes because it does most of the work.

Key generator

Hands out unused short keys (e.g. 7 base62 characters ≈ 3.5 trillion values). Pre-generating keys avoids checking for collisions on every write.

Unused key pool

A batch of keys generated ahead of time. Each key generator instance claims a block of them, so two writers can never be handed the same key.

Paste bodies

The text itself can be up to a few megabytes, which is cheap to keep in object storage and awkward to keep in database rows. The database stores only a pointer.

Paste metadata

Key, owner, created time, expiry and the object-storage path. Small rows, so a single database with read replicas goes a long way.

Hot pastes

Catches the reads the CDN misses for very popular pastes. A cache-aside lookup saves a database and object-storage round trip.

Expiry cleaner

Runs periodically to delete pastes past their expiry date. Reads also check expiry, so a paste disappears on time even if cleanup runs late.

Asked in interviews at

  • nvidia
  • servicetitan

Learn more

All system design examples