KatInterview

Design a Scalable Text Paste Service (Pastebin Clone)

System DesignModel answer
EasyModel answerSystem Designsystem-designdistributed-systemsapi-design

Last updated

Design a text sharing system that accepts raw text or code snippets and generates short, durable URLs with customizable TTLs under high read concurrency.

Problem Overview

Design a distributed text-sharing web application similar to Pastebin. Users should be able to upload plain text or code snippets, assign optional expiration policies, generate a short non-predictable URL, and distribute that link to others.

Functional Requirements

  1. Paste Creation: Users submit text data and optionally pick an expiration timeframe (e.g., 10 minutes, 1 day, 30 days, or infinite). They may also supply a custom string identifier.
  2. Paste Access: Anyone presenting a valid unique key gets the original raw text content.
  3. Paste Deletion: Anonymous creations cannot be deleted manually. Authenticated authors can explicitly purge pastes they own.
  4. Expiration Handling: Once a paste passes its expiration timestamp, it must be inaccessible to readers.

Non-Functional Requirements

  1. Low Latency & High Availability: Read queries must return in under 50ms. The system operates under a heavy read-to-write skew (between 10:1 and 50:1).
  2. Durability: Uploaded snippets must remain persistent and uncorrupted until their expiration date.
  3. Collision Resistance & Entropy: Generated keys must be unique. Private pastes should rely on unguessable key formats.

System Capacity & Scale Assumptions

  • Write Throughput: 10 million new paste submissions per day (~115 writes/sec average, ~500 writes/sec peak).
  • Read Throughput: 100 million paste reads per day (~1,150 reads/sec average, ~5,000 reads/sec peak).
  • Payload Constraints: Average paste payload size is 10 KB; absolute maximum is 2 MB per paste.
  • Storage Projections: ~100 GB of fresh content ingested daily (~36.5 TB/year before compression or eviction).

What Your Architecture Should Cover

  1. API Endpoints: Formal RESTful interface definitions for key operations, including payloads, failure cases, and status codes.
  2. Storage Split & Data Model: Schema design for metadata vs. raw payload storage, detailing the rationale behind separating object storage from relational/NoSQL metadata engines.
  3. Identifier Generation: Comparison of identifier allocation strategies (Key Generation Service with memory-buffered ranges vs. inline cryptographic hashing/counters).
  4. End-to-End Execution Flow: Complete trace of read/write lifecycles through load balancers, web tiers, distributed caches, storage tiers, and garbage collection workers.
  5. Operational Edge Cases & Trade-offs: Strategies for handling viral/hot keys, rate limiting, and cache invalidation strategies during deletions.

Hints

Hint 1

Consider how separating small metadata (e.g., owner, TTL, key) from heavy payloads (up to 2 MB) impacts database indexing and buffer pool efficiency.

Hint 2

Evaluate how pre-generating short unique strings in bulk off the critical write path eliminates database lock contention and collision checks.

Hint 3

Ensure lazy expiration logic on the read path so strict system correctness does not depend on background cleanups running instantaneously.