Load Balancing
Last updated: 2 minutes read.
Tyk supports native round-robin load-balancing in its proxy. This means that Tyk will rotate requests through a list of target hosts as requests come in. This can be very useful in microservice architectures where clusters of specialized services are launched for high availability.
Setting up load balancing is done on a per API basis, and is defined in the API Definition file/object:
-
proxy.enable_load_balancing
: Set this value totrue
to have a Tyk node distribute traffic across a list of servers. -
proxy.target_list
: A list of upstream targets (can be one or many hosts):
"target_list": [
"http://10.0.0.1",
"http://10.0.0.2",
"http://10.0.0.3",
"http://10.0.0.4"
]
Note
You must fill in the target_list
section.
See Service Discovery to see how you can integrate a service discovery system such as Consul or etcd with Tyk and enable dynamic load balancing support.
Configure load balancing and weighting via the Dashboard
To set up load balancing via the Dashboard, from the Core Settings tab in the API Designer select Enable round-robin load balancing from the API Settings options:
You can now add your Load Balancing Upstream targets and apply weighting to it. For example, for testing purposes, you can send 10% (set weighting to 1
) of traffic to a beta environment, and 90% (set weighting to 9
)to the production environment.
Note
Weighting is new from v1.10 of the Dashboard
Configure load balancing via Tyk Operator
Load balancing is configured within Tyk Operator, using the following configuration parameters within the proxy configuration block:
enable_load_balancing
: Set totrue
to activate load balancingtarget_list
: Specifies a list of upstream targets
An example is shown below:
|
|
gRPC load balancing
You can also perform gRPC Load balancing.