System Design Lab›System Design Questions›Design Pastebin
Design Pastebin
EasyStoragestoragekey-valuecachingexpiration
Question Overview
Design a text-sharing service like Pastebin where users paste text, receive a short URL, and share it until it expires. The interesting parts are generating unique, unguessable keys, storing paste bodies cheaply, and serving a read-heavy workload with low latency.…
Sign up to see the full question and AI interviewer
Requirements
- Create a paste of up to 1 MB of text and return a short, unique URL
- Read a paste by URL with low latency; unlisted pastes are reachable only through their link
- Optional custom alias, expiration time, and syntax-highlighting language
- Expired pastes stop being served immediately and are purged from storage in the background
- Signed-in users can list and delete their own pastes
- No paste is lost before it expires (durable writes, replicated storage)
Back-of-the-envelope numbers
- Writes: 5M pastes/day ÷ 86,400 s ≈ 58 writes/s average, ~175/s at 3× peak
- Reads: 10:1 read-to-write ratio → 50M reads/day ≈ 580 reads/s average, ~1.7K/s at peak
- Body storage: 5M × 10 KB = 50 GB/day ≈ 18 TB/year ≈ 90 TB over 5 years before compression and expiry
- Metadata: ~200 bytes × 5M/day × 365 × 5 ≈ 1.8 TB, comfortably handled by a sharded SQL or key-value store
- Key space: 7 base62 characters = 62^7 ≈ 3.5 trillion keys, versus ~9B pastes created in 5 years
- Cache: holding 20% of a day's read volume ≈ 0.2 × 50M × 10 KB ≈ 100 GB, spread over a few cache nodes
Key components
- Stateless API servers behind a load balancer serving POST /pastes and GET /{key}
- Key generation service that hands out pre-generated random base62 keys so creates never collide or retry
- Object storage (e.g. S3) for paste bodies and a key-value or SQL store for key, owner, size, expiry, and visibility
- Cache (Redis or Memcached) plus a CDN in front of the read path for hot pastes
- Expiry handling: check expires_at on every read, and a background worker that batch-deletes expired bodies and metadata
Common mistakes
- Storing multi-KB paste bodies inline in the primary database instead of object storage, bloating its hot working set
- Using sequential IDs for unlisted pastes, which makes every paste enumerable by incrementing the URL
- Deriving the key from a content hash without handling collisions or two users pasting identical text
- Relying only on a periodic cleanup job for expiry, so expired pastes stay readable until the next sweep
- Skipping a read cache even though reads outnumber writes 10 to 1 and popular pastes are heavily skewed
Likely follow-ups
- How would you support pastes larger than 1 MB, such as 100 MB log files?
- How would you prevent abuse such as spam, malware links, or leaked credentials?
- How would you add view counts without turning every read into a database write?
- How would you guarantee a custom alias is unique if the service runs in multiple regions?
- How would you delete all of a user's pastes for a GDPR erasure request?
No community solutions yet
Be the first to publish your solution
Practice ‘Design Pastebin’ with an AI Interviewer
Get scored feedback on your diagram, scalability approach, and trade-offs. Free while we grow — up to 3 full interviews a day.