Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7...

42
2 © The Pythian Group Inc., 2018 June 21, 2018 - DataOps Barcelona Barcelona, Spain Implementing MySQL Database-as-a-Service using Open Source tools Matthias Crauwels

Transcript of Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7...

Page 1: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

2© The Pythian Group Inc., 2018

June 21, 2018 - DataOps BarcelonaBarcelona, Spain

Implementing MySQL Database-as-a-Service using Open Source toolsMatthias Crauwels

Page 2: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

© The Pythian Group Inc., 2018 3

Who am I?

Page 3: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

© The Pythian Group Inc., 2018 4

4© The Pythian Group Inc., 2017

Matthias Crauwels● Living in Ghent, Belgium● Bachelor Computer Science● ~20 years Linux user / admin● 10+ years PHP developer● 5+ years MySQL DBA● ~1 year at Pythian as MySQL

Database Consultant● Father of Leander

Page 4: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

© The Pythian Group Inc., 2018 5© The Pythian Group Inc., 2018 5

PYTHIAN

A global IT company that helps businesses leverage disruptive technologies to better compete.

Our services and software solutions unleash the power of cloud, data and analytics to drive better business outcomes for our clients.

Our 20 years in data, commitment to hiring the best talent, and our deep technical and business expertise allow us to meet our promise of using technology to deliver the best outcomes faster.

Page 5: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

6© 2018 Pythian. Confidential

AI / ML / BLOCKCHAIN

Intelligent analytics and decision making

Software autonomy

Disruptive data technologies

CLOUD MIGRATION & OPERATIONS

Plan, Migrate, Manage, Optimize, Innovate

Multi-cloud, Hybrid-Cloud, Cloud Native

ANALYTIC DATA SYSTEMS

Kick AaaS cloud-native, pre-packaged analytics platform

Custom analytics platform design, implementation and support services–for on-premises and cloud

Data science consulting and implementation services

OPERATIONAL DATA SYSTEMS

Database services–architecture to ongoing management

On prem and in the cloud

Oracle, MS SQL, MySQL, Cassandra, MongoDB, Hadoop, AWS/Azure/Google DBaaS

Page 6: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

7© The Pythian Group Inc., 2018

AGENDA

7

● Introduction

● History

● Database-as-a-Service: Frontend solution

● Database-as-a-Service: Backend management

● Overview

● Questions

Page 7: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

8© The Pythian Group Inc., 2018

Let’s get started!

Page 8: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

9© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 9

You start a new application, in many cases on a LAMP stack

● Linux● Apache● MySQL● PHP

Everything on a single server!

History

Page 9: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

10© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 10

Your application grows… What do you do?

You buy a bigger server!

History

Page 10: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

11© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 11

You application grows even more! Yay!

You buy more servers and split your infrastructure!

History

Database

Web server File server

Page 11: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

12© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 12

Your application grows even more!

● You scale up the components● Web servers are easy, just add more and load balance● File servers are easy, get more/bigger disks, implement RAID solutions, ...● What about the database??

■ More servers? ● Ok but what about the data?

■ I want all my web servers to see the same data.● Writing it on all the servers? Overhead!

History

Page 12: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

13© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 13

MySQL replication!

● Writing to master● Reading from replica’s (slaves)

History

Page 13: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

14© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 14

Million dollar questions

● How do we know what server is the master?● How do we know which servers are the replica’s?● How do we manage this replication topology?● What if the master goes down?● What about maintenance?● …

History

Page 14: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

15© The Pythian Group Inc., 2018

Database-as-a-Service

Frontend Solution

Page 15: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

16© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 16

ProxySQL

Page 16: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

17© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 17

ProxySQL is a high performance layer 7 proxy application for MySQL.

● It provides ‘intelligent’ load balancing of application requests onto multiple databases

● It understands the MySQL traffic that passes through it, and can split reads from writes.

● It understands the underlying database topology, whether the instances are up or down

● It shields applications from the complexity of the underlying database topology, as well as any changes to it

● ...

ProxySQL: what?

Page 17: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

18© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 18

● HostgroupAll backend MySQL servers are grouped into hostgroups. These “hostgroups” will be used for query routing.

● Query rulesQuery rules are used for routing, mirroring, rewriting or blocking queries. They are at the heart of ProxySQL’s functionalities

● MySQL users and serversThese are configuration items which the proxy uses to operate

ProxySQL: terminology

Page 18: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

19© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 19

ProxySQL: basic design (1)

Page 19: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

20© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 20

ProxySQL: basic design (2)

Page 20: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

21© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 21

ProxySQL: internals

Page 21: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

22© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 22

ProxySQL will be configured to share configuration values with its peers. Currently all instances are equal and can be used to reconfigure, there is no “master” or “leader”. This a feature on the roadmap.

Helps to:

● avoid your ProxySQL instance to be the single point of failure● avoid having to reconfigure every ProxySQL instance on the

application server

ProxySQL: clustering

Page 22: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

23© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 23

ProxySQL exists between the application and the database.

● It hides the complexity of the database topology to the application● It knows which server is the master and which are the slaves● It will not make changes to the topology so topology management

is not solved with this product. ● It has support for gracefully taking a server out of service● It is easy to configure● It can be clustered for not being a single-point-of-failure

ProxySQL: conclusions

Page 23: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

24© The Pythian Group Inc., 2018

Question about ProxySQL?

Page 24: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

25© The Pythian Group Inc., 2018

Database-as-a-Service

Backend management

Page 25: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

26© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 26

Orchestrator

Page 26: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

27© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 27

Orchestrator is a High Availability and replication management tool.

It can be used for:

● Discovery of a topology● Visualisation of a topology● Refactoring of a topology● Recovery of a topology

Orchestrator: what?

Page 27: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

28© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 28

Orchestrator can (and will) discover your entire replication technology as soon as you connect it to a single server in the topology.

It will use SHOW SLAVE HOSTS, SHOW PROCESSLIST, SHOW SLAVE STATUS to try and connect to the other servers in the topology.

Requirement: the orchestrator_topology_user needs to be created on every server in the cluster so it can connect.

Orchestrator: discovery

Page 28: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

29© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 29

Orchestrator comes with a web interface that visualizes the servers in the topology.

Orchestrator: visualization

Page 29: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

30© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 30

Orchestrator can be used to refactor the topology.

This can be done from the command line tool, via the API or even via the web interface by dragging and dropping.

You can do things like

● Repoint a slave to a new master● Promote a server to a (co-)master● Start / Stop slave● ...

Orchestrator: refactoring

Page 30: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

31© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 31

All of these features are nice, but they still require a human to execute them. This doesn’t help you much when your master goes down at 3AM and you get paged to resolve this.

Orchestrator can be configured to automatically recover your topology from an outage.

Orchestrator: recovery

Page 31: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

32© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 32

To be able to perform a recovery, Orchestrator first needs to detect a failure.

As indicated before Orchestrator connects to every server in the topology and gathers information from each of the instances.

Orchestrator uses this information to make decisions on the best action to take. They call this the holistic approach.

Orchestrator: how recovery works?

Page 32: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

33© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 33

Orchestrator: failure detection example

Page 33: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

34© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 34

Orchestrator was written with High Availability as a basic concept.

You can easily run multiple Orchestrator instances with a shared MySQL backend. All instances will collect all information but they will allow only one instance to be the “active node” and to make changes to the topology.

To eliminate a single-point-of-failure in the database backend you can use either master-master replication (2 nodes) or Galera synchronous replication (3 nodes).

Orchestrator High Availability

Page 34: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

35© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 35

Since version 3.x of Orchestrator there is “Orchestrator-on-Raft”.

Orchestrator now implements the ‘raft consensus protocol’. This will

● Ensure that a leader node is elected from the available nodes● Ensure that the leader node has a quorum (majority) at all times● Allow to run Orchestrator without a shared database backend● Allow to run without a MySQL backend but use a sqlite backend

Orchestrator High Availability

Page 35: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

36© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 36

A common example of a High Availability setup

● 3 Orchestrator nodes in different DC’s● Often one primary DC, one backup DC and one “arbitrator” node in a

cloud DC.● Orchestrator developers have made changes to raft protocol to allow

■ leader to step down■ other nodes to yield to a certain node to become the leader

● Shlomi Noach from GitHub will definately go into more detail on how they implemented this at GitHub.

Orchestrator High Availability

Page 36: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

37© The Pythian Group Inc., 2018

Questions about Orchestrator?

Page 37: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

38© The Pythian Group Inc., 2018

Overview

Page 38: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

39© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 39

Architecture overview

APP(S)

Leader

Page 39: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

40© The Pythian Group Inc., 2018

Questions?

Page 40: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

41© The Pythian Group Inc., 2018

Credits

Page 41: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

42© The Pythian Group Inc., 2018© The Pythian Group Inc., 2018 42

Credits go to:

● René Cannaò and Derek Downey for the images on ProxySQL internals and overview. Taken from their “ProxySQL Tutorial” on Percona Live 2016.

● Shlomi Noach for the Orchestrator screenshots taken from the Orchestrator manual and from his “Orchestrator at GitHub” blogpost.

Credits

Page 42: Implementing MySQL Database-as-a-Service using Open …...ProxySQL is a high performance layer 7 proxy application for MySQL. It provides ‘intelligent’ load balancing of application

ContactMatthias Crauwels

[email protected]

+1 (613) 565-8696 ext. 1215