Skip to content

Add active–standby load balancing strategy to pool #509

@tulzke

Description

@tulzke

Description

The current pool implementation supports only the round_robin balancing strategy.

It would be useful to have a strategy where:

  • Only a subset of replicas is active and actually receives traffic.
  • The remaining replicas act as standby and are promoted into the active subset when needed.

This allows:

  • Keeping a controlled number of nodes serving traffic
  • Using the remaining nodes as high-availability and capacity reserve.

Proposed functionality

Introduce a new balancing strategy (for example active_standby or priority) with the following behavior:

  1. The pool is configured with N connections in total.
  2. The size of the primary (active) subset is configurable:
    • Either as a fixed number: primaryCount = P, 1 <= P <= N
    • Or as a fraction: primaryShare ∈ (0, 1], converted to P = ceil(N * primaryShare)
  3. At any point in time the strategy:
    • Selects up to P healthy connections as the active subset.
    • Routes all traffic only to this active subset (e.g. round-robin within it).
    • Treats the remaining healthy connections as standby (no traffic unless promoted).
  4. If an active connection becomes unhealthy:
    • It is removed from the active subset.
    • A healthy standby connection is promoted into the active subset to keep its size close to P.
  5. If a previously unhealthy connection becomes healthy again:
    • It is added back to the pool of candidates and may be selected into the active subset according to the strategy rules.

From the caller’s perspective, the promotions and demotions are transparent.

Example configuration

Conceptual API, just as an illustration:

pool := connection_pool.New(
    connection_pool.WithStrategy(
        connection_pool.StrategyActiveStandby(
            connection_pool.WithPrimaryPoolSize(8),
        ),
    ),
    connection_pool.WithConnections([]connection_pool.Node{
        {Conn: conn1},
        {Conn: conn2},
        {Conn: conn3},
        {Conn: conn4},
        {Conn: conn5},
        {Conn: conn6},
        {Conn: conn7},
        {Conn: conn8},
        {Conn: conn9},
        {Conn: conn10},
    }),
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions