MySQL Architecture Design Patterns For Performance, Scalability, and Availability Presentation
MySQL Architecture Design Patterns For Performance, Scalability, and Availability Presentation
Alexander Rubin
Principal Consultant
Agenda
HA and Scale-Out
Architectural Tools
MySQL Replication
DRDB Clustering
MySQL Cluster
Design Patterns
Simple Master-Slave
Master and Many Slaves
Master-Master
DRBD Pair
DRBD Master with Many Slaves
MySQL Cluster
Scale-out/Sharding
Continuous Availability
Non-stop service
No disruption of service even during a fail over
disasters
power
failures
network failures
Clustering
Technologies
hardware failures
software failures
Replication
Technologies
maintenance operations
hardware upgrades
Well-Managed
software upgrades
Unmanaged
35 days
Small
Business
4 days
ISPs &
Mainstream
Business
9.
8 hours
50 mins
Data
Centers
Banking
Medical
5 mins
Telco
Military
Defense
Scale-Up
Vertical
Expensive SMP hardware
Proprietary software
Platform lock-in
Fork Lift to increase capacity & performance
High Cost
Scale-Out
Horizontal
Commodity Intel/AMD hardware
Open source software
Low Cost
Platform independence
Add servers to increase capacity & performance
MySQL Replication
Writes & Reads
Web/App
Server
Writes
relay
binlog
mysqld
I/O
Thread
SQL
Thread
index &
binlogs
data
Replication
binlog
mysqld
MySQL Master
MySQL Slave
data
Reads
Master Server
Slave Server
Backups
MySQL Replication
Writes
Writes
Index &
Bin Log
Rotation
Possible Roles
Fail over server
Used for performing backups
Read/Write load balancing
Additional slaves allow Scale-Out
ual
Man ver
lO
Fai
Reads
ver Server
O
Slave
l
Fai
MasterXServer
Backups
MySQL Replication
X
Writes
Writes
Index &
Bin Log
Rotation
Possible Roles
Fail over server
Used for performing backups
Read/Write load balancing
Additional slaves allow Scale-Out
Linux Heartbeat
= Virtual IP =
10.10.10.10
Passive Server
Active Server
= Private IP =
10.10.10.20
Primary DRBD
= Private IP =
10.10.10.21
DRBD
Secondary DRBD
Linux Heartbeat
= Virtual IP =
10.10.10.10
ive Server
t
Passive
c
A
Active
X Server
= Private IP =
10.10.10.20
Primary DRBD
= Private IP =
10.10.10.21
DRBD
D
RB
D
Secondary
DRBD
ry
ma
Pri
MySQL
Server
MySQL
Server
MySQL
Server
MySQL
Server
MySQL
Server
NDB API
Data
Node
Data
Node
NDB
Storage Engine
Data
Node
Data
Node
MySQL Cluster
Management
Server
Management
Server
Capital
Country
UTC
Copenhagen
Denmark 2
Berlin
Germany 2
-5
Tokyo
Japan
Athens
Greece
Moscow
Russia
Oslo
Norway
Beijing
China
Partition 1
Partition 2
Data
Node
P1-Primary
P1-Secondary
P2-Secondary
P2-Primary
Partition 3
Node Group 1
Partition 4
Data
Node
Data
Node
Data
Node
P3-Primary
P3-Secondary
P4-Secondary
P4-Primary
Node Group 2
XMySQL
Server
MySQL
Server
MySQL
Server
MySQL
Server
MySQL
Server
NDB API
Data
Node
Data
X
Node
NDB
Storage Engine
Data
Node
Management
Server
Data
Node
Management
X
Server
MySQL Cluster
Patterns
Master/Slave Replication
Master with Read Only Slaves
Master to Master
Ring Replication
DRDB HA
DRBD Master Pair with Read Only Slaves
Master to Master Cross Datacenter + DRDB
Simple Sharding
Large Sharing/Scale-out solution + DRDB
Sharding + DRDB Fail-Over + Geographical
Redundancy
Asynchronous
Slave
MySQL
Replication
Advantages
Disadvantages
Slave 2
Slave 4
Slave 3
Master 2
Advantages
Disadvantages
Total insert/update/delete load is ~.5 one server or slaves
begin falling behind
Applications and schema must be designed to eliminate
duplicates that would break replication
Fail-back can be more complicated
Master 3
Asynchronous
MySQL
Master 2
Replication
Master 4
Advantages
Can read from or write any server
Works across WAN - Supports multiple geographical redundancy
BP - Use DRDB HA for each
Disadvantages
Total insert/update/delete load for all servers is ~.5 of typical load of one server
or slaves begin falling behind
Applications and schema must be designed to eliminate duplicates that would
break replication
Fail-over and Fail-back is very complicated
Pattern: DRBD HA
Hot Primary
Synchronous
DRBD
Replication
Warm Secondary
Advantages
No data loss
Can replicate from the pair via the fail-over VIP
Allows for heavier load on primary than replication on master
Fully automated fail-over when using Heartbeat
Very easy to rebuild old primary as new secondary after fail-over
Can be 3-4 9s Available
Disadvantages
Secondary is passive
30-300 Second delay in recovery after fail-over
Only works on Linux
Synchronous
DRBD
Replication
Warm Secondary
Master Pair
Shard A
Shard B
Shard C
Shard D