Let people paste text, get a link, and share it. Like the URL shortener, but with big content to store.
“Design Pastebin.”
It is short on purpose. Your first job is to make it specific.
| What they check | Why it matters |
|---|---|
| Spotting the real difference from a URL shortener | The code part is the same. The twist is big content. A strong candidate says so early and splits small hot metadata from large blobs. |
| Storage reasoning | Where do the bytes live, in what format, how many copies, and what does that cost? Numbers and a clear choice, not ‘put it in a database’. |
| Lifecycle: expiry and deletion | Most pastes expire. Cleaning up billions of rows and blobs without scanning everything, and without half-deleted states, is the hard operational part. |
| Privacy and safety | ‘Unlisted’ is not ‘secret’. User text can contain scripts, passwords and illegal content. The interviewer wants to see you think about access control and abuse. |
| Read-path and failure thinking | A viral paste, a cache outage, a write that half-succeeds. Say what happens, and why the user does not lose data. |
A create request stores the text in object storage and a small record (code, owner, expiry, visibility, pointer) in a metadata store. A read looks up the record, checks status, expiry and access, and returns the text. Pastes never change, so they cache extremely well.
expires_at on every read, sweep expired pastes in the background by time bucket, and use object-store lifecycle rules as a backstop.| Step | Minutes | What to get done |
|---|---|---|
| 1. Clarify | 4 | Expiry, visibility, size limit, edit or not. Say what is out of scope. |
| 2. Estimate | 4 | Writes and reads per second, then bytes: per day, per 5 years, metadata vs content. |
| 3. API and data | 5 | Create, read, raw, delete. The metadata record with a pointer to the blob. |
| 4. High-level design | 7 | Metadata store, object store, cache, CDN. One write path, one read path. |
| 5. Deep dives | 15 | Where content lives, unguessable links and access, expiry at scale, safe fast reads. |
| 6. Scale and failures | 7 | Half-failed writes, viral paste, cache down, abuse, monitoring. |
| 7. Wrap up | 3 | Recap, trade-offs, what you would do next. |
| Ask | Why you ask it | Typical answer | How it changes the design |
|---|---|---|---|
| What do users store: text only, or also files and images? | Files change the problem (virus scanning, previews, much bigger sizes). | Text and code only. A maximum of 10 MB per paste. | Text compresses well and can be served as text. A hard size limit protects the system. |
| Do pastes expire? What choices do users get? | Expiry drives storage size and a whole cleanup subsystem. | Yes: 10 minutes, 1 day, 1 week, or never. Default 1 day for anonymous users. | A fixed set of expiry classes. Most data is short-lived, so cleanup is a core job, not an extra. |
| Who can see a paste: public, unlisted, private? | Decides access checks, caching rules and how long the code must be. | Public (anyone, may be listed), unlisted (anyone with the link), private (owner only, needs login). | Public can use the CDN. Unlisted needs an unguessable link. Private needs an auth check on every read and no shared caching. |
| Can people edit a paste after creating it? | Edits break caching and need versions. | No. A paste is immutable. To change it, make a new one. | Immutable content can be cached for a long time and is easy to replicate. Say this out loud, it simplifies a lot. |
| Can users pick a custom name, and do we need accounts? | Aliases need a uniqueness check. Accounts decide limits and ownership. | Optional custom alias for signed-in users. Anonymous creation is allowed with tight limits. | Conditional insert on the alias (as in the URL shortener). Owner field and per-user limits. |
| How many pastes a day, how big, and how many reads per paste? | The numbers decide whether the content or the request rate is the hard part. | 1 million new pastes a day, average 10 KB, about 10 reads per paste. | Tiny request rate, but about 10 GB of text a day. Storage is the main design question. |
| How durable must a paste be? | Losing a paste is losing user data. | Very durable. Availability of reads is important, but never losing data matters more. | Replicated metadata, erasure-coded blobs, and write order that cannot lose data silently. |
| Do we need syntax highlighting, search, or view counts? | Each adds services or write load. | Highlighting in the browser. Basic view counts, a little late is fine. No full-text search. | Highlighting costs the server nothing. Views go through a queue, not a counter on the paste row. |
| How long do we keep a paste that never expires? | Unbounded growth. | Forever, but we may move old data to cheaper storage. | Plan storage tiers and a growth budget. Content must be cheap per GB. |
| What about abuse and takedowns (spam, malware, leaked passwords, illegal content)? | Public paste sites are heavily abused, and the law may require removal. | Yes. Report button, automated scanning, and fast removal. | An async scanning pipeline, a block status, and a way to purge caches and the CDN quickly. |
| Assumption | Value |
|---|---|
| New pastes per day | 1 million |
| Average paste size | 10 KB of text |
| Read to write ratio | 10 : 1 |
| Peak traffic vs average | 3 times the average |
| Expiry mix of new pastes | 40% one day, 30% one week, 30% never |
| Metadata per paste (code, owner, dates, pointer) | about 300 bytes |
| Text compression (gzip or zstd) | about 3 times smaller |
| Retention | 5 years for pastes that never expire |
| Cache hit rate we aim for | 90% or better |
| One app server can handle | about 1,000 requests per second |
| What | Maths | Result |
|---|---|---|
| New pastes per second (average) | 1,000,000 ÷ 86,400 s | about 12 per second |
| New pastes per second (peak) | 12 × 3 | about 35 per second |
| Reads per second (average) | 12 × 10 | about 120 per second |
| Reads per second (peak) | 120 × 3 | about 350 per second |
| Text added per day | 1,000,000 × 10 KB | 10 GB per day |
| Text per year if we kept everything | 10 GB × 365 | 3.65 TB per year |
| Pastes that never expire, after 5 years | 30% × 1M × 365 × 5 | about 550 million |
| Their text, before compression | 550M × 10 KB | about 5.5 TB (short-lived pastes add only about 25 GB alive at any moment) |
| After 3 times compression | 5.5 TB ÷ 3 | about 1.8 TB |
| On disk with durability | 1.8 TB × 1.5 (erasure coding), or × 3 (three full copies) | about 2.7 TB, or 5.5 TB |
| Metadata after 5 years | 550M × 300 bytes | about 165 GB (about 490 GB with 3 copies) |
| Content to metadata ratio | 5.5 TB ÷ 165 GB | about 33 to 1 before compression |
| Hot cache (80/20 of a day of reads) | 0.2 × (1M × 10 reads) × 10 KB | about 20 GB |
| Reads that reach the origin (90% hits) | 120 × 10%, then 350 × 10% | about 12 per second, 35 at peak |
| Bandwidth at peak | 350 × 10 KB | 3.5 MB per second, about 28 Mbit/s |
| Pastes that expire per day | (40% + 30%) × 1M | 700,000 per day, about 8 per second (7 GB of text) |
| Method | Path | Request | Response | Notes |
|---|---|---|---|---|
| POST | /v1/pastes | { content, title?, language?, expiresIn?, visibility?, customAlias? } | 201 { code, url, rawUrl, expiresAt } | Limit body to 1 MB here, bigger pastes (up to 10 MB) use a signed upload. 413 if too large, 429 over the limit, 409 alias taken. Idempotency-Key header so a retry does not make a second paste. |
| GET | /{code} | none | 200 HTML page with the text, escaped | Public and unlisted. 404 unknown, 410 expired or removed. Cache-Control: public for public pastes, private for private ones. |
| GET | /raw/{code} | none | 200 text/plain; charset=utf-8 | Served from a separate domain. X-Content-Type-Options: nosniff. Supports Range requests for large pastes. |
| GET | /v1/users/me/pastes?cursor= | none | 200 { items, nextCursor } | Owner only. Newest first, keyset pagination by (created_at, code). |
| DELETE | /v1/pastes/{code} | none | 204 | Owner only. Soft delete, then a background job removes the blob. Purges cache and CDN. |
| Field (pastes table) | Type | Notes |
|---|---|---|
| code (key) | string | Short random code for public, long random code for unlisted. Partition key. Unique. |
| owner_id | id, optional | Null for anonymous pastes. |
| title, language | short strings | Language is a hint for highlighting. |
| visibility | public | unlisted | private | Decides caching and access checks. |
| created_at, expires_at | timestamps | expires_at null means never. Also stored as an expiry bucket (the hour). |
| size_bytes, sha256 | number, hex | Size for limits and bandwidth. Hash to detect corruption (and for dedup, if used). |
| content_key | string | Where the text is in object storage. For tiny pastes this can be inline_text instead. |
| status | active | deleted | expired | blocked | Lets us hide a paste at once, before data is physically deleted. |
| Other stores | Holds | Key |
|---|---|---|
| Object storage | The compressed text, one object per paste | blobs/{code} (or the content hash) |
| owner_pastes (secondary index) | A user's pastes, newest first | owner_id, then created_at |
| expiry_index | Which pastes expire in which hour | bucket (hour), then code |
| view events (queue, then aggregates) | One event per view | code, time |
| code ranges (small counter store) | The next unused range of the counter | one row, as in the URL shortener |
code : "k3Fz9aQ" owner_id : 48213 title : "nginx config" language : "nginx" visibility : "public" created_at : 2026-03-02T09:14:00Z expires_at : 2026-03-03T09:14:00Z (bucket: 2026-03-03T09) size_bytes : 8421 sha256 : "9f2c...e1" content_key : "blobs/k3Fz9aQ" status : "active"
| Component | What it does |
|---|---|
| CDN | Caches public pastes close to users. Pastes never change, so the cache is simple. Not used for private pastes. |
| Paste service | Validates, compresses, writes the blob and the record, applies limits, enforces visibility. |
| Raw service | Serves the plain text from a separate domain with safe headers, so pasted content cannot touch the main site's cookies. |
| Redis | Caches metadata (and small or hot pastes). Cache-aside with a TTL never longer than the paste's life. |
| Metadata store | Source of truth for the records. Partitioned by hash of code, three copies in different zones. |
| Object storage | Holds the compressed text. Very durable, cheap per GB, scales without work. |
| Expiry sweeper | Finds pastes whose time has come using the hour bucket index, hides them, deletes the text, then the record. |
| Scanner and queue | After a create, checks the text asynchronously for spam, malware and leaked secrets, and counts views off the hot path. |
The problem: Each paste is up to 10 MB of text. Over 5 years that is terabytes. We need it durable, cheap, fast to read, and not in the way of the small, hot records.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Text inside the database row | A TEXT or BLOB column in the pastes table. | One place, one transaction, simplest code. | The database grows to terabytes. Backups, restores and new replicas move all of it. Big rows push hot metadata out of memory. Costs the most per GB. |
| Text on local disk or a shared file system | Write files to a disk or network file system, keep the path in the record. | Cheap and simple at first. | You must build replication, durability and growth yourself. A disk failure is data loss. |
| Text in object storage, pointer in the record | Upload the compressed text as an object. Store only the key in the metadata record. | Built for large, immutable blobs. Very durable (erasure coding). Cheap per GB. Scales without work. | Two systems to write to, so the order and failure cases need care. An extra hop on a read. |
| Hybrid: small inline, large in object storage | Under a few KB, keep the text in the record. Above that, use object storage. | Saves a round trip for the many tiny pastes. | Two code paths and a threshold to tune. Only worth it once measurements say so. |
The two kinds of data behave differently. The metadata is small, read by key, and hot. The text is large, written once, and read whole. Putting them in one store makes both worse. After 5 years the metadata is about 165 GB and the compressed text about 1.8 TB (about 2.7 TB on disk with erasure coding).
The cost of the split is a write that touches two systems. We handle that by writing the blob first, then the record. A failure after the blob leaves an orphan blob, which is harmless and cleaned up later. The other order could leave a record that points to nothing, and a user who sees ‘paste not found’ for data they just saved.
| Failure | What the user sees | How we fix it |
|---|---|---|
| Blob upload fails | The create returns an error. Nothing was saved. | Client retries with the same Idempotency-Key. Same code, same blob key, safe to repeat. |
| Blob saved, record write fails | The create returns an error. An orphan blob exists. | A reconciliation job lists blobs older than a day with no record, and deletes them. |
| Record saved, blob missing (should never happen) | A 500 on view. | Prevented by the write order. Monitor and alert on any such read. Checksums catch corruption. |
| Delete: record removed, blob remains | Nothing: the paste is gone. | Delete is two steps (hide the record, then delete the blob), and the job is safe to repeat. |
code = nextCode(visibility) // range or 128-bit random
raw = zstd.compress(text)
store.put("blobs/" + code, raw, { sha256 }) // 1. blob first (idempotent: same key)
ok = meta.putIfAbsent(code, { ..., content_key, status: "active" }) // 2. then the record
if (!ok) return 409 // only a custom alias can clash
queue.send({ type: "scan", code }) // 3. async, off the request path
return 201The problem: An unlisted paste is protected only by its link. A private paste must be readable by its owner only. If an attacker can guess codes, ‘unlisted’ means ‘public’.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Short sequential code (like the URL shortener) | Counter ranges, scrambled, base62, 7 characters. | Short, easy to type and share. | Easy to enumerate or guess: with 550 million live pastes in 3.5 trillion codes, a guess hits about 1 in 6,400. |
| Longer random code | 8 to 10 random base62 characters. | Still short. Harder to guess. | At 8 characters one guess in about 400,000 still hits a live paste. At 1,000 guesses a second that is a hit every 7 minutes. Rate limits help but do not solve it. |
| 128-bit random code | 16 random bytes from a secure random source, written in base62 or base64url (22 characters). | Cannot be guessed or enumerated. No coordination needed. Collisions are impossible in practice. | Long URL. Not typeable. Fine for pastes people send as links. |
| Short code plus a secret key | Short public code, and a separate random key in the URL fragment (after #) or a signed link. | Can be combined with end-to-end encryption. The server never sees the key. | More complex. The server cannot scan the content. Losing the key loses the paste. |
Public pastes are meant to be found, so a short code from the same range scheme as the URL shortener is fine. Unlisted pastes depend on secrecy of the link, so the code must have enough random bits that guessing is hopeless: 22 base62 characters carry about 131 bits, while there are only about 2^29 live pastes. A guess lands on a real paste about once in 6 × 10^29 tries.
Private pastes do not rely on the link at all. Every read checks the login and the owner. Their responses are marked Cache-Control: private, no-store, they never go into the shared CDN cache, and the blob is fetched with a short-lived signed URL (or streamed through the app server), so a leaked link stops working in a minute.
| Visibility | Code | Who may read | Caching |
|---|---|---|---|
| Public | 7 to 8 characters (ranges, as in the URL shortener) | Anyone. May appear in a public ‘recent’ list. | CDN and Redis. Long TTL up to the expiry. |
| Unlisted | 128-bit random (22 characters) | Anyone who has the link. Not listed, and marked noindex. | CDN is fine because the URL is secret. TTL up to the expiry. |
| Private | Any code | Owner only (login checked on every read) | No shared cache. Short-lived signed URL for the blob. |
X-Robots-Tag: noindex so search engines skip it.The problem: 70% of pastes expire. That is about 700,000 deletions a day, against hundreds of millions of rows over the years. We must stop serving expired pastes on time, free the space, and never leave half-deleted data.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Check expires_at on every read | If the time has passed, answer 410 and do not return the text. | Exact. Always on time. No background work needed for correctness. | Does nothing for pastes nobody reads. Space is not freed. |
| Scan the whole table for expired rows | A nightly job runs a query on expires_at over all rows. | Simple to write. | A full scan of hundreds of millions of rows. Slow, heavy, and it competes with real traffic. |
| Expiry index by time bucket | A second table keyed by hour: expiry_index(bucket, code). The sweeper reads one bucket at a time. | Reads only what is due. Easy to pace and to resume. Easy to split across workers. | A second write on create. The index must stay in step with the record. |
| Object-store lifecycle rules | Tag each blob with its expiry class (1 day, 7 days) and let the store delete after N days. | No code to run. The store does it at scale. | Coarse (days), and it deletes only the blob, not the record or the cache. Good as a safety net, not the main tool. |
Correctness comes from the read check: an expired paste is never served, even if cleanup is late. Space comes from the sweeper. It reads the bucket for each past hour, and for every code does the same three steps in the same order: hide (set status to expired and remove from cache), delete the blob, then delete the record (or keep a tiny tombstone for a while). Every step is safe to repeat, so a crash in the middle just means the next run finishes the job.
About 8 expirations a second is a light load, so the sweeper can be slow and paced, which protects live traffic. Lifecycle rules on blob tags catch anything the sweeper missed. A reconciliation job compares blobs and records to find leaks.
for hour in dueBuckets(now - 5 minutes): // oldest first, resumable
for code in expiryIndex.scan(hour, pageSize = 500):
meta.update(code, status = "expired") // 1. stop serving at once
cache.delete(code); cdn.purge(code) (if public) // best effort
store.delete("blobs/" + code) // 2. free the space (idempotent)
meta.delete(code) // 3. drop the record (or keep a tombstone)
expiryIndex.delete(hour, code)
markBucketDone(hour) // pace the loop: do not hurt live traffic| Question | Answer |
|---|---|
| What if the 10-minute expiry matters? | The read check handles it exactly. The sweeper uses the hour bucket, so a 10-minute paste can sit for up to an hour before its space is freed. That is fine. |
| Can a deleted code be reused? | Not soon. Old links live in emails and chats. Public codes come from an ever-growing counter, so they are simply never reused. Random codes will not clash. |
| Owner deletes by hand | Same three steps, but done right away, with a CDN purge. Soft delete first, then a short grace period for undo and for legal holds. |
| Moving old ‘never expire’ pastes to cold storage | A separate job, based on last access. Cheaper per GB, slower to read, and the record notes which tier holds the text. |
The problem: Reads are mostly cache-friendly, but a viral paste can still be thousands of requests a second. And the text comes from strangers: it may contain scripts, giant lines, or things that should never run in a visitor's browser.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Serve everything from the app server and storage | Each request reads the record and the blob. | Simple. | The origin and storage take every read. A viral paste hits one object hard. |
| CDN for public and unlisted pastes | Cache the page and raw text at the edge, with a TTL up to the expiry. | Pastes are immutable, so there is nothing to invalidate except deletes. Takes most reads off the origin. | A deleted or blocked paste can stay at the edge until purged or the TTL ends. |
| Redis for metadata and small pastes | Cache-aside in front of the metadata store, and for hot small text. | Fast. Cuts metadata reads by about 90%. | Needs stampede protection. More memory. |
| Serve raw text from the main domain | Return user text from the same site as the login pages. | Simplest. | A single bug lets a paste run script with access to the site's cookies (XSS). Dangerous. |
Because a paste never changes, the CDN can hold it until it expires: set the TTL to the smaller of the time left and, say, a day. The only thing that can invalidate it is a delete or a takedown, which we handle with a CDN purge. Redis keeps metadata hot. Together they take about 90% of reads off the origin, leaving about 12 reads a second on average.
The security rule is simple: never let a paste be treated as a web page. Show the text escaped inside a page we control, and serve the raw text as text/plain from a different domain, so even a mistake cannot reach the main site's cookies.
| Header or rule | Why |
|---|---|
| Content-Type: text/plain; charset=utf-8 | The browser shows text, and does not run it as HTML or script. |
| X-Content-Type-Options: nosniff | Stops the browser guessing a different type from the content. |
| Separate domain for raw text (for example usercontent.example) | Cookies and storage of the main site are not sent there. A bug cannot steal sessions. |
| Content-Security-Policy: sandbox; default-src 'none' | Even if opened as a page, nothing can run. |
| Escape text in the HTML view, highlight in the browser with a safe library | Never insert user text as markup. |
| Range requests and streaming for large pastes | A 10 MB paste starts to show at once and a retry can resume. Never load the whole text into app server memory. |
| Cache-Control: public, max-age up to the expiry (public and unlisted), private, no-store (private) | Correct caching per visibility. |
Deleting many large rows from a database also leaves dead space that must be reclaimed later (vacuum or compaction), on top of the normal load. A simplified model with fixed numbers and no random values. Text compresses 3 times in both designs, so the comparison is about where the bytes live. Metadata is 300 bytes per paste. The database keeps 3 copies; object storage uses erasure coding (about 1.5 times). One GB in the database costs 10 units and in object storage 1 unit. Units are illustrative, not prices.
| Bottleneck | Fix |
|---|---|
| Database size: text kept in rows | Keep only metadata in the database. Text goes to object storage. Backups and restores shrink by about 12 times (compressed text plus metadata, against metadata alone). |
| One viral paste read thousands of times a second | CDN for public and unlisted pastes, a short in-process cache, and Redis. Spread one hot key across copies if needed (see Hot Keys). |
| Metadata store too big or too busy for one machine | Partition by hash of code (consistent hashing). 165 GB is small, so shard for headroom and failure isolation, not for size. |
| Many large uploads at once | Cap the size, stream the body, and for big pastes use a signed upload straight to object storage, so app servers never hold 10 MB bodies. |
| Cleanup competing with live traffic | Pace the sweeper, work bucket by bucket, run it in off-peak hours, and give it lower priority than user requests. |
| Storage growing forever for pastes that never expire | Tier old, unread pastes to cold storage. Compress. Keep a growth forecast and review the ‘never’ option. |
| ‘Recent pastes’ or ‘my pastes’ lists scanning too much | Secondary index by (owner_id, created_at) with keyset pagination, and a precomputed public ‘recent’ stream. |
| Failure | How the design copes |
|---|---|
| Object storage is slow or down | Reads of cached pastes keep working. Writes return a clear error and the client retries with the same Idempotency-Key. Do not accept a paste we cannot store. |
| Metadata store loses a node or zone | Three copies in different zones. Reads and writes continue on the others. Rebuild the missing copy in the background. |
| Redis is down or cold | Fall back to the metadata store, with request coalescing so one lookup per code. Rate limit, so a cold cache does not flatten the database. |
| A create dies between blob and record | An orphan blob remains. The reconciliation job removes blobs with no record after a day. The user simply retries. |
| The sweeper crashes halfway | Every step is idempotent and each bucket has a done marker. The next run finishes the work. |
| A bad paste must disappear now (legal, malware) | Set status to blocked (read check stops it at once), delete from Redis, purge the CDN, then delete the blob. Keep an audit record. |
Pastebin looks like the URL shortener, but the content changes the design. I split the data: small hot metadata in a key-value store, partitioned by code, and compressed text in object storage. Writes put the blob first and the record second, so a failure leaves harmless orphans. Pastes are immutable, so a CDN and Redis carry almost all reads. Expiry is checked on every read and swept by hour bucket. Unlisted pastes use 128-bit codes, private pastes need a login, and raw text is served safely from a separate domain.
| Decision | What we gain | What it costs |
|---|---|---|
| Metadata and text in separate stores | Small fast database, cheap durable blobs, quick restores | Two systems to write to, and a reconciliation job for orphans |
| Blob first, record second | No record can point to missing text | Orphan blobs to clean up |
| Immutable pastes | Simple caching, no versions, easy replication | No editing: changes mean a new paste and a new link |
| 128-bit codes for unlisted pastes | Cannot be guessed | Long URLs that are hard to type |
| Hour-bucket expiry index | Cleanup reads only what is due | A second write on create, and freeing space up to an hour late |
| Skip content de-duplication | Simple deletes, no privacy leak, works with encryption | Identical pastes are stored more than once |
The part that makes this different from the URL shortener.
Where ‘unlisted’ and ‘private’ get tested, and where user text meets a browser.
Viral pastes, deletion at volume, lists and counters.
Changes to the problem. They test whether you know why your design looks as it does.
A change in requirements is a test of whether you understand why your design looks the way it does.
| New requirement | What changes in the design |
|---|---|
| Pastes must be editable | Immutable becomes versioned: new content per version, a small mutable pointer to the latest. The pointer needs invalidation, the blobs stay cacheable forever. |
| Allow file and image uploads up to 1 GB | Direct signed uploads to object storage, multipart and resumable. Virus scanning, content-type checks, thumbnails, and a CDN for large objects with range requests. |
| Everything must be end-to-end encrypted | The client encrypts, the key stays in the URL fragment. We store ciphertext only: no server-side scanning or highlighting, and a lost link means lost data. |
| 100 times more pastes (100M a day) | Request rate is still moderate (about 1,200 writes a second), but bytes explode (1 TB a day). Aggressive tiering, shorter default expiry, per-user quotas, and a larger sharded metadata store. |
| Global users with strict latency | Multi-region replication of blobs and metadata, regional code ranges, CDN everywhere, and deletes that fan out to all regions. |
| Pastes must be deleted within one hour of expiry, with proof | Hour buckets become minute buckets, the sweeper gets a deadline and monitoring, deletions are logged to an audit trail, and cold copies and backups need their own deadline. |
| Private team workspaces with sharing and roles | A permissions model (owner, team, roles) on every read, signed URLs for blobs, no shared cache for private data, and audit logs of access. |
| Add public search and trending pastes | A separate search index fed from a queue, plus view-count aggregation into a top-K for ‘trending’. Both are eventually consistent and off the main path. |
| Area | Weak | Good | Great |
|---|---|---|---|
| Requirements | Starts drawing. Never asks about expiry, visibility or size. | Asks about expiry, visibility, limits and scale, and writes both lists. | Asks what makes it different from a shortener (size, expiry, trust). Confirms pastes are immutable, and says what that buys. |
| Estimation | Only requests per second. No storage numbers. | Writes, reads, daily and 5-year storage, with correct maths. | Compares content and metadata sizes, accounts for expiry mix, compression and erasure coding, and uses the result to decide the storage design. |
| Design | One box called ‘database’ holding the text. | Metadata store, object store, cache, and a clear read and write path. | Explains the write order and orphan handling, puts the CDN where immutability allows it, and keeps background work off the request path. |
| Deep-dive depth | Says ‘use S3’ with no reasoning. | Compares storage options, explains expiry cleanup and unguessable links. | Gives numbers (33 to 1, 131 bits vs 1 in 6,400), names failure cases, and makes every cleanup step idempotent. |
| Trade-offs and failures | Cannot say what happens if one of the two writes fails. | Covers cache down, object store down, viral paste, and abuse. | States the cost of each choice (two stores, orphans, no dedup, long URLs) and what they would monitor and add next. |
| Safety and privacy | Does not mention that pasted text can be malicious. | Mentions escaping, rate limits and private access control. | Separate raw domain, nosniff, CSP, signed URLs, scanning pipeline, takedown across CDN and backups, and the honest ‘unlisted is not secret’. |
| Mistake | Do this instead |
|---|---|
| Treating Pastebin as the URL shortener and re-doing code generation for ten minutes | Say ‘same ranges and base62 as the shortener’ once, then spend the time on storage, expiry, privacy and safe serving. |
| Storing the text in the database without any numbers | Compare sizes (33 to 1), backup and restore time, and cost, and then split metadata from blobs. |
| Writing the record before the blob | Blob first, record second. A failure leaves an orphan blob, not a broken link. |
| Cleaning up expired pastes with a full-table scan | Check expires_at on read for correctness, and sweep by hour bucket for space. |
| Calling unlisted pastes ‘private’ or ‘secure’ | Say unlisted means unguessable, not secret. Use 128 random bits, and offer private (login) for anything sensitive. |
| Serving user text as HTML from the main domain | Escape in the page, serve raw as text/plain with nosniff, from a separate domain. |
| Updating a view counter on the paste row for every read | Send view events to a queue and aggregate. Never create a hot row, and never break caching. |
| Forgetting caches and backups when deleting | Order the delete (hide, purge cache and CDN, delete blob, delete record), and say how backups age out. |
The code generation and redirect ideas that this design reuses.
Where the compressed text lives: buckets, objects, erasure coding and lifecycle rules.
Why immutable pastes are ideal for edge caching, and how purges work.
Expiry, tiering and cleaning up old data.
Why text compresses about 3 times, and the trade-offs of dedup.
Escaping and safe handling of untrusted text.
What to do when one paste gets most of the traffic.
Limiting creates per user and per IP to stop spam.