Zonal affinity for internal passthrough Network Load Balancers (original) (raw)

By default, an internal passthrough Network Load Balancer distributes new connections to eligible backends without considering the zone in which the client and backend are located.

With zonal affinity, the load balancer can distribute new connections from a given client VM to a modified set of eligible backends that are in the client VM's zone. Limiting cross-zone traffic by keeping traffic local to the zone whenever possible reduces inter-zone data transfer cost, reduces latency and improves performance, while maintaining the benefits of multi-zonal architecture.

Zonal affinity is configured on the backend service of an Internal passthrough Network Load Balancer. The load balancer supports different zonal affinity optionsthat offer varying degrees of preference for routing new connections to eligible backends that are in the same zone as a compatible client. Note that established connections in the load balancer's connection tracking table aren't affected by zonal affinity.

Feature compatibility

Before enabling zonal affinity, you must understand which internal passthrough Network Load Balancer features are supported with zonal affinity.

Supported features

Unsupported features

Zonal affinity is incompatible with internal passthrough Network Load Balancers that are configured with the following:

Compatible clients

Zonal affinity is possible only for VM clients that are located in the same region as the load balancer. Zonal affinity isn't compatible with the following clients, which always operate as if zonal affinity is disabled:

Compatibility with next hop internal passthrough Network Load Balancers

While zonal affinity can be enabled for internal passthrough Network Load Balancers used as next hops for static routes, it is generally discouraged for stateful architectures where virtual appliances like firewalls are configured in parallel and load balancing entities are placed on either side of the firewalls.

To learn more, see therequirementssection in the Internal passthrough Network Load Balancer as next hops guide.

Zonal affinity options

Internal passthrough Network Load Balancers support the following zonal affinity options:

To learn how to configure zonal affinity on the backend service of an internal passthrough Network Load Balancer, see Use zonal affinity.

How zonal affinity works

The sections that follow provide an advanced understanding of how zonal affinity works. Understanding these details is not required to configure zonal affinity, but it can help you understand edge cases and precise traffic distribution behavior.

Specifically, these sections cover the following:

Different types of backends

Zonal affinity creates a set of modified eligible backends based on the load balancer's original eligible backends and configured backends. To explain how zonal affinity performs this modification, we precisely define five different backend sets. This document references the following terms in subsequent sections as it explains how zonal affinity works.

Zonal match

A zonal match describes the conditions under which zonal affinity is triggered. The load balancer might then modify the set of original eligible backends to provide the configured zonal affinity. The modification of the original eligible backends takes place after the load balancer selects aneligible backend for a new connection.

In order for the zonal affinity logic to be triggered, the following sequence of events must occur:

  1. Zonal affinity must be enabled.
    If zonal affinity is enabled, continue to the next step.
  2. Determine whether the client is a compatible client.
    If the client is compatible, continue to the next step.
  3. Determine whether a zonal match can occur.
    A zonal match means that the client VM is in a zone that contains at least one zonal match test backend. Zonal match test backends are a set of configured backends, based on the original eligible backends. For details, see Zonal match conditions.
    A zonal match is never possible if either of the following is true:
    • Zonal affinity is disabled
    • The client isn't a compatible client
  4. Apply the zonal affinity logic.

Zonal match conditions

For a zonal match to happen, at least one instance or endpoint in the zonal match test backends must be in the same zone as a compatible client. Both the_configured backends_ and the original eligible backends are inputs used to determine the zonal match test backends.

Original eligible backends Zonal match test backends
All healthy primary backends All configured primary backends Configured primary backends might all be healthy or a combination of healthy and unhealthy.
All healthy failover backends All configured failover backends Configured failover backends might all be healthy or a combination of healthy and unhealthy.
All unhealthy primary backends All configured primary backends The configured primary backends are all unhealthy by definition when the original eligible backends are all unhealthy primary backends.

Zonal match example

Consider the following setup for an internal passthrough Network Load Balancer to understand whether a zonal match occurs.

Scenario 1:

Scenario 2:

After a zonal match occurs, you apply the zonal affinity logic as outlined in the following sections.

Zonal affinity logic

If a zonal match occurs, apply the zonal affinity logic depending on the zonal affinity option that is configured. The options that enable zonal affinity are as follows:

After a zonal match occurs and depending on the type of zonal affinity option that is configured, the modified eligible backends might be the same as the original eligible backends, a subset of the original eligible backends, or different from the original eligible backends.

How ZONAL_AFFINITY_STAY_WITHIN_ZONE works

If zonal affinity is set to ZONAL_AFFINITY_STAY_WITHIN_ZONE, and a zonal match occurs, the load balancer distributes new connections to the modified eligible backends. The modified eligible backends might be the same as the original eligible backends, a subset of the original eligible backends, or different from the original eligible backends.

To create modified eligible backends, the load balancer uses the following process:

  1. Start with the zonal match test backends identified by the zonal match condition.
  2. Remove all backends that aren't in the same zone as the client. This gives us a set of zonal matched backends. This set is always non-empty because a zonal match has occurred.
  3. Compute the intersection of the zonal matched backends with the_original eligible backends_. This intersection might be non-empty or empty.
    • If the intersection is non-empty, the modified eligible backends is the intersection set. The modified eligible backends might be the same as the_original eligible backends_, or the modified eligible backends might be a subset of the original eligible backends.
    • If the intersection is empty, the modified eligible backends is the zonal matched backends itself, which is always different from the original eligible backends. In this situation, all modified eligible backends are unhealthy.

The following table summarizes the process to create the set of modified eligible backends when the zonal affinity option isZONAL_AFFINITY_STAY_WITHIN_ZONE. This zonal affinity option favors backends in the client's zone even if it means using unhealthy backends.

Original eligible backends (A) Zonal match test backends (B) Zonal matched backends (C) Intersection (A∩C) Modified eligible backends
All healthy primary backends All configured primary backends Zonal match test backends might all be healthy or a combination of healthy and unhealthy. All primary backends in the client's zone Zonal matched backends might all be healthy, all unhealthy, or a combination of healthy and unhealthy. All healthy primary backends in the client's zone Intersection not empty: The modified eligible backends are all healthy primary backends in the client's zone. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends. Intersection is empty: The modified eligible backends are all unhealthy primary backends in the client's zone. The modified eligible backends are the same as the zonal matched backends, which are all primary backends in the client's zone; however, all of these backends are unhealthy because the intersection with the original eligible backends is empty.
All healthy failover backends All configured failover backends Zonal match test backends might all be healthy or a combination of healthy and unhealthy. All failover backends in the client's zone Zonal matched backends might all be healthy, all unhealthy, or a combination of healthy and unhealthy. All healthy failover backends in the client's zone Intersection not empty: The modified eligible backends are all healthy failover backends in the client's zone. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends. Intersection is empty: The modified eligible backends are all unhealthy failover backends in the client's zone. The modified eligible backends are the same as the zonal matched backends, which are all failover backends in the client's zone; however, all of these backends are unhealthy because the intersection with the original eligible backends is empty.
All unhealthy primary backends All configured primary backends Zonal match test backends are all unhealthy by definition when the original eligible backends are all unhealthy primary backends. All unhealthy primary backends in the client's zone All unhealthy primary backends in the client's zone Intersection is always not empty: The modified eligible backends are all unhealthy primary backends in the client's zone. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends.

How ZONAL_AFFINITY_SPILL_CROSS_ZONE and spillover ratio work

If zonal affinity is set to ZONAL_AFFINITY_SPILL_CROSS_ZONE, and a zonal match occurs, the load balancer distributes new connections to the modified eligible backends. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends.

When the modified eligible backends are the same as the original eligible backends, new connections might be sent to eligible backends in the client's zone, or they might be sent to eligible backends in any zone ("spill over"). This distribution depends on a configurable spillover ratio.

A configurable spillover ratio indicates the threshold value for keeping traffic in the client's zone. The value of the spillover ratio can range from 0.0 to1.0, inclusive. If you don't specify a spillover ratio when configuringZONAL_AFFINITY_SPILL_CROSS_ZONE, Google Cloud uses a default value of0.0.

Zero spillover ratio

If the configured spillover ratio is 0.0, the load balancer uses the following process to create the modified eligible backends:

  1. Start with the zonal match test backends identified by the zonal match condition.
  2. Remove all backends that aren't in the same zone as the client. This gives us a set of zonal matched backends. This set is always non-empty because a zonal match has occurred.
  3. Compute the intersection of the zonal matched backends with the_original eligible backends_. This intersection might be non-empty or empty.
    • If this intersection is non-empty, the modified eligible backends is the intersection set. The modified eligible backends might be the same as the original eligible backends, or the modified eligible backends might be a subset of the original eligible backends.
    • If the intersection is empty, the modified eligible backends are the same as the original eligible backends.

The following table summarizes the process to create the set of modified eligible backends when the zonal affinity option isZONAL_AFFINITY_SPILL_CROSS_ZONE and the configured spillover ratio is 0.0.

Original eligible backends (A) Zonal match test backends (B) Zonal matched backends (C) Intersection (A∩C) Modified eligible backends
All healthy primary backends All configured primary backends Zonal match test backends might all be healthy or a combination of healthy and unhealthy. All primary backends in the client's zone Zonal matched backends might all be healthy, all unhealthy, or a combination of healthy and unhealthy. All healthy primary backends in the client's zone Intersection not empty: The modified eligible backends are all healthy primary backends in the client's zone. New connections are distributed within the client's zone. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends. Intersection is empty: The modified eligible backends are_the same as original eligible backends_. New connections might be distributed within the client's zone or to other zones.
All healthy failover backends All configured failover backends Zonal match test backends might all be healthy or a combination of healthy and unhealthy. All failover backends in the client's zone Zonal matched backends might all be healthy, all unhealthy, or a combination of healthy and unhealthy. All healthy failover backends in the client's zone Intersection not empty: The modified eligible backends are all healthy failover backends in the client's zone. New connections are distributed within the client's zone. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends. Intersection is empty: The modified eligible backends are_the same as original eligible backends_. New connections might be distributed within the client's zone or to other zones.
All unhealthy primary backends All configured primary backends Zonal match test backends are all unhealthy by definition when the original eligible backends are all unhealthy primary backends. All unhealthy primary backends in the client's zone All unhealthy primary backends in the client's zone Intersection is always not empty: The modified eligible backends are all unhealthy primary backends in the client's zone. New connections are distributed within the client's zone. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends.

Nonzero spillover ratio

If the configured spillover ratio is greater than 0.0 but less than or equal to 1.0, the load balancer uses the following process to create the modified eligible backends:

  1. Start with the zonal match test backends identified by the zonal match condition.
  2. Remove all backends that aren't in the same zone as the client. This gives us a set of zonal matched backends. This set is always non-empty because a zonal match has occurred.
  3. Compute the intersection of the zonal matched backends with the_original eligible backends_. This set might be non-empty or empty.
  4. Calculate the following ratio:
    fractextcount(textzonalmatchedbackends;cap;textoriginaleligiblebackends)textcount(textzonalmatchedbackends)\frac{\text{count}(\text{zonal matched backends} \; \cap \; \text{original eligible backends})}{\text{count}(\text{zonal matched backends})}fractextcount(textzonalmatchedbackends;cap;textoriginaleligiblebackends)textcount(textzonalmatchedbackends)
    Note that the calculated ratio is always zero when the intersection set is empty.
  5. Use the calculated ratio to determine the modified eligible backends:
    • If the calculated ratio is greater than or equal to the spillover ratio, the modified eligible backends is the intersection set. The modified eligible backends might be the same as the original eligible backends, or the modified eligible backends might be a subset of the original eligible backends.
    • If the calculated ratio is less than the spillover ratio, the modified eligible backends are the same as the original eligible backends.

The following table summarizes the process to create the set of modified eligible backends when the zonal affinity option isZONAL_AFFINITY_SPILL_CROSS_ZONE option and the configured spillover ratio isn't 0.0:

Original eligible backends (A) Zonal match test backends (B) Zonal matched backends (C) Intersection (A∩C) Modified eligible backends
All healthy primary backends All configured primary backends Zonal match test backends might all be healthy or a combination of healthy and unhealthy. All primary backends in the client's zone Zonal matched backends might all be healthy, all unhealthy, or a combination of healthy and unhealthy. All healthy primary backends in the client's zone Calculated ratio ≥ spillover ratio: The modified eligible backends are all healthy primary backends in the client's zone. New connections are distributed within the client's zone. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends. Calculated ratio < spillover ratio: The modified eligible backends are_the same as original eligible backends_. New connections might be distributed within the client's zone or to other zones.
All healthy failover backends All configured failover backends Zonal match test backends might all be healthy or a combination of healthy and unhealthy. All failover backends in the client's zone Zonal matched backends might all be healthy, all unhealthy, or a combination of healthy and unhealthy. All healthy failover backends in the client's zone Calculated ratio ≥ spillover ratio: The modified eligible backends are all healthy failover backends in the client's zone. New connections are distributed within the client's zone. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends. Calculated ratio < spillover ratio: The modified eligible backends are_the same as original eligible backends_. New connections might be distributed within the client's zone or to other zones.
All unhealthy primary backends All configured primary backends Zonal match test backends are all unhealthy by definition when the original eligible backends are all unhealthy primary backends. All unhealthy primary backends in the client's zone All unhealthy primary backends in the client's zone Calculated ratio is always ≥ spillover ratio: The modified eligible backends are all unhealthy primary backends in the client's zone. New connections are distributed within the client's zone. The modified eligible backends might be the same as the original eligible backends or a subset of the original eligible backends.

Spillover ratio examples

The following examples show how ZONAL_AFFINITY_SPILL_CROSS_ZONE works.

Consider the following setup where an internal passthrough Network Load Balancer is configured with aZONAL_AFFINITY_SPILL_CROSS_ZONE zonal affinity option with a spillover ratio of 0.8:

internal passthrough Network Load Balancer zonal affinity example.

Some traffic spilling over to a different zone (click to enlarge).

Scenario A: Compatible client in zone 1

Scenario B: Compatible client in zone 2

What's next