The load balancing algorithm used within the scope of the locality.
The possible values are: - ROUND_ROBIN: This is a simple policy in
which each healthy backend is selected in round robin order. This is
the default. - LEAST_REQUEST: An O(1) algorithm which selects two
random healthy hosts and picks the host which has fewer active
requests. - RING_HASH: The ring/modulo hash load balancer implements
consistent hashing to backends. The algorithm has the property that
the addition/removal of a host from a set of N hosts only affects
1/N of the requests. - RANDOM: The load balancer selects a random
healthy host. - ORIGINAL_DESTINATION: Backend host is selected based
on the client connection metadata, i.e., connections are opened to
the same address as the destination address of the incoming
connection before the connection was redirected to the load
balancer. - MAGLEV: used as a drop in replacement for the ring hash
load balancer. Maglev is not as stable as ring hash but has faster
table lookup build times and host selection times. For more
information about Maglev, see
https://ai.google/research/pubs/pub44824 - WEIGHTED_ROUND_ROBIN:
Per-endpoint Weighted Round Robin Load Balancing using weights
computed from Backend reported Custom Metrics. If set, the Backend
Service responses are expected to contain non-standard HTTP response
header field Endpoint-Load-Metrics. The reported metrics to use for
computing the weights are specified via the customMetrics field.
This field is applicable to either: - A regional backend service
with the service_protocol set to HTTP, HTTPS, HTTP2 or H2C, and
load_balancing_scheme set to INTERNAL_MANAGED. - A global backend
service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED,
INTERNAL_MANAGED, or EXTERNAL_MANAGED. If sessionAffinity is not
configured—that is, if session affinity remains at the default value
of NONE—then the default value for localityLbPolicy is ROUND_ROBIN.
If session affinity is set to a value other than NONE, then the
default value for localityLbPolicy is MAGLEV. Only ROUND_ROBIN and
RING_HASH are supported when the backend service is referenced by a
URL map that is bound to target gRPC proxy that has
validateForProxyless field set to true. localityLbPolicy cannot be
specified with haPolicy.
Enums
Name
Description
UNDEFINED_LOCALITY_LB_POLICY
A value indicating that the enum field is not set.
INVALID_LB_POLICY
No description available.
LEAST_REQUEST
An O(1) algorithm which selects two random healthy hosts and picks the host which has fewer active requests.
MAGLEV
This algorithm implements consistent hashing to backends. Maglev can be used as a drop in replacement for the ring hash load balancer. Maglev is not as stable as ring hash but has faster table lookup build times and host selection times. For more information about Maglev, see https://ai.google/research/pubs/pub44824
ORIGINAL_DESTINATION
Backend host is selected based on the client connection metadata, i.e., connections are opened to the same address as the destination address of the incoming connection before the connection was redirected to the load balancer.
RANDOM
The load balancer selects a random healthy host.
RING_HASH
The ring/modulo hash load balancer implements consistent hashing to backends. The algorithm has the property that the addition/removal of a host from a set of N hosts only affects 1/N of the requests.
ROUND_ROBIN
This is a simple policy in which each healthy backend is selected in round robin order. This is the default.
WEIGHTED_MAGLEV
Per-instance weighted Load Balancing via health check reported weights. If set, the Backend Service must configure a non legacy HTTP-based Health Check, and health check replies are expected to contain non-standard HTTP response header field X-Load-Balancing-Endpoint-Weight to specify the per-instance weights. If set, Load Balancing is weighted based on the per-instance weights reported in the last processed health check replies, as long as every instance either reported a valid weight or had UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains equal-weight. This option is only supported in Network Load Balancing.
WEIGHTED_ROUND_ROBIN
Per-endpoint weighted round-robin Load Balancing using weights computed from Backend reported Custom Metrics. If set, the Backend Service responses are expected to contain non-standard HTTP response header field Endpoint-Load-Metrics. The reported metrics to use for computing the weights are specified via the customMetrics fields.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-11 UTC."],[],[],null,["# Class LocalityLbPolicy (1.35.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.35.0 (latest)](/python/docs/reference/compute/latest/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.34.0](/python/docs/reference/compute/1.34.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.33.0](/python/docs/reference/compute/1.33.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.32.0](/python/docs/reference/compute/1.32.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.31.0](/python/docs/reference/compute/1.31.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.30.0](/python/docs/reference/compute/1.30.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.29.0](/python/docs/reference/compute/1.29.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.28.0](/python/docs/reference/compute/1.28.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.27.0](/python/docs/reference/compute/1.27.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.26.0](/python/docs/reference/compute/1.26.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.25.0](/python/docs/reference/compute/1.25.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.24.0](/python/docs/reference/compute/1.24.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.23.0](/python/docs/reference/compute/1.23.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.22.0](/python/docs/reference/compute/1.22.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.21.0](/python/docs/reference/compute/1.21.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.20.1](/python/docs/reference/compute/1.20.1/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.19.2](/python/docs/reference/compute/1.19.2/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.18.0](/python/docs/reference/compute/1.18.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.17.0](/python/docs/reference/compute/1.17.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.16.1](/python/docs/reference/compute/1.16.1/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.15.0](/python/docs/reference/compute/1.15.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.14.1](/python/docs/reference/compute/1.14.1/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.13.0](/python/docs/reference/compute/1.13.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.12.1](/python/docs/reference/compute/1.12.1/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.11.0](/python/docs/reference/compute/1.11.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.10.1](/python/docs/reference/compute/1.10.1/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.9.0](/python/docs/reference/compute/1.9.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.8.0](/python/docs/reference/compute/1.8.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.7.0](/python/docs/reference/compute/1.7.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.6.1](/python/docs/reference/compute/1.6.1/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.5.2](/python/docs/reference/compute/1.5.2/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.4.0](/python/docs/reference/compute/1.4.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.3.2](/python/docs/reference/compute/1.3.2/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.2.0](/python/docs/reference/compute/1.2.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.1.0](/python/docs/reference/compute/1.1.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [1.0.0](/python/docs/reference/compute/1.0.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [0.9.0](/python/docs/reference/compute/0.9.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [0.8.0](/python/docs/reference/compute/0.8.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [0.7.0](/python/docs/reference/compute/0.7.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [0.6.0](/python/docs/reference/compute/0.6.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [0.5.0](/python/docs/reference/compute/0.5.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [0.4.2](/python/docs/reference/compute/0.4.2/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [0.3.0](/python/docs/reference/compute/0.3.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [0.2.1](/python/docs/reference/compute/0.2.1/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy)\n- [0.1.0](/python/docs/reference/compute/0.1.0/google.cloud.compute_v1.types.BackendService.LocalityLbPolicy) \n\n LocalityLbPolicy(value)\n\nThe load balancing algorithm used within the scope of the locality.\nThe possible values are: - ROUND_ROBIN: This is a simple policy in\nwhich each healthy backend is selected in round robin order. This is\nthe default. - LEAST_REQUEST: An O(1) algorithm which selects two\nrandom healthy hosts and picks the host which has fewer active\nrequests. - RING_HASH: The ring/modulo hash load balancer implements\nconsistent hashing to backends. The algorithm has the property that\nthe addition/removal of a host from a set of N hosts only affects\n1/N of the requests. - RANDOM: The load balancer selects a random\nhealthy host. - ORIGINAL_DESTINATION: Backend host is selected based\non the client connection metadata, i.e., connections are opened to\nthe same address as the destination address of the incoming\nconnection before the connection was redirected to the load\nbalancer. - MAGLEV: used as a drop in replacement for the ring hash\nload balancer. Maglev is not as stable as ring hash but has faster\ntable lookup build times and host selection times. For more\ninformation about Maglev, see\n\u003chttps://ai.google/research/pubs/pub44824\u003e - WEIGHTED_ROUND_ROBIN:\nPer-endpoint Weighted Round Robin Load Balancing using weights\ncomputed from Backend reported Custom Metrics. If set, the Backend\nService responses are expected to contain non-standard HTTP response\nheader field Endpoint-Load-Metrics. The reported metrics to use for\ncomputing the weights are specified via the customMetrics field.\nThis field is applicable to either: - A regional backend service\nwith the service_protocol set to HTTP, HTTPS, HTTP2 or H2C, and\nload_balancing_scheme set to INTERNAL_MANAGED. - A global backend\nservice with the load_balancing_scheme set to INTERNAL_SELF_MANAGED,\nINTERNAL_MANAGED, or EXTERNAL_MANAGED. If sessionAffinity is not\nconfigured---that is, if session affinity remains at the default value\nof NONE---then the default value for localityLbPolicy is ROUND_ROBIN.\nIf session affinity is set to a value other than NONE, then the\ndefault value for localityLbPolicy is MAGLEV. Only ROUND_ROBIN and\nRING_HASH are supported when the backend service is referenced by a\nURL map that is bound to target gRPC proxy that has\nvalidateForProxyless field set to true. localityLbPolicy cannot be\nspecified with haPolicy."]]