How to Connect to Multiple Elasticsearch Client Nodes Without a Load Balancer

By: Steve Croce

Posted on: November 10, 2017

Since all ObjectRocket for Elasticsearch clusters come with multiple client nodes, one of the common questions we get from our customers is why we don’t provide a load balancer to connect to all of them.

Many see a single connection to a single node as key point of failure for the cluster, so they’ve requested some kind of load balancer to manage a pool of connections.

The simple answer is that Elasticsearch is designed specifically to not need a load balancer. In this blog, let’s walk through all of the ways that Elasticsearch allows you to use all of the clients we provide.

Load balancing is built into the client

Almost every key Elasticsearch client allows you to provide multiple client endpoints and handles the load balancing internally. The method used can differ from client to client, but for the most part, they will use a round-robin scheme to loop through the available clients

The majority of the tools and clients out there support multiple hosts in this way and to make it easy for you, we include connection snippets in the ObjectRocket UI for Python, Ruby, C#, Java, Javascript, Go, Logstash, and Beats. You can just pick the technology you’re using and then copy the snippet with your hostnames pre-populated.

Alternatives for applications that won’t take multiple hosts

Though it’s uncommon, there are a few applications that don’t take a list of hosts. The most notable is Kibana, which can only accept a single host. To work around this, there are a couple of alternatives.

Point each part of your app at a different client

For non-mission-critical uses and applications, it is perfectly acceptable to point at a single client node. Unless the application has a super-high request rate, a single client should be able to easily manage the load. If you have a number of these types of applications, just point each one at a different client to balance the load.

Load balance locally

In the few cases where the client/application doesn’t support it and you really need redundancy in client connections, another option is to set up some local load-balancing You can do this with something like nginx and HAProxy, or you can just set up a local hostname in DNS that will round-robin between the Elasticsearch clients. Once again, we see very few cases where this is absolutely needed, but there are solutions available when it does come up.

Conclusion

The bottom line is that almost every scenario you come across will allow you to supply a list of hosts and handle the balancing for you, but in a pinch, there are examples out there to help you load balance locally when you need to.