Requirements


Functional Requirements:

  • Upload & store text/code — a user can paste or write content and the system stores it.
  • Generate a unique shareable URL — each paste gets a short, unique link (e.g., pastebin.com/abc123) the user can share.
  • Retrieve paste by URL — anyone with the link can view the content.
  • Expiration / TTL — pastes live for a set period (e.g., 24h, 1 week, or a custom time) then auto-delete.



Non-Functional Requirements:

  • High availability — this is a link-sharing service; people open pastes hours or days later. If the site is down, those links are dead on arrival. Availability beats consistency here (worst case: someone sees a stale paste, not an error).
  • Low read latency — Pastebin is heavily read-heavy (think 10:1 read-to-write ratio). The "open a link" path is the hottest path in the system, so reads should be fast and cheap. This will drive your caching strategy later.
  • Scalability — assume millions of users. The system should grow horizontally as paste creation and traffic spike (e.g., Reddit Hug-of-Death on a popular paste).



Capacity Estimation

DAU - 5000000

Pastes per day - 1000000

Read to write ratio - 10:1

RPS(write) = 1000000 / 86400 = 12

RPS(read) = 120

Avg paste size = 10 KB

Storage per day = 1000000 * 10 = 10 GB/day

Storage over 5 year = 10 * 365 * 5 = 18 TB

Bandwidth = 120 * 10 KB = 1200


API Design

POST /pastes

{

"content": "...",

"expiration": "24h"

}

-> 201 Created

{

"key": "abc123",

"url": " https://pastebin.com/abc123",

"expire_at": "..."

}


GET /pastes/abc123

-> 200 Ok

{

"content": "...",

"created_at": "...",

}

-> 404 Not Found

{

"error": "Paste expired or does not exist"

}



High-Level Design

CDN - the client sends a request to the CDN to find cacheable content

Load Balancer - if the required content is not cached, the request is sent to a load balancer to distribute the load.

API Gateway - accepts incoming requests from clients and redirects them to the required microservices

Expiration Service - microservice that checks a link's expiration date: if the expiration date has expired, the service returns a message that the content is no longer available. It also registers new links to user-created content.

PostgreSQL - a database for storing metadata about content, including expiration dates

S3 - stores the text content directly



Database Design




Detailed Component Design

Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.