---
title: "Proxy-Based Load Balancing"
url: https://docs.zeroc.com/ice/3.8/runtime/invocation/proxy-based-load-balancing
language: python
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Proxy-Based Load Balancing

Programming language: Python. Other languages: [C++](https://docs.zeroc.com/ice/3.8/runtime/invocation/proxy-based-load-balancing/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/runtime/invocation/proxy-based-load-balancing/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/runtime/invocation/proxy-based-load-balancing/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/runtime/invocation/proxy-based-load-balancing/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/runtime/invocation/proxy-based-load-balancing/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/runtime/invocation/proxy-based-load-balancing/php.md), [Ruby](https://docs.zeroc.com/ice/3.8/runtime/invocation/proxy-based-load-balancing/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/runtime/invocation/proxy-based-load-balancing/swift.md).

A proxy to a [replicated object](https://docs.zeroc.com/ice/3.8/runtime/invocation/proxies-to-replicated-objects.md) can distribute its invocations over the replicas: a direct proxy holds the endpoints of the replicas, and an indirect proxy gets them from the [locator](https://docs.zeroc.com/ice/3.8/runtime/locators.md). [Locator Semantics for Clients](https://docs.zeroc.com/ice/3.8/runtime/locators/locator-semantics-for-clients/python.md) describes load balancing with a locator.

## Load Balancing with Connection Caching

By default, a proxy [caches its connection](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-establishment/python.md#connection-reuse-and-caching) and uses the `Random` [endpoint selection type](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-establishment/python.md#endpoint-selection). On the first invocation, Ice reuses an existing connection to any of the proxy's endpoints, including one opened by another proxy; otherwise, it tries the endpoints in random order until it establishes a connection to one of them. The proxy then sends all its invocations over this connection until the connection closes, so the proxies of a communicator that hold the same endpoints typically reach the same server.

With the `Ordered` endpoint selection type, Ice tries the endpoints in the order they appear in the proxy, and still reuses an existing connection to any of them first.

## Per-Request Load Balancing

When a proxy does not cache its connection, Ice selects an endpoint for each invocation, and uses an existing connection to this endpoint or connects to it. With the `Random` endpoint selection type, successive invocations can therefore reach different servers, though not necessarily in equal numbers:

```py
proxy = VisitorCenter.GreeterPrx(
    communicator,
    "greeter:tcp -h 10.0.0.1 -p 4061:tcp -h 10.0.0.2 -p 4061")
proxy = proxy.ice_connectionCached(False)
```

With the `Ordered` endpoint selection type, each invocation goes to the first endpoint, and to the next ones only when Ice cannot connect to the first. Ice does not remember a failed connection attempt: while the first server is unavailable, every invocation starts with an attempt to connect to it.

## See Also

- [Terminology](https://docs.zeroc.com/ice/3.8/basics/terminology.md)
- [Connection Establishment](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-establishment/python.md)
- [Ice.Default.\*](https://docs.zeroc.com/ice/3.8/property-reference/ice-default-properties/python.md)
- [Locator Semantics for Clients](https://docs.zeroc.com/ice/3.8/runtime/locators/locator-semantics-for-clients/python.md)
- [Load Balancing](https://docs.zeroc.com/ice/3.8/services/icegrid/load-balancing.md)
