Load balancing
Load balancing distributes incoming traffic across multiple backend servers, improving availability and scalability. Quark supports several load balancing algorithms and can be configured to balance traffic for any service.
Basic configuration
Section titled “Basic configuration”To set up load balancing, you need to:
- Define a load balancer with a list of backend servers
- Reference that load balancer in a location’s target
[loadbalancers.my_backends]backends = ["192.168.1.10", "192.168.1.20", "192.168.1.30"]
[services.my_app]domain = "example.com"
[[services.my_app.locations]]source = "/*"target = "http://${my_backends}:8080"In this example, requests to example.com will be distributed across the three backend servers on port 8080.
Load balancing algorithms
Section titled “Load balancing algorithms”Quark supports different algorithms for distributing traffic:
Round Robin (default)
Section titled “Round Robin (default)”Distributes requests evenly across all backends in sequential order:
[loadbalancers.my_backends]algo = "round_robin" # Optional since it's the defaultbackends = ["192.168.1.10", "192.168.1.20", "192.168.1.30"]Each backend receives an equal share of requests in rotation.
Weighted Round Robin
Section titled “Weighted Round Robin”Allows you to assign different weights to backends, sending more traffic to servers with higher capacity:
[loadbalancers.my_backends]algo = "round_robin"backends = ["192.168.1.10", "192.168.1.20", "192.168.1.30"]weights = [5, 3, 2]In this configuration:
192.168.1.10receives 50% of requests (5/10)192.168.1.20receives 30% of requests (3/10)192.168.1.30receives 20% of requests (2/10)
IP Hash
Section titled “IP Hash”Routes requests from the same client IP to the same backend server, providing session persistence:
[loadbalancers.my_backends]algo = "ip_hash"backends = ["192.168.1.10", "192.168.1.20", "192.168.1.30"]