Using MySQL for Distributed Database
Architectures
Peter Zaitsev
CEO, Percona
Percona Technical Webinars
July 31, 2018
© 2018 Percona.
1
Presentation
Cover Basics
Why Going Distributed
How to do it
© 2018 Percona.
2
Distributed ?
MySQL Deployment on More
than one System
© 2018 Percona.
3
Modern MySQL Scalability
© 2018 Percona.
4
Even more Modern MySQL Scalability
© 2018 Percona.
5
Single MySQL Instance Can Do
Hundreds of Thousands of Queries/Sec
Tends of Thousands of Updates/Sec
Traverse Tens of Millions of Rows/Sec
Comfortably Handle Several TB Database size
© 2018 Percona.
6
Lets Do Some Math
100.000 QPS
10 Queries per User Interaction
10.000 User Interactions/sec
864.000.000 User Interactions/Day
30 User Interactions/User Avg
28.000.000 Daily Active Users Possible
15M of Daily Active Users counting time of day skew
© 2018 Percona.
7
Distributed Systems Tend To be
More Complicated to Develop Against
More Complicated to Operate
Have Additional Performance Bottlenecks
Have Complicated Failure Modes
© 2018 Percona.
8
With All of this ?
Why “Go Distributed” ?
© 2018 Percona.
9
Reasons to “Go Distributed”
High Data
Scalability
Availability Distribution
© 2018 Percona.
10
High Availability with MySQL
Cold Standby (ie DRBD)
Failover (Classical Replication)
Active-Active Clustering (PXC, MySQL Group Replication)
© 2018 Percona.
11
Q1:What Failure Modes Do you Consider ?
Server Crash/Server Hardware Failure
Software Bugs and Storage Corruption
Network Failure
“Datacenter” Failure
Developer Mistakes/Intruder Actions
© 2018 Percona.
12
Q2:What Data Am I allowed to lose ?
Limited Data Loss Allowed
No Data Loss
No Transactions In Flight Loss
© 2018 Percona.
13
Q3:How Quickly do you need to Recover ?
“Immediate?”
“Seconds?”
“Minutes?”
“Hours?”
© 2018 Percona.
14
Speed of Light Realities
Data •Synchronous – Slow
Propagation •Asynchronous –
Can Be Data Loss Can Occur
© 2018 Percona.
15
Scalability
Scaling Scaling Scaling
Reads Writes Data Size
© 2018 Percona.
16
Data Distribution
Some Data
Must be in •User Latency Reasons
Specific •Legal and Compliance
Geographic Reasons
Location
© 2018 Percona.
17
Distributed Architectures with MySQL
© 2018 Percona.
18
Main Concepts
Replication
Sharding
Failover Management
Traffic Management
© 2018 Percona.
19
Replication
Having Multiple Copies of the
data, updated with changes
© 2018 Percona.
20
Availability
Service Stays up when
component fails
© 2018 Percona.
21
Availability via Redundancy
Have more than one system
Works well for stateless systems
Is not enough for databases
© 2018 Percona.
22
Availability via Replication
Redundant Paired with
Computing Replicated
Resource Data
© 2018 Percona.
23
Where Replication Happens
Storage Level
Database Level
Application Level
© 2018 Percona.
24
Storage Level Replication
Replication in SAN/NAS, DRBD
Typically provides cold standby
Simple choice which works with many systems
Amazon Aurora – Smart Storage
© 2018 Percona.
25
Database level
Most Flexible
Most Common
Hot/Warm Spare
Some can do Active-Active
© 2018 Percona.
26
Application Level
Hard to get right
Rarely used, especially “used right”
Partial Replication/Syncronization
Smart conflict resolution
Cross Vendor Redundancy
© 2018 Percona.
27
Sharding
Split data set by certain criteria
and store such “shards” on
separate “clusters”
© 2018 Percona.
28
Typical Sharding
By User
By Customer Account/Company
© 2018 Percona.
29
Sharding and Replication
Sharding Almost Always
used with some kind of
Replication
© 2018 Percona.
30
Failover Management
Many Replication Modes Require “Failover”
Need some Tool To Decide on Failover
Need some Tool to Perform Failover
© 2018 Percona.
31
Traffic Management
Scaling with Large Number of Connections
Routing Traffic to Right “Shard”
Read-Write Splitting
Load Management
Avoiding “Dead” Nodes
© 2018 Percona.
32
Options in MySQL
© 2018 Percona.
33
Replication Options in MySQL
Classical MySQL Replication
MySQL Group Replication
Percona XtraDB Cluster and Galera
MySQL (NDB) Cluster
© 2018 Percona.
34
Classical MySQL Replication
© 2018 Percona.
35
Classical MySQL Replication Properties
Asynchronous or Semi-Synchronous
Parallel (since MySQL 5.7)
Many Masters to Many Slaves (MySQL 5.7)
No Conflict Resolution or “Protection”
No Built-in Failover
© 2018 Percona.
36
Advanced MySQL Replication Topologies
© 2018 Percona.
37
PMM Dashboard for Replication
© 2018 Percona.
38
MySQL Group Replication
© 2018 Percona.
39
MySQL Group Replication (New in 5.7)
“Group of Peers”
Write-Anywhere or Dedicated Writer
Asynchronous Replication with Flow Control
Conflicts Prevented through Certification
Built in Failover
No Automated Provisioning
© 2018 Percona.
40
Percona XtraDB Cluster/Galera
© 2018 Percona.
41
Percona XtraDB Cluster Topology
© 2018 Percona.
42
PXC/Galera Properties
Write to Any Node
Certification Based Replication
Virtually Synchronous; Can ensure no stale reads
Built in Fail-Over
Built-in Node Provisioning
© 2018 Percona.
43
Transaction Commit Flow
© 2018 Percona.
44
PXC 5.7 Performance Improvements
http://bit.ly/2qGCr0T and http://bit.ly/2pzvAIW
© 2018 Percona.
45
PMM Dashboard for PXC
© 2018 Percona.
46
MySQL Cluster
Mostly In Memory Storage
Synchronous Replication
Pessimistic Locking
Conflict Detection with Async Replication
Niche Use Only
© 2018 Percona.
47
Sharding in MySQL
Typically Painful or Very Painful
No Built-In or Standard Solution
Many Custom App-Layer Implementation Exists
© 2018 Percona.
48
Thinking about Sharding
Query Routing to the right Shard
Data Aggregation for Cross-Shard Queries
Shard Balancing
© 2018 Percona.
49
Vitess
Stated by team in YouTube
Now Open Source in CNCF
Deployed at Slack
Supports MySQL Protocol
Supports Cross Shard Queries
Supports Re-Sharding
© 2018 Percona.
50
Vitess Architecture
© 2018 Percona.
51
Failover in MySQL
MHA
MySQL Failover
Orchestrator
© 2018 Percona.
52
Orchestrator Screenshot
© 2018 Percona.
53
Traffic Management Solutions
DNS • Not Immediate, Does not handle existing connections
HAProxy • TCP/IP Port level. Does not understand MySQL Protocol
Elastic Load Balancer (etc) • Like HA Proxy in the Cloud
MySQL Router • Currently very basic
MaxScale, ScaleArc • Proprietary Solutions
ProxySQL • MySQL Protocol Aware 100% Open Source Proxy Solution for MySQL
© 2018 Percona.
54
ProxySQL
• 100% OpenSource
• Well Supported
• Read-Write Splitting
• Caching
• Query Rewrites
• Load Balancing
• 10k+ Connection Support
© 2018 Percona.
55
Dedicated shared ProxySQL 5
6
application server 1 application server 2 application server 3
ProxySQL
PXC node 1 PXC node 2 PXC node 3
© 2018 Percona.
56
ProxySQL on application side 5
7
application server 1 application server 2 application server 3
ProxySQL ProxySQL ProxySQL
PXC node 1 PXC node 2 PXC node 3
© 2018 Percona.
57
ProxySQL at PMM
© 2018 Percona.
58
Cloud Only Options
DBaaS in
•Amazon RDS
the cloud
•Amazon Aurora
comes with
•Google Cloud SQL
built-in HA •Azure Database for MySQL
Options
© 2018 Percona.
59
Beyond MySQL
© 2018 Percona.
60
MySQL is a Part of your Data Infrastructure
MySQL is Good for Many
Things but MySQL is not
Good for Everything
© 2018 Percona.
61
MySQL can be used together with
Full Text Queue/Stream Analytics at
Caching
Search Processing Scale
• Redis, • Elastic, Solr • Kafka • Hadoop,
Memcache Clickhouse
© 2018 Percona.
62
Cross Technology Replication
Trigger Based • SymmetricDS, Self-Made Solution
Replication Tools
Kafka Gateway • Debezium, Yelp’s MySQLStreamer
Tungsten Replicator • Replication from MySQL to Variety Data Stores
Custom Binary Log • MySQL to Tarantool Replication
Consumers • MySQL to ClickHouse Replication
© 2018 Percona.
63
Summary
Lots of Options Exist for Building
Distributed Architectures with MySQL
Lots of Option for Integrating MySQL
with other Open Source Data Stores
© 2018 Percona.
64
November 5-7th, 2018
Call for Papers Open! Get Your Tickets for Percona
Connect. Accelerate. Innovate. Live Europe!
● We’re delighted to be in Frankfurt this year! A
● MySQL, MongoDB, PostgreSQL & other Open Source vibrant city, in a central location with many direct
Databases flights makes it easy for you to get here!
● Security, Open Source Databases, Serverless, Cloud ● Percona Live Europe 2018 includes a new
or On Premise business track that covers the best ideas for how
● High Availability, Scalability open source databases and database
● Business Goals, Case Studies, What the Future Holds technologies can address and solve business
● Radisson Blu Hotel, Frankfurt, Germany issues such as application time-to-market,
resource costs, OPEX and CAPEX expenses, etc.
Submit Your Proposal by August 10th! Super Saver Tickets Available Until
August 19th!
Prices Increase on the 20th!
© 2018 Percona.
65
www.percona.com/live/e18/
Thank You!
© 2018 Percona.
66