Skip to main content

Configure Load Balancing

Decide how the gateway spreads requests across the instances of the service, and whether a client stays on the same instance.

How it works​

When the service has several instances, the gateway chooses one per request. Round robin suits identical instances and short requests. Choose another algorithm when request durations vary widely, or when the same caller must reach the same instance.

Affinity breaks on scaling

With consistent hashing, adding or removing an instance sends part of the callers to a different instance. Do not keep session state only in memory.

Every parameter and its default: reference.

Use cases​

When instances are not interchangeable (a session kept in memory) or when requests differ a lot in cost.

Prerequisites​

  • An API instance that is deployed and answers.
  • A service running several instances.

Procedure​

  1. In API Manager, go to API Instances and open the API. To cover everything published on a gateway instead, open the gateway.
  2. Open its Backend traffic policies and add the rule load balancing.
  3. In Algorithm, choose how requests are spread.
  4. Turn Session Persistence on to keep a client on the same instance.
  5. Deploy.

Parameters​

FieldWhat it isDefault
AlgorithmRound Robin: each instance in turn. Least Request: the least busy. Random. Consistent Hash: the same client to the same instance.Round Robin
Session PersistenceKeep the requests of a client on the same instance.Off

Behavior and limits​

  • Least Request suits requests of very different durations.
  • Keeping a client on one instance is a workaround: a service that keeps nothing in memory scales and restarts better.

See also​