Overview of load balancers suitable for Docker environments
Microservices became one of very popular application architectures. It provides much greater opportunities for scalability, debugging and control than in monolith apps. But in order to use its full potential, you need to set up good environment and provide additional services for your app to ...
Microservices became one of very popular application architectures. It provides much greater opportunities for scalability, debugging and control than in monolith apps. But in order to use its full potential, you need to set up good environment and provide additional services for your app to interact with itself.
In this article I am going to review some services that can help you organize a great microservice application.
Load balancing
When your application begins to grow, a huge load might appear and you might need to scale your services to handle it. But at the same time there should be a way to balance load properly among instances of your service.
Traefik
Træfik
Traefik is a load balancer written in Go language. It is easy to configure and deploy. Especially if you use Docker containers for your app.
It provides a good UI to display your services, their health check and response times.
One of advantages of Traefik is that it provides routing features to map ports (entry points) to your services (backends) through configured domain and path rules (frontends).
Frontend rules allow to set up authentication, headers replacements and other things needed for your proxied services to expose for public.
Backend configuration provides features for health checking and load balancing strategies, available out of the box:
- wrr: Weighted Round Robin
- drr: Dynamic Round Robin: increases weights on servers that perform better than others. It also rolls back to original weights if the servers have changed.
If one of the servers suddenly begins to fail, a circuit breaker feature will not let your clients notice that
[backends.backend1.circuitbreaker] expression = "NetworkErrorRatio() > 0.5"
Another benefit is integrated support for key-value storages like
- Consul
- etcd
- ZooKeeper
- boltdb
Summary:
- Can be used for server configurations of any complexity
- Very easy configuration to use with Docker
- Integrated support for key-value services
Rancher balancer
Rancer docs
If you are using Rancher for managing your docker containers, it is a good option to use its integrated load balancing feature.
Rancher load balancer provides most of the features required for proxying: port forwarding, mapping of source and target ports of docker containers, health checking and server priorities.
It uses HAProxy under the hood and supports to add any additional configuration in addition to default features. (See Infra HTTP load-balancing using HaProxy - Viblo | Free service for technical knowledge sharing for more details)
Summary:
- Can be used for server configurations of any complexity
- Provided out of the box with Rancher panel
- Automatically applies configurations for services installed on the system
Nginx
Nginx docs
Nginx is one of the most popular web-server solutions. And one of its features is load balancing of several proxied servers.
As well as Traefik, it provides load balancing strategies in its configuration:
- round-robin — requests to the application servers are distributed in a round-robin fashion,
- least-connected — next request is assigned to the server with the least number of active connections,
- ip-hash — a hash-function is used to determine what server should be selected for the next request (based on the client’s IP address).
Nginx includes passive health checking the servers, which means that any failed request will be forwarded to next server.
In addition, paid solution, Nginx Plus, provided UI and additional features.
Summary:
- Might be hard to configure for use with complex architectures.
- Supports not only balancing servers, but also SCGI / FastCGI services.
- UI available only in paid version.