Robust and scalable Go application with MySQL master-slave replication running in Docker containers! πΎ
This project demonstrates high-availability database architecture using MySQL master-slave replication with a Go backend. Perfect for learning about distributed systems and database scaling! π―
- π Master-Slave Replication - 1 Master + 3 Slave nodes
- π³ Docker Containerization - Easy deployment and scaling
- π Automatic Failover - Built-in replication monitoring
- β‘ High Performance - Read scalability across multiple slave nodes
- π Data Consistency - ACID compliance with replication
- π Health Monitoring - Built-in database health checks
graph TB
A[Go Application] --> B[MySQL Master]
B --> C[Slave 1]
B --> D[Slave 2]
B --> E[Slave 3]
style A fill:#74c0fc
style B fill:#ff8787
style C fill:#51cf66
style D fill:#51cf66
style E fill:#51cf66
| Component | Technology | Purpose |
|---|---|---|
| Backend | High-performance API server | |
| Database | Primary data storage | |
| Containerization | Environment isolation | |
| Orchestration | Multi-container management |
- π³ Docker
- π³ Docker Compose
- βοΈ Go 1.25.3+ (for local development)
-
Clone the repository
git clone https://github.com/FollG/go-database-replication.git cd go-database-replication -
Start the environment
# Start all services (Master + 3 Slaves + Go Application) chmod +x \ ./build/stop.sh \ ./build/start.sh \ ./build/status.sh \ ./build/setup-replication.sh ./build/start.sh -
Verify services are running
./build/status.sh
β You should see 5 running containers!
-
Check replication status
# Connect to master and check slave status docker-compose exec mysql-master mysql -uroot -psecret -e "SHOW SLAVE HOSTS;"
TODO
| Variable | Default | Description |
|---|---|---|
DB_MASTER_HOST |
mysql-master |
Master database host |
DB_MASTER_PORT |
3306 |
Master database port |
DB_SLAVE_HOSTS |
slave1,slave2,slave3 |
Comma-separated slave hosts |
MASTER_DB_USER |
./configs.*.yaml |
Database username |
SLAVE_DB_USER |
./configs.*.yaml |
Database username |
MASTER_DB_PASSWORD |
./configs.*.yaml |
Database password |
SLAVE_DB_PASSWORD |
./configs.*.yaml |
Database password |
# This will create data on the master node
curl -X POST http://localhost:8080/api/users/ \
-H "Content-Type: application/json" \
-d '{"name": "MisterFish", "email": "misterfish@gmail.com"}'# This will read from slave nodes (round-robin)
curl http://localhost:8080/api/users-
Connection Refused
# Check if containers are running docker-compose ps # Check master logs docker-compose logs mysql-master
-
Replication Not Working
# Check slave status docker-compose exec mysql-slave1 mysql -uroot -psecret -e "SHOW SLAVE STATUS\G"
-
Application Can't Connect
# Verify network docker network ls docker network inspect go-database-replication_default
We welcome contributions! π Here's how you can help:
- π΄ Fork the project
- πΏ Create your feature branch (`git checkout -b feature/AmazingFeature`)
- πΎ Commit your changes (`git commit -m 'Add some AmazingFeature'`)
- π€ Push to the branch (`git push origin feature/AmazingFeature`)
- π Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- MySQL Documentation for replication setup
- Docker community for excellent containerization guides
- Go community for best practices and libraries
β Don't forget to star the repository if you found it helpful! β
Made with β€οΈ and β by FollG