Replication basics
RDS primary + read replicas
Replication goals
- Read scaling — route SELECT queries to replicas.
- High availability — promote replica if primary fails.
- Geographic proximity — read replica in EU for EU users.
- Backup / DR — delayed replica for point-in-time recovery.
Leader-follower (primary-replica) is the most common pattern: all writes go to the primary; replicas apply the write-ahead log asynchronously or semi-synchronously.
-- App routing (conceptual)
-- writes → primary.db.streamhub.internal
INSERT INTO videos (id, creator_id, title) VALUES ($1, $2, $3);
-- reads → replica.db.streamhub.internal (accept replica lag)
SELECT id, title, view_count FROM videos WHERE creator_id = $2 ORDER BY created_at DESC LIMIT 20;
Replication lag and consistency
Replicas lag the primary by milliseconds to seconds. Implications for StreamHub:
| Aspect | Read from replica | Read from primary |
|---|---|---|
| Latency | Lower load on primary | Higher primary load |
| Freshness | May miss last few writes | Always latest |
| StreamHub use | Public feeds, browse pages | Post-upload confirmation, billing |
Latency
Read from replicaLower load on primaryRead from primaryHigher primary loadFreshness
Read from replicaMay miss last few writesRead from primaryAlways latestStreamHub use
Read from replicaPublic feeds, browse pagesRead from primaryPost-upload confirmation, billing
After a creator uploads a video, StreamHub reads from primary for the "your video is live" page; followers see it on replicas within ~1 second.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 6 sections
- Failover
- When to shard
- Sharding strategies
- Cross-shard challenges
- Replication + sharding together
- Migration path
Test yourself
Answer these before moving on — recall is what makes it stick.