The Upstream Target
Each API definition includes an upstream target URL. Tyk Gateway replaces its own hostname with this URL when forwarding the request.- Tyk OAS: the upstream target is configured in the
upstreamsection of the Tyk Vendor Extension. See Upstream. - Tyk Classic: the upstream target is the
proxy.target_urlfield in the API definition.
upstream.url:http://acme.service.com/user-serviceserver.listenPath.value:/users- an endpoint
GET /{id}/profile - hosted on a Tyk Gateway with the domain
acme-gateway.com
GET http://acme-gateway.com/users/1234/profile is matched to the Users API and forwarded to the upstream depending on server.listenPath.strip:
true: forwarded tohttp://acme.service.com/user-service/1234/profilefalse: forwarded tohttp://acme.service.com/user-service/users/1234/profile
Load Balancing
Tyk supports round-robin load balancing across multiple upstream targets. When load balancing is enabled, Tyk rotates requests through the configured target list on each incoming request. Targets can be weighted so that traffic is distributed in a controlled ratio - for example, directing 90% of traffic to a production environment and 10% to a beta environment.Configuration
Configure targets and set weights in theupstream.loadBalancing section of the Tyk Vendor Extension:
9 receives nine times as many requests as a target with weight 1. There is no upper limit on weight values. Weight must be specified for each target - if omitted it defaults to 0, which excludes the target from the rotation.
Setting a weight of
0 will skip that target; this is useful if you need to remove a target from the load balancing temporarily.proxy.enable_load_balancing: true and list the target URLs in proxy.target_list:
proxy.target_list will be addressed in turn. To increase the weighting for a target, you must include it multiple times in the list.
Skipping Unavailable Hosts
Tyk Gateway’s uptime tests periodically probe each upstream target and automatically remove failing hosts from the load balancing rotation, so requests are only sent to healthy targets. Setupstream.loadBalancing.skipUnavailableHosts: true in Tyk OAS, or proxy.check_host_against_uptime_tests: true in Tyk Classic.
See Uptime Tests for more details and how to configure the probes.
Service Discovery
Rather than a static upstream URL, Tyk can query a service discovery endpoint - such as Consul, etcd, or Eureka - to resolve the current upstream target at request time. This is useful when upstream services are scaled dynamically and their addresses change. The service discovery endpoint returns a list of addresses that Tyk uses as its load balancing target list. The static upstream URL (upstream.url in Tyk OAS, proxy.target_url in Tyk Classic) is still required in the API definition. If the service discovery query fails, Tyk falls back to the static URL.
See Service Discovery for details of how to configure the service discovery feature.
Upstream TLS
When forwarding to an HTTPS upstream, Tyk Gateway verifies the server’s certificate against the system trust store on the host running the Gateway. For upstreams using self-signed or internally issued certificates, add the issuing CA certificate to that trust store. When the upstream requires mutual TLS (mTLS), Tyk must also present a client certificate during the TLS handshake. Certificates are mapped to upstream domains in the API definition or at the Gateway level, so different client certificates can be used for different upstream hosts within the same API. For defense against compromised certificate authorities, certificate pinning restricts which public keys Tyk will accept from a given upstream domain, regardless of what a CA has signed. For non-production environments where the upstream certificate cannot be trusted (such as local development), theupstream.tlsTransport.insecureSkipVerify option in the API definition (Tyk Classic: proxy.transport.ssl_insecure_skip_verify) disables upstream certificate verification for that API. This should never be enabled in production.
See Upstream Mutual TLS for full configuration detail.
gRPC Forwarding
gRPC is an RPC framework that uses HTTP/2 as its transport protocol. Tyk supports gRPC passthrough proxying, including all streaming modes. gRPC requests follow the path format/{ServiceName}/{MethodName}. This path must reach the upstream unchanged, so strip listen path must be set to false in the API definition.
The upstream target URL format depends on whether the upstream gRPC server requires TLS.
Secure gRPC (TLS)
Set the upstream target to an https:// URL:
h2c://:
TCP Forwarding
Tyk can forward raw TCP traffic, acting as a transparent proxy for non-HTTP services such as databases or services using custom binary protocols. Set the upstream target URL scheme totcp:// for a plain TCP upstream or tls:// for a TLS-secured upstream.
See TCP Proxy for full configuration detail, including port assignment, SNI-based routing, and health checks.