Load balancer

This policy balances incoming requests among backend endpoints to improve performance and reliability.

Through Load balancer policy, requests are routed based on the round-robin strategy and distributed across multiple endpoints.

The load for a service is balanced by directing requests to two or more services in a pool until the optimum level is achieved. The application routes requests to services in the pool sequentially, starting from the first and moving to the last, without considering the individual performance of the services.

After all services in the pool have received requests, the first service is chosen again, and the cycle repeats.

In IBM API Studio, this policy is identified by the kind LoadBalancer.

Example of a Load balanced routing policy:

kind: LoadBalancer
apiVersion: apim.ibm.com/v1
metadata:
  name: loadbalancer-routing
  version: 1.0
  namespace: dev
  tags:
    - routing
    - route
    - policy
spec:
  input : request # optional 
  output : response # optional
  roundRobinHttp:
    verb: "GET"
    endpoints:
      - endpoint:
          name: 'endpoint_1'
          tlsClientProfile: tls_profile
          url: ${pet_url_alias}  
          urlType: 'plain' # plain, variables, jsonata      
          version: HTTP/1.0 # HTTP/1.1, HTTP/2
          timeout: 200
          compressRequest: "br" # "gzip", "br", "deflate", "none"
          decompressResponse: false
          followRedirects: false
          chunkedUpload: false
          persistentConnections: true
        suspendTimeout: 300
    statusException:
      - pattern: '200'
  extensions:
    webm-gateway:
      apiVersion: api.ibm.com/v1
      spec:
        endpoints:
          - name: 'endpoint_1'
            connectionTimeout: 300
            sslConfig:
              keyStoreAlias: DEFAULT_IS_KEYSTORE
              keyAlias: ssos
              trustStoreAlias: DEFAULT_IS_TRUSTSTORE
            serviceRegistryParameters:
              - name: ""
                value: ""

To invoke the Load balancer policy, you can specify the following configurations:

Type Description
spec Describes the Load Balancer configuration.

This section includes:

  • input.Uses the incoming request as input.
  • output. Returns the response as the output

It also contains round robin routing, endpoint definitions, SSL configuration and service registry parameters.

roundRobinHttp Defines round robin routing for HTTP.

This section includes:

  • verb. Sets the HTTP method used for routing.
  • endpoints. Lists the endpoints used for routing.
endpoint Specifies configuration details for each endpoint. Use the Add endpoint button in the Endpoint configuration section to configure these parameters.

This section includes:

  • name. Identifies the endpoint.
  • tlsClientProfile. Applies a TLS client profile to outbound calls.
  • url. Specifies the endpoint URL. Supports variable references.
  • urlType. Defines how the URL is interpreted. Valid values are plain, variables and jsonata.
  • version. Sets the HTTP version.
  • timeout. Defines the request timeout in milliseconds.
  • compressRequest. Applies compression to outgoing requests. Available options are Gzip, Brotli, Deflate, or None.
  • decompressResponse. Controls response decompression.
  • followRedirects. Controls redirect behavior.
  • chunkedUpload. Controls chunked upload behavior.
  • persistentConnections. Reuses persistent TCP connections when enabled.
  • suspendTimeout. Keeps the endpoint suspended for the defined duration after a failure.
sslConfig Specifies SSL configuration for the endpoint. Use the Add endpoint button in the Endpoint configuration section to configure these parameters.

This section includes:

  • keyStoreAlias. Sets the keystore alias used for TLS.
  • keyAlias. Sets the private key alias.
  • trustStoreAlias. Sets the truststore alias used for certificate validation.
serviceRegistryParameters Provides parameters used for constructing discovery service URIs. Use the Add endpoint button in the Endpoint configuration section to configure these parameters.

This section includes:

  • name. Sets the registry parameter name.
  • value. Sets the registry parameter value.
statusException Defines status codes that are not treated as errors. Use the Add endpoint button in the Endpoint configuration section to configure these parameters.

This section includes:

  • pattern. Specifies a three digit status code or a wildcard pattern such as 400, 3**, or 50*.
extensions.webm-gateway Provides gateway specific configuration.

This section includes:

  • apiVersion. Sets the API version for the extension.
  • spec.endpoints. Lists the gateway endpoints. This includes:
    • name. Identifies the gateway endpoint.
    • connectionTimeout. Sets the timeout for creating connections.
    • sslConfig. Applies TLS settings for gateway calls.
    • serviceRegistryParameters. Defines discovery parameters used by the gateway.