Loading...
A 20-minute mock system design interview. You drive the pace. Jump to the board when you are ready; skip capacity math if you want. The interviewer grades your thinking, not a template match. This is an easier question than most, so the bar shifts to execution: clean estimation, the storage split, key-generation correctness, a real expiry story. Strong candidates finish with time to spare and volunteer extended topics.
The trap is treating this as a CRUD app with a UUID primary key. Pastebin is a short-URL + blob store: unique non-guessable keys, a 5:1 read/write mix, metadata that wants a database and content that wants object storage, and expiration that must actually delete bytes.
Two shared surfaces (only one is on screen at a time; use the panel arrow to switch):
Build incrementally while you talk. Trace one paste create and one paste read through your diagram. Argue the tradeoff, not "industry standard."
Read this before you go in. These are the decisions, and why they matter.
A sequential integer URL (pastebin.com/1, /2, /3) is guessable: crawlers and attackers walk the namespace. You need a short, unique, hard-to-enumerate key.
Charset. Base62 (a-zA-Z0-9) or Base64. Six Base64 characters → 64^6 ≈ 68.7 billion keys. Seven Base62 characters → 62^7 ≈ 3.5 trillion. Pick a length from the 10-year paste count plus a safety factor, not from vibes.
How you mint them. Three families, pick one and defend it:
Do not hash the content (MD5, truncate). It fails three ways: identical content from two users lands on one key, truncation collides anyway, and content-derived keys can be precomputed by an attacker — which breaks the unguessability requirement.
Custom vanity URLs are a separate uniqueness check in the same namespace, not a replacement for the default generator. A taken alias returns an error — never silently mutate it. Cap alias length.
Pastes are two different data types. Metadata (key, created_at, expiry, user, size, visibility) is small and queried. Content (the blob, up to ~10 MB) is large and rarely filtered. Putting both in one SQL row works at toy scale and then the table becomes a blob store with indexes on the wrong thing.
The standard split: metadata in SQL (or a small KV), content in object storage (S3). Cache hot pastes (80/20: 20% of pastes take 80% of reads) in Redis with TTL ≤ paste expiry.
Typical load is ~5 reads per write. Optimize the read path: CDN → cache → metadata DB → object storage. The write path can be a single region; the read path wants a CDN.
"TTL on the row" is not a design. Object storage does not vanish when a SQL row does. And a cron that scans for expired rows every minute hammers the DB for no user-visible gain. The pattern is lazy plus scheduled: the read path checks expiry and deletes on touch; a lightweight cleanup worker (or bucket lifecycle rules) sweeps object + row + cache during off-peak windows; freed keys go back to the unused pool. The contract you state out loud: an expired paste may physically persist for a while, but it is never served. Pastes with no expiry get a default TTL (say two years) or the store grows forever — though "storage is cheap, keep forever" is defensible if argued.
One complete design you can study, then rebuild in your own words. Do not recite it. In the interview, draw your graph and defend the choices.
Rough numbers are fine; the method is what gets graded. Use the 5:1 ratio and the 36 TB to justify object storage + CDN, not a giant SQL table.
Web Client, Mobile Client
→ Load Balancer / API Gateway
→ Paste Service (stateless, mark distributed)
↔ Key Generation Service → Key DB (unused / used keys)
↔ Metadata DB (SQL)
↔ Blob Store (S3; paste bodies)
↔ Redis (hot pastes; TTL ≤ expiry)
→ CDN (read path)
→ Worker (expiry / cleanup)
pastes/{key}; INSERT metadata; SET cache with TTL.https://pastebin.example/{key}.GET on an expired paste: the read path checks expire_at before serving. Expired → 404 (or 401 for permission failures) and delete lazily right there; the off-peak Worker sweeps whatever was never touched, and the freed key returns to the unused pool. Expired content may persist physically for a while — it is never served.
Collision / enumeration: random keys with no KGS still need a uniqueness check (duplicate-insert + retry); sequential keys fail the security probe.
Cache vs expiry: a cache TTL longer than paste expiry serves deleted content. TTL must be min(popularity window, remaining life).
Pastes(key PK, user_id, created_at, expire_at, size_bytes, visibility, content_uri)
Keys(key PK, status: unused|used, allocated_to, allocated_at)
Users(id, email, plan) — optional, for custom URLs and delete-auth
key if it outgrows one primary. Range-by-prefix is the obvious wrong answer: some prefixes run hot and servers unbalance. Consistent hashing eases rebalancing. Content is already sharded by the object storePastesapi_dev_key quotas (spam), private pastes (permission in metadata, checked on read — unguessable keys are not access control, links leak), malware scan of content, burn-after-read pastesSnowflake IDs encoded in Base62 instead of a KGS (must still break sequentiality). Random + collision-retry at this write rate (12/sec — the retry loop is not yet a hotspot). KV (DynamoDB/Cassandra) for metadata instead of SQL — billions of small rows with no joins favor KV at the high end. Memcached instead of Redis. Content-hash keys are the one variant that is not defensible without naming its costs: cross-user collisions, truncation collisions, precomputable URLs. What matters is that you can argue the tradeoff.