Skip to main content
Version: 3.4

Load Balancing

The Getting Started tutorials are contributed by

Load balancing manages traffic between clients and servers. It is a mechanism used to decide which server handles a specific request, allowing for improved performance, scalability, and reliability. Load balancing is a key consideration in designing systems that need to handle a large volume of traffic.

Apache APISIX supports weighted round-robin load balancing, in which incoming traffic are distributed across a set of servers in a cyclical pattern, with each server taking a turn in a predefined order.

In this tutorial, you will create a route with two upstream services and enable round-robin load balancing to distribute traffic between the two services.


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

Enable Load Balancing#

Let's create a route with two upstream services. All requests sent to the /headers endpoint will be forwarded to and, which should echo back the requester's headers.

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

You will receive an HTTP/1.1 201 OK response if the route was created successfully.

  1. The pass_host field is set to node to pass the host header to the upstream.
  2. The scheme field is set to https to enable TLS when sending requests to the upstream.


The two services respond with different data.


"headers": {
"Accept": "*/*",
"Host": "",
"User-Agent": "curl/7.58.0",
"X-Amzn-Trace-Id": "Root=1-63e34b15-19f666602f22591b525e1e80",
"X-Forwarded-Host": "localhost"


"headers": {
"accept": "*/*",
"host": "",
"user-agent": "curl/7.58.0",
"content-type": "application/json",
"x-application-owner": ""

Let's generate 100 requests to test the load-balancing effect:

hc=$(seq 100 | xargs -i curl "" -sL | grep "httpbin" | wc -l); echo $hc, $((100 - $hc))

The result shows the requests were distributed over the two services almost equally: 51, 49

What's Next#

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