πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
NEWSLIVESearch All Content
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Design Pastebin

System Design ProblemsPaste Service🟒 Free Lesson

System Design Problems

Design Pastebin

Pastebin allows users to paste text or code and share it via a unique URL. Services like GitHub Gist, hastebin, and dpaste handle millions of pastes daily with simple creation and reading workflows.

  • Paste Creation β€” Accept text input, generate unique URL, store with metadata
  • Paste Reading β€” Retrieve paste content via short URL with minimal latency
  • Expiration β€” Pastes auto-delete after configurable TTL periods

Pastebin is simpler than most system design problemsβ€”it's essentially a write-once-read-many (WORM) system with time-based expiration.

Requirements

Functional Requirements

  • Users can create a paste with text content (up to 10MB)
  • Each paste gets a unique, shareable URL
  • Pastes can be public or private (unlisted)
  • Pastes expire after a configurable duration (10 min, 1 hour, 1 day, 1 week, never)
  • Support syntax highlighting for code pastes
  • Users can set a custom name for the paste (optional)

Non-Functional Requirements

  • Latency: Read paste in < 100ms
  • Availability: 99.9% uptime
  • Durability: Pastes must not be lost before expiration
  • Scalability: 10M new pastes/day, 100M reads/day

Back-of-the-Envelope Estimation

API Design

Architecture Diagram
POST /api/v1/pastes
Request:  { "content": "...", "syntax": "python", "visibility": "public", "expires_in": "1h" }
Response: { "paste_id": "abc123", "url": "https://paste.example.com/abc123" }

GET /{paste_id}
Response: { "content": "...", "syntax": "python", "created_at": "...", "expires_at": "..." }

GET /api/v1/pastes/{paste_id}/raw
Response: Plain text content (no JSON wrapping)

DELETE /api/v1/pastes/{paste_id}
Response: { "status": "deleted" }

High-Level Architecture

ClientLoadBalancerPaste ServiceExpiration SvcID GeneratorRedis CacheObject Storage(S3/GCS)Metadata DBPastebin Architecture

Detailed Design

Storage Layer

Pastebin has two distinct storage needs:

Data TypeStorageReason
Paste content (large)Object Storage (S3)Cost-effective, durable, high throughput
Paste metadataRelational DB (PostgreSQL)Structured queries, relationships
Hot pastesRedisSub-millisecond reads, TTL support
Expired paste trackingRedis sorted setEfficient expiration scanning

Expiration Strategy

Pastebin requires automatic deletion of expired pastes:

Option A: Lazy Expiration (Recommended)

  • Check expires_at on every read
  • Delete if expired; return 404
  • Simple, no background processing
  • May show stale data in cache

Option B: Active Expiration

  • Background worker scans for expired pastes
  • Deletes from database and cache periodically
  • More consistent, but adds complexity
  • Use sorted set in Redis: EXPIRE_AT score=<timestamp>

Content Storage Pattern

Store large paste content in object storage, metadata in the database:

Architecture Diagram
// Metadata record
{
  paste_id: "abc123",
  user_id: "user_456",
  content_path: "s3://pastes/ab/c1/abc123.txt",
  syntax: "python",
  visibility: "public",
  created_at: "2026-06-20T10:00:00Z",
  expires_at: "2026-06-20T11:00:00Z",
  size_bytes: 10240
}

Syntax Highlighting

Support syntax highlighting for code pastes:

  1. Client submits paste with syntax parameter (or auto-detect)
  2. Server stores raw content in object storage
  3. On read, apply syntax highlighting at the CDN edge or application layer
  4. Cache highlighted HTML alongside raw content

Scaling Considerations

Database Partitioning

Partition paste metadata by paste ID hash:

Architecture Diagram
shard = hash(paste_id) % NUM_SHARDS

This distributes pastes evenly across shards. For time-based queries (e.g., "recent pastes"), maintain a separate time-indexed table or use a time-series database.

Read Path Optimization

  1. Check Redis cache for paste metadata
  2. Cache hit: return content from object storage (cached at CDN)
  3. Cache miss: query database, populate cache, return content
  4. CDN caches public paste content at edge locations

Write Path Optimization

  1. Generate unique paste ID (Snowflake or random)
  2. Write metadata to database (async if possible)
  3. Write content to object storage (S3 multipart upload for large pastes)
  4. Populate Redis cache proactively
  5. Return paste URL to user

What to Learn Next

-> Design URL Shortener Similar WORM pattern with ID generation and caching strategies.

-> Caching Strategies Cache-aside, write-through, and TTL-based expiration patterns.

-> CDNs Caching static content at the edge for global low-latency access.

-> Databases Choosing between SQL and NoSQL for metadata storage.

-> Design Object Storage Building scalable blob storage for large content objects.

-> Design Unique ID Generator Snowflake IDs, UUIDs, and distributed ID generation.


Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type β€” Always start by categorizing the problem
  2. Incorrect formula application β€” Verify the formula applies to your specific case
  3. Unit errors β€” Always check units are consistent throughout
  4. Sign errors β€” Pay careful attention to positive and negative values
  5. Rounding too early β€” Keep full precision until the final answer
  6. Forgetting constraints β€” Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-11-14

β€”
β˜†β˜†β˜†β˜†β˜†
0 ratings

Rate & Feedback

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement