system-design-primer
exercise

Pastebin

Design Pastebin.com — users paste a block of text and get back a short, randomly generated link to it. Bit.ly is the same problem with the text replaced by a URL.

constraints and assumptions
  • 10 million users a month
  • 10 million pastes a month
  • Read-heavy at 100:1
  • Pastes expire
  • Links are not guessable
  • Analytics on views
  • Service is highly available
work it in four steps
in short

Scope to the paths that matter: a user enters a block of text and gets a generated link; a user enters the link and sees the paste; expired pastes are deleted; the service tracks analytics on page views.

Do the arithmetic before designing. 10 million writes a month at an average paste size of 1 KB is 10 GB of new content a month, 360 GB over three years. That is one machine's worth of data, so the design pressure comes from reads, not storage.

from the primer — step 1: outline use cases and constraints

Gather requirements and scope the problem. Ask questions to clarify use cases and constraints. Discuss assumptions.

Without an interviewer to address clarifying questions, we'll define some use cases and constraints.

Use cases

We'll scope the problem to handle only the following use cases

  • User enters a block of text and gets a randomly generated link
    • Expiration
      • Default setting does not expire
      • Can optionally set a timed expiration
  • User enters a paste's url and views the contents
  • User is anonymous
  • Service tracks analytics of pages
    • Monthly visit stats
  • Service deletes expired pastes
  • Service has high availability

Out of scope

  • User registers for an account
    • User verifies email
  • User logs into a registered account
    • User edits the document
  • User can set visibility
  • User can set the shortlink

Constraints and assumptions

State assumptions

  • Traffic is not evenly distributed
  • Following a short link should be fast
  • Pastes are text only
  • Page view analytics do not need to be realtime
  • 10 million users
  • 10 million paste writes per month
  • 100 million paste reads per month
  • 10:1 read to write ratio

Calculate usage

Clarify with your interviewer if you should run back-of-the-envelope usage calculations.

  • Size per paste
    • 1 KB content per paste
    • shortlink - 7 bytes
    • expiration_length_in_minutes - 4 bytes
    • created_at - 5 bytes
    • paste_path - 255 bytes
    • total = ~1.27 KB
  • 12.7 GB of new paste content per month
    • 1.27 KB per paste * 10 million pastes per month
    • ~450 GB of new paste content in 3 years
    • 360 million shortlinks in 3 years
    • Assume most are new pastes instead of updates to existing ones
  • 4 paste writes per second on average
  • 40 read requests per second on average

Handy conversion guide:

  • 2.5 million seconds per month
  • 1 request per second = 2.5 million requests per month
  • 40 requests per second = 100 million requests per month
  • 400 requests per second = 1 billion requests per month
sourcedonnemartin/system-design-primer / solutions/system_design/pastebin/README.mdsyncedsynced from donnemartin/system-design-primer@master · 2026-08-16