What is Database Replication?
You'll learn: What database replication is and why systems copy data across multiple database instances.
The Core Idea
Database replication is the process of copying data from a primary (master) database to one or more replica (slave) databases. Think of it like having backup copies of a book in different libraries—when the original gets updated, the copies are updated too to stay in sync.
The primary database handles all writes (inserts, updates, deletes), while replicas receive those changes and apply them to their own copies of the data. This creates multiple identical copies of your database distributed across different servers.
Why Replication Matters
Just as CDNs solve the latency problem by placing content closer to users (lessons 169-170), database replication solves several critical problems:
- Read scalability: Multiple replicas can handle read queries simultaneously, distributing load
- Availability: If the primary fails, a replica can take over
- Geographic distribution: Place replicas closer to users in different regions
- Backup and disaster recovery: Replicas serve as live backups
The Basic Flow
- Application writes data to the primary database
- Primary logs the change
- Change is transmitted to replica databases
- Replicas apply the change to their local copy
- All databases now contain the same data (eventually)
This is similar to how origin servers and edge servers work in CDN architectures (lesson 170), except we're replicating database state instead of static content.
Key Takeaway: Database replication copies data from a primary database to replica databases, enabling read scalability, higher availability, and geographic distribution of data.