Traffic Management for Multiple Upstream Services (Weighted)
Traffic Management for Multiple Upstream Services (Weighted)
Policy Name |
|
Summary |
Manages weighted API instance traffic to multiple upstream services from a single consumer endpoint |
First Flex Gateway version available |
v1.5.0 |
Returned Status Codes |
No return codes exist for this policy. |
The following information applies only to Flex Gateway running in Local Mode. To configure multiple upstream services for Flex Gateway running in Connected Mode, see Multiple Upstream Services for Flex Gateway Running in Connected Mode. |
Summary
Flex Gateway running in Local Mode supports API instances that expose multiple upstream services through a single consumer endpoint.
Flex Gateway manages request traffic by using different routes that can each direct traffic to multiple upstream services. Flex Gateway directs traffic to the routes by using the route order and the individual route’s rules. Additionally, you can add a weighted percentage to each upstream service within a route to manage the percentage of requests sent to the upstream service. For information about configuring non-weighted traffic, refer to Traffic Management for Multiple Upstream Services.
API instances with multiple upstream services in Local Mode are configured by using PolicyBinding
YAML configuration resources. Each route-weighted
resource defines a single route. To add additional routes, add multiple route-weighted
resources.
For a tutorial about how to publish an API instance with this policy applied, see Publishing an API with Multiple Upstream Services in Local Mode.
Deploying APIs with multiple upstream services does not affect the Outbound Transport Layer Security policy. You can apply an Outbound TLS policy to each upstream service. |
Configuring Policy Parameters
Refer to the following policy definition and table of parameters:
policyRef: name: route-weighted config: routes: - weight: <int> // REQUIRED, max_value=100, min_value=1 destinationPath: <string> // OPTIONAL, default: "/" destinationRef: name: <string> // REQUIRED rules: - path: <URL-regex> // OPTIONAL, Example: (.*) methods: <regex-string> // OPTIONAL, Example: GET|POST headers: <header-name>: <regex-string> // OPTIONAL host: <regex-string> // OPTIONAL
Parameter | Required or Optional | Default Value | Description |
---|---|---|---|
|
Required |
Empty |
Array of API upstream services. |
|
Required |
N/A |
Weight of total requests sent to this upstream service. |
|
Required |
N/A |
Path of the upstream service |
|
Required |
N/A |
Name of the upstream service as defined in the |
|
Optional |
Empty |
Array of rulesets for this route. |
|
Optional |
Empty |
Request path that the route can service. |
|
Optional |
Empty |
Array that defines the types of request methods that the route can service. |
|
Optional |
Empty |
Array that defines what headers and regular expression value must be present for this route to service the request. |
|
Optional |
Empty |
Request host URL that the route can service. |
How This Policy Works
The Traffic Management policy directs traffic to different sets of upstream services by using multiple routes with a defined route order and individual rulesets to direct traffic to different sets of upstream services.
In the following diagram, different routes manage requests to flight information databases and to a customer service application. Route one has two upstream services defined, which directs 70% of requests to a stable database and 30% of requests to a beta database.
To achieve this configuration, bind two route-weighted
resources to the exposed API instance. One route-weighted
resource directs traffic to the flight information database, and the other route-weighted
resource directs traffic to the customer service application.
Upstream Services
You can use multiple upstream services in a single route to direct requests to similar services. For example, to test the performance of a new beta upstream service without sending all traffic to the new service, you can direct half of the traffic to a stable upstream service and half to the new upstream service.
The upstream service within the route that each request is sent to is random and independent of any previous request. The routes.weight
value defines the chance of a request being sent to a particular upstream service. The percentage of traffic sent to that upstream service is the upstream’s routes.weight
divided by the total weight of all upstream services. For example, if there are two upstream services with weight 1
, each receives 50% of the traffic to that route. If the weight values are 1
and 3
, one route would receive 25% of traffic and the other 75%.
Because any upstream service within a route can receive any request, all upstream services within the same route must adhere to the same API contract.
Route Rules
You can direct requests to different routes by using route rules. Requests must meet the rules for only one of the rulesets in the route.
Rulesets refer to any combination of the four rules: path
, method
, headers
, and host
. You can use multiple rulesets to support different combinations of rules.
All rules are optional. If a rule is not included in a ruleset, that rule is ignored. For example, not specifying a host means that the route can service any host if the request meets the other route rules. Not defining any rule means that the route can service every request.
If a request does not meet the rules for any route, Flex Gateway returns a 404
error code.
Route Order
In addition to using route rules, you can direct requests to different routes by using policy ordering.
To order policies, see Ordering Policies
Setting the policy order sets the order in which traffic is directed to the routes. Flex Gateway directs requests to the first route if the request meets one of the route rulesets. Therefore, route ordering is very important when a request can meet the route rules of multiple routes.
For example, in a configuration in which route one has the GET
method defined as a rule and route two has no route rules defined, all GET
requests are sent to route one and all other requests are sent to route two. If the route order was reversed and route one had no route rules, Flex Gateway would direct all requests to route one before any GET
requests could reach route two.