This repository is a sequence of production-style subprojects that teach MySQL replication and availability step by step. Each subproject builds on the previous one and focuses on one major concept at a time.
- SubProject01 — Single MySQL CRUD
- SubProject02 — Multiple MySQL servers
- SubProject03 — Asynchronous source-replica replication
- SubProject04 — Semi-synchronous replication
- SubProject05 — GTID-based replication
- SubProject06 — Manual failover
- SubProject07 — Automatic failover
Most replication tutorials stop after setting up a replica.
This repository goes further by showing:
- how replication works,
- how semi-sync changes commit behavior,
- how GTID simplifies recovery,
- how to handle source failure manually,
- and how to automate failover.
Across the repository, the following ideas are reused:
- FastAPI as the application layer
- MySQL 8 as the database layer
- Docker and Docker Compose for local infrastructure
- Shell scripts for step-by-step setup
- Explicit verification scripts after each major change
Typical topology:
mysql_db_write_1— source or primarymysql_db_read_1— replica or promoted primary depending on the project
FastAPI typically exposes:
POST /ordersfor write operationsGET /ordersfor read operations
Writes go to the writable database. Reads go to the replica unless the topology changes during failover.
- How MySQL binary logs work
- How replication threads work
- How GTID changes replication recovery
- How semi-sync improves durability
- How to promote a replica manually
- How to automate failover using Python and Docker
- How application configuration must change during database promotion
- Start the Docker environment for the subproject you want to study.
- Run the scripts in order.
- Test the FastAPI APIs.
- Simulate failures where applicable.
- Observe how the system behaves and recovers.
For each subproject:
- read the README first,
- run the scripts one by one,
- verify the output,
- and only then move to the next subproject.
This repository is designed as a step-by-step learning lab. The intention is not just to configure replication, but to understand the operational behavior of MySQL replication systems from first principles.