Friday, May 15, 2020

Which Cluster is Suitable for Your Application Workload:MySQL InnoDB Cluster or MySQL NDB Cluster ?



Introduction

MySQL offers two types of clustering solution for managing Read/Write intensive workloads , ensuring Rock Solid Availability.
1.MySQL InnoDB Cluster
2. MySQL NDB Cluster
Glimpse of MySQL InnoDB Cluster
   This Cluster is designed for users that uses MySQL Server with InnoDB storage engine.
   It will serve as a natural extension for users currently using MySQL Replication with InnoDB to a       new replication architecture i.e Clustering on top of Group Replication.
MySQL InnoDB Cluster = MySQL Server + MySQL Shell + MySQL Router.
MySQL Server
  • Group Replication Technology.
  • Single-Primary /Multi-Primary Mode.
  • Fault Tolerance.
  • Conflict detection and resolution.
  • Automatic distributed recovery.
MySQL Shell
  • Multi-Language(Python , Java script , SQL).
  • Administrator API. 
  • Create and manage InnoDB Cluster.
  • Perform DBA operations.
MySQL Router
  • Transparent client connection routing.
  • Load Balancing and Fail-over.
  • No configuration needed.
Note:- Minimum MySQL Server needed for InnoDB Cluster = 03 , Maximum = 09.
Glimpse of  MySQL NDB Cluster
 This Cluster is based on NDB storage engine which is a distributed real time in-memory network database.
 It is tightly integrated solutions ,which mean it doesn't have a non-clustering mode.
MySQL NDB Cluster = Data Node + Application Node + Management Node                        
Data Node
  • Data Storage(Memory , Disk).
  • Automatic & User defined partitioning.
  • Scale out for capacity and performance.
Application Node
  • C++/Java APIs
  • Real time Applications
  • Automatic fail-over & load balancing.
  • Standard SQL interface
  • Enables GEO Replications
Management Node
  • Management, Monitoring & Configuration.
  • Arbitrator for split brain/network partitioning.
  • Cluster logs.
Minimum Data node needed :- 02 || maximum Data node needed : 48

What is difference between InnoDB and NDB storage engine ?

So What is differences between MySQL InnoDB Cluster and MySQL NDB Cluster ?

I. Basic Differences

MySQL InnoDB Cluster  can scale upto 09 nodes , where as MySQL NDB Cluster can scale upto 48 data nodes.
MySQL InnoDB Cluster can't execute cross-shard transactions , where as MySQL NDB Cluster can do.

II. Architecture Differences
MySQL InnoDB Cluster


This cluster can run into either single master/primary mode or multi-master mode.     
Transaction work flow will be same in both mode of operations.

Let us take an example , Fig-  which is running one Master database(write/read) and two participant database(read slave). all write transactions have to be routed to the master server. Read transactions can go to either to one of the participant servers.
The MySQL Router is an important tool to ensure that transaction coming from app will go on which database node.
when router starts it open two port for application , one port 6446 - Read/Write and another port 6447- Read only.
In this Architecture , it requires application distinguish read transactions from write transactions and it means that an app can only guaranteed to see its own updates if it uses the same master MySQL server all the time.
Also , When app send transaction to group of MySQL server via Router then it uses PAXOS protocol to ensure that participants arrive at the same commit order. The committer has to wait until a majority of participants in the group has received the transaction and couple of rounds to ensure that all nodes comes to same commit derision.  

Technically ,InnoDB Cluster provides more read scalability than write scalability.
MySQL NDB Cluster
In this architecture , MySQL Router is not needed for MySQL Cluster although it is possible.

Direct App connectivity provided to talk with Cluster Data Node.

Another differences is with MySQL Cluster , all MySQL Servers see the same data , thus you can send the query to any MySQL Server connected to the cluster. each MySQL can read and update data in the entire cluster.

Also , MySQL Cluster has In-built Shared capabilities so that app can scale well write + read intensive workloads with MySQL Cluster.
The MySQL InnoDB Cluster solution is aimed at building highly available solutions with read scaling.

III. Sharding Differences
MySQL Cluster runs distributed transactions over all shards(=NODE GROUP) and it can run both updating transactions as well as read queries over multiple shards. MySQL InnoDB Cluster don't have same features. application has to solved this sharding technique.

IV. Query Execution Differences
Query Execution in InnoDB Cluster is single threaded where as NDB cluster can push down query condition evaluation to data nodes.These are evaluated in parallel if scans are sent to multiple partitions.In addition cluster can push down joins to the NDB data nodes.
Thus MySQL NDB Cluster can achieve substantial parallelism in the execution of a single query.

V. Handling Node Failures Differences

MySQL InnoDB Cluster requires three server to handle one node failures
( Formula #  No of Server = 2* No of failures + 1 ). it can't continue to service updates when two nodes have failed out of three since it can't form majority (PAXOS protocol ) in that case.

In MySQL Cluster which nodes are to survive is based on heartbeat protocol , this protocol contains all data nodes in cluster, A surviving set of nodes must have at least one node in each Node Group(== Shard).
In case of 02 data nodes in 01 node group and one of them fails, the surviving node will still be able to continue if it can access the arbitrator(Management Node) and arbitrator accepts its request to form new cluster. if arbitrator fails, cluster will select a new one immediately.

In case of Network partitioning 50/50 situation, MySQL Cluster uses Arbitrator to solve n/w partitioning,  and MySQL InnoDB Cluster use Quorum to solve it but in different way.

In short , MySQL NDB Cluster can still run with 01 replicas in Node Groups where as with MySQL InnoDB Cluster needed 02 replicas to run and accepts transactions.

Also, MySQL NDB Cluster tries to maintain the cluster to be available for insert/update/delete all the time where as InnoDB Cluster it is ok to enter into read-only mode for some time and do mannual intervention to decide which parts that should survive.



Below tables described as summary of differences.


What Clustering Solution to CHOOSE ?

I. Based on Real Time Behavior
MySQL NDB Cluster is designed for predictable response time due to in-memory capabilities. it can provide 100 % of the responses within time limits of down to hundreds of microseconds for demanding telecom and financial applications.

Many of our customers requires 100% of responses of complex transactions to complete within milliseconds this makes it impossible to use a solution based on disk-based storage. thus Innodb cluster has challenged to provide predictable response time.

II.Based on Availability
MySQL NDB Cluster requires minimum 2 replicas to stay available whereas InnoDB Cluster requires 3 replicas to stay highly available. 

MySQL NDB Cluster doesn't support replication using GTIDs , semi-sync replication where as InnoDB Cluster does support it.

Both Clustering Solution delivers progressively high availability levels, with MySQL NDB Cluster designed to delivered 99.9999% uptime where as MySQL InnoDB Cluster 99.99% uptime.

Both Clustering Solutions uses Asynchronous Replication to wire one cluster DC 1 to another DC 2.

III.Based on Scalability
Both Clustering Solutions scale very well for reads, for write scaling NDB will scale to many (node groups ==shards) without changing the application code.

MySQL NDB Cluster scales to millions of update transactions per second, MySQL InnoDB Cluster scales to ten of thousands of update transactions per second

IV. Based on Storage Engine Feature Set
InnoDB Support Max row size of ~65K bytes where as NDB has limitation of 14K bytes.

InnoDB supports fulltext indexes, NDB doesn't support it.

InnoDB runs all queries using a single thread that runs inside the MySQL Server. NDB runs queries in a number of threads that corporate and queries are automatically parallelised when more than one partition is used in the query.
NDB supports pushing down joins into the data node where they will execute with some level of parallelism.

InnoDB uses B-Tree structure for primay key as well as secondary key , where as NDB always uses main memory hash index for primary key and T-tree structure for ordered index.

I would always recommended to look for limitations/FAQ before you certify for any of those clustering solutions.

Conclusion :-

MySQL NDB Cluster was originally designed for telecom servers that require constant uptime, it was designed for scalability to a large number of nodes while still maintaining consistency of its data.
                                             There are many areas where MySQL InnoDB Cluster will be beneficial. it will be a more natural alternative for existing Master- slave replication where needed Always-On situation for application workloads.
No doubt , InnoDB has rich set of features than NDB storage engine and more useful for designing general purpose application.

Feel Free to give feedback.

Next , Blog i will talk about how transaction works in NDB Cluster.

No comments:

Post a Comment