Course contentsShow
← System Design
Lesson 1553 of 1,91938. Real-World System: PastebinFree lesson

Object Storage vs Database for Paste Content

Compare storing paste text in relational DB vs object storage like S3 for cost and retrieval performance.

Object Storage vs Database for Paste Content

You'll learn: When to store paste text in a relational database versus object storage like Amazon S3, and how each choice affects cost and performance.

The Storage Dilemma

When designing Pastebin, you face a crucial decision: where do you actually store the paste content? You have two main options:

  1. Store in the database alongside metadata (title, expiration, owner)
  2. Store in object storage (S3, Azure Blob) and keep only metadata in the database

Database Storage

Storing paste content directly in a TEXT or BLOB column is simple and keeps everything together. Retrieval is a single query: SELECT content, title, created_at FROM pastes WHERE key = 'abc123'.

Pros: Simple architecture, ACID guarantees, easier transactions
Cons: Databases are expensive per GB (~$0.10-0.25/GB/month), limited by database size/IOPS, large rows slow down queries and backups

Object Storage

Storing paste content in S3-like systems means your database holds only a pointer: s3://pastes/abc123.txt. When a user views the paste, you make two calls: one to fetch metadata from the database, one to fetch content from S3.

Pros: Dramatically cheaper (~$0.02/GB/month), unlimited scalability, designed for large blobs
Cons: Two network calls (latency), eventual consistency issues, more complex architecture

The Practical Choice

For Pastebin's large text blobs and read-heavy workload, object storage wins. The 5-10x cost savings matter at scale, and you can cache frequently-accessed pastes to hide the two-call latency. Reserve database storage for small pastes (<10KB) to avoid double-hop overhead.

Key Takeaway: Use object storage for paste content to achieve massive cost savings (~80%) and unlimited scale; accept slightly higher retrieval latency mitigated by caching, while keeping metadata in the database for fast queries.