Why Replicate: Availability and Failover
What you'll learn: How database replicas act as backup systems that keep your application running even when the primary database fails.
The Redundancy Safety Net
You've learned that replicas help scale reads. But their second critical job is ensuring your system doesn't go down when hardware fails, networks partition, or disasters strike.
Think of replicas like backup generators in a hospital. When the main power fails, backup systems kick in automatically so life-critical equipment keeps running. Database replicas work the same way.
How Replicas Enable Failover
When your primary database (the write-accepting database) becomes unavailable—whether from a crash, network issue, or maintenance—a replica can be promoted to become the new primary. This process is called failover.
Without replicas:
- Primary database crashes → entire application goes down
- No writes possible, often no reads either
- Manual recovery could take minutes or hours
With replicas:
- Primary database crashes → failover to replica happens
- Replica becomes new primary and accepts writes
- Downtime reduced from hours to seconds or minutes
- Application continues serving users
Automatic vs Manual Failover
Manual failover requires human operators to detect the failure and promote a replica. It's slower but gives you control.
Automatic failover uses monitoring systems to detect primary failure and promote a replica without human intervention. Faster, but needs careful configuration to avoid false positives (remember health check flapping?).
Geographic Redundancy
Replicas can be placed in different data centers or cloud regions. If an entire data center loses power or connectivity, your replicas elsewhere keep the system available.
Key Takeaway: Replicas provide redundancy that transforms a single point of failure into a highly available system capable of surviving hardware failures, network issues, and disasters through automatic or manual failover.