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

Read Replicas for Retrieval Scaling

Use database read replicas to distribute paste retrieval load and reduce primary database query pressure.

Read Replicas for Retrieval Scaling

What you'll learn: How to scale Pastebin's read-heavy retrieval workload by distributing queries across database replicas.

The Core Idea

As millions of users retrieve pastes simultaneously, your primary database becomes overwhelmed with read queries. Read replicas are synchronized copies of your primary database that handle read-only operations, allowing you to horizontally scale retrieval capacity.

Think of it like a library: instead of one librarian (primary database) frantically searching for books while also cataloging new ones, you hire multiple librarians (replicas) who each have identical copies of the catalog. They all handle book lookups while the head librarian focuses on adding new books.

How It Works for Pastebin

Your primary database handles all writes (new pastes, updates). It continuously replicates data to multiple read replicas through asynchronous or semi-synchronous replication. When users retrieve pastes:

  1. Write requests (creating pastes) → Primary database
  2. Read requests (viewing pastes) → Load-balanced across replicas
  3. Metadata queries for paste info → Distributed to nearest replica

For Pastebin's read-heavy workload (90%+ reads), adding 5-10 replicas can multiply your retrieval capacity dramatically. Each replica handles a portion of the read traffic, preventing the primary from becoming a bottleneck.

Replica Lag Consideration

Replication isn't instant. A paste created on the primary might take 100-500ms to appear on replicas (replication lag). For Pastebin, this is typically acceptable—users won't immediately share their URL. However, you might route the paste creator to the primary for a few seconds to ensure they see their own content.

Key Takeaway: Read replicas horizontally scale Pastebin's retrieval operations by distributing read queries across synchronized database copies, multiplying read throughput while isolating the primary for write operations.