Monday, January 20, 2014

Load Balancing and Failover in JDBC Drivers

When you have to connect your java application to a database in a database cluster, using a JDBC driver, you can simply connect to one of the nodes of the cluster. (For example, if it's a MySQL cluster you can connect to one of its SQL nodes.) But what happens if that node goes down? You lose the connectivity to the cluster and high availability aspect too which is one of main intents of having a cluster. Connecting to a single node makes a single point of failure. How do we avoid this?

If we can achieve failover aspect, we can avoid above situation. And fortunately most of the JDBC drivers support failover (and load balancing too). Intent of this post is to list load balancing/failover supported JDBC URLs of some popular JDBC drivers.



Here, it is load balanced among given hosts. If a node is down while you're trying to connect, JDBC driver retries to connect for the given time period  (loadBalanceBlacklistTimeout). If the node is still down it tries to connect to another node. That's how failover is achieved by this.

SQL SERVER (Microsoft JDBC driver)


Here it supports only failover. If the active node is down, it connects to the failover (passive) node.



Please comment if you know URLs of any other JDBC Driver.

No comments:

Post a Comment