Skip to main content

Version: 3.2.3.x

Configure API Upstream

A single upstream URL may suffice for testing but enabling load balancing and health checks is highly recommended for production.

Prerequisites

  1. Obtain a User Account with Super Admin or API Provider Role.
  2. Complete Add Service from API Definition.

Configure 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. API7 Enterprise Edition supports a variety of load balancing algorithms. The default value is the weighted round-robin algorithm. This algorithm distributes incoming requests over a set of nodes based on their weight in a cyclical pattern.

In this tutorial, you will modify the load balancing method to Least Connection and add another node for high availability. For Least Connection, node with the lowest value of (active connections + 1) / weight will be picked.

  1. Select Services > your target service. In this tutorial, the Swagger Petstore service (See Add Service from API Definition) will be used as an example.
  2. Select Upstreams > your target upstream. In this tutorial, the default upstream will be used as an example.
  3. Click Upstream Configuration > Edit.
  4. Change the Load Balancing Type to Least Connection.

Update Load Balancing Type

  1. Click Nodes > Add Node.
  2. Enter another mock server address as the second node. Set the weight to 100 as the same of the first node to make the two nodes equal.

Add Node 2

  1. Click Update.

Validate

for i in {1..10}; do curl -v http://127.0.0.1:9080/pet/1; done

You can see the response from two different nodes.

From node1:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 323
Connection: keep-alive
Date: Fri, 01 Sep 2023 10:11:27 GMT
x-srv-trace: v=1;t=e20ed9789ce8d5aa
x-srv-span: v=1;s=2993fb8bc11de3bd
Access-Control-Allow-Origin: *
X-RateLimit-Limit: 120
X-RateLimit-Remaining: 119
X-RateLimit-Reset: 1693563147
ETag: W/"143-JIrwO+Sx1/7FTTpJ2ljwAfgaRCY"
Vary: Accept-Encoding
Server: APISIX/dev

{
"name": "Dog",
"photoUrls": [
"https://example.com/dog-1.jpg",
"https://example.com/dog-2.jpg"
],
"id": 1,
"category": {
"id": 1,
"name": "pets"
},
"tags": [
{
"id": 1,
"name": "friendly"
},
{
"id": 2,
"name": "smart"
}
],
"status": "available"
}

From node2:

HTTP/1.1 404 NOT FOUND
Content-Type: text/html; charset=utf-8
Content-Length: 233
Connection: keep-alive
Date: Fri, 01 Sep 2023 10:11:27 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Server: APISIX/dev

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>

Configure Health Check

Health checking is a mechanism that determines whether upstream nodes are healthy or unhealthy based on their responsiveness. With health checks enabled, API7 Enterprise Edition will only forward requests to upstream nodes that are considered healthy, and not forward requests to the nodes that are considered unhealthy.

There are two general approaches to health check:

  • Active health checks: API7 Enterprise Edition determines the health of an upstream node by actively probing the node.
  • Passive health checks: API7 Enterprise Edition determines the health of an upstream node based on how the node responds to user requests without initiating additional probes. Passive checks must be used with active checks. They cannot be used alone.

This tutorial will show you how to configure both active and passive health checks for your upstream.

  1. Select Services > your target service. In this tutorial, the Swagger Petstore service (See Add Service from API Definition) will be used as an example.
  2. Select Upstreams > your target upstream. In this tutorial, the default upstream will be used as an example.
  3. Click Active Health Check > Enable.
  4. Use the default value and click Enable.
  5. Click Passive Health Check > Enable.
  6. Use the default value and click Enable.

API7.ai Logo

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

Product

API7 Cloud

SOC2 Type IIISO 27001HIPAAGDPRRed Herring

Copyright © APISEVEN PTE. LTD 2019 – 2025. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the

Apache Software Foundation