Senior Track Roadmap

Database architecture: replicas

This course explains how a Postgres read replica works and when one is worth adding. It covers streaming and replaying the write-ahead log, asynchronous replication and replication lag, and the writing and reading roles in Rails, with replica: true and connected_to. It examines read-your-own-writes failures, measures one application's read share and database time, and identifies the single query that could justify a replica. It also shows how GET requests can write. It ends with a challenge to implement replica routing logic.

What you'll learn

  • ✓How a replica streams and replays the primary's write-ahead log
  • ✓Why replication lag grows with write volume and causes read-your-own-writes failures
  • ✓Declaring writing and reading roles in Rails and routing with connected_to
  • ✓Measuring whether the primary is saturated before adding a replica
  • ✓Finding writes hidden in GET requests before routing by HTTP verb
  • ✓Implementing the choice between primary and replica for each request
Free preview · Lesson 1 3 min read

What a replica actually is

A read replica is a second database that copies everything the first one does, a little later. Both halves of that sentence matter, and the second half is where every replica problem comes from.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...