Skip to main content

Version: 3.9.0

Load Balancing

Load balancing is a technique used to distribute network request loads. It is a key consideration in designing systems that need to handle a large volume of traffic, allowing for improved system performance, scalability, and reliability

Apache APISIX supports a number of load balancing algorithms, one of which is the weighted round-robin algorithm. This algorithm distributes incoming requests over a set of servers in a cyclical pattern.

In this tutorial, you will create a route with two upstream services and uses the round-robin load balancing algorithm to load balance requests.


  1. Complete Get APISIX to install APISIX.
  2. Understand APISIX Route and Upstream.

Enable Load Balancing

Create a route with two upstream services, and, to distribute requests across. Both services respond with the request headers when receiving request at /headers:

curl -i "" -X PUT -d '
"id": "getting-started-headers",
"uri": "/headers",
"upstream" : {
"type": "roundrobin",
"nodes": {
"": 1,
"": 1
"pass_host": "node",
"scheme": "https"

type: use roundrobin as the load balancing algorithm.

nodes: upstream services.

pass_host: use node to pass the host header to the upstream.

scheme: use https to enable TLS with upstream.

You should receive an HTTP/1.1 201 Created response if the route was created successfully.


Generate 50 consecutive requests to APISIX /headers route to see the load-balancing effect:

resp=$(seq 50 | xargs -I{} curl "" -sL) && \
count_httpbin=$(echo "$resp" | grep "" | wc -l) && \
count_mockapi7=$(echo "$resp" | grep "" | wc -l) && \
echo $count_httpbin, $count_mockapi7

The command keeps count of the number of requests that was handled by the two services respectively. The output shows that requests were distributed over to the two services: 23, 27

What's Next

You have learned how to configure load balancing. In the next tutorial, you will learn how to configure key authentication. Logo

API Management for Modern Architectures with Edge, API Gateway, Kubernetes, and Service Mesh.


API7 Cloud

SOC2 Type IRed Herring

Copyright © APISEVEN Ltd. 2019 – 2024. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the

Apache Software Foundation