Course contentsShow
← Cloud and Infrastructure
Lesson 2475 of 2,98953. High Availability PatternsFree lesson

Database Replication Fundamentals

Understanding replication concepts, synchronous vs asynchronous replication, and why databases need replication.

Database Replication Fundamentals

What you'll learn: You'll understand what database replication is, why it's essential for high availability, and the critical distinction between synchronous and asynchronous approaches.

What Is Database Replication?

Database replication is the process of continuously copying data from one database server (the primary or master) to one or more other servers (the replicas or secondaries). Think of it like keeping multiple synchronized copies of an important document across different filing cabinets—if one cabinet burns down, you still have the others.

Why Databases Need Replication

Without replication, your database is a single point of failure. If it crashes, your entire application goes down. Replication provides:

  • High availability: If the primary fails, a replica can take over
  • Load distribution: Read queries can be spread across replicas
  • Geographic distribution: Place data closer to users in different regions
  • Data protection: Multiple copies guard against data loss

Synchronous vs Asynchronous Replication

The crucial trade-off in replication is when replicas acknowledge receiving data:

Synchronous replication waits for at least one replica to confirm it has written the data before acknowledging the transaction to the client. This guarantees strong consistency—replicas are always up-to-date—but adds latency and reduces availability if replicas are unreachable.

Asynchronous replication acknowledges transactions immediately after the primary writes them, then sends updates to replicas in the background. This provides better performance and allows the system to continue if replicas fail, but creates a replication lag where replicas may be slightly behind.

The choice depends on your RPO requirements: can you tolerate losing the last few seconds of transactions if the primary fails (asynchronous), or must every committed transaction survive (synchronous)?

Key Takeaway: Database replication copies data across multiple servers for availability and resilience; synchronous replication ensures consistency at the cost of latency, while asynchronous prioritizes performance but accepts temporary lag between primary and replicas.