Skip to content

Commit bc22520

Browse files
docs: Document session balancer mode for VTGate tablet routing (#2043)
* Document session balancer mode for VTGate tablet routing * Sync documentation updates --------- Co-authored-by: promptless[bot] <179508745+promptless[bot]@users.noreply.github.com>
1 parent b26fdef commit bc22520

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

content/en/docs/24.0/reference/features/tablet-balancer.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ each tablet.
2828

2929
## Balancer Modes
3030

31-
However, in some topologies, a simple affinity algorithm does not effectively balance the load.
32-
VTGate provides two additional balancer modes to address different topology and traffic patterns:
33-
**prefer-cell** and **random**.
31+
However, you may want more control over how traffic gets balanced across tablets.
32+
VTGate provides three additional balancer modes to address different topology and traffic patterns:
33+
**prefer-cell**, **random**, and **session**.
3434

3535
### When Default Policy is Insufficient
3636

@@ -116,24 +116,40 @@ guaranteed even load distribution across all tablets, regardless of where traffi
116116
With the random balancer, you can optionally use `--balancer-vtgate-cells` to restrict the
117117
tablet pool to specific cells, but it's not required.
118118

119+
### Session Balancer
120+
121+
The session balancer ensures that a session always reads from the same replica to maintain monotonic consistency. Without this, a connection might read a value from one tablet, then get routed to a different tablet with higher replication lag and read an older value, effectively reading "backwards in time."
122+
123+
The session balancer uses rendezvous hashing (also called highest random weight hashing) to route each session to the same tablet throughout its lifetime. Rendezvous hashing ensures minimal connections move when tablets enter or leave the pool. For each session, it computes a hash weight for every available tablet using the tablet's alias and the session's unique identifier. The tablet with the highest weight is selected; as this process is deterministic, the same session always routes to the same tablet.
124+
125+
The algorithm prefers tablets in the local cell to minimize latency. If there are no available tablets in the local cell, the balancer will route traffic to external cells as a fallback.
126+
127+
Note that there are still cases where the monotonic consistency guarantee can be broken. For example, if a session is currently connected to a specific tablet, and that tablet goes down or goes out of serving, the session balancer will automatically route the session to a new, healthy tablet. If the new tablet is not as up-to-date as the previous tablet, the session may observe an older value for the same read.
128+
129+
**When to use session mode:**
130+
* Your application requires monotonic consistency within a session
131+
* Session stickiness is more important than absolute load distribution
132+
* You want to eliminate the possibility of "backwards" reads due to replication lag differences
133+
119134
## Configuration
120135

121-
VTGate provides three balancer modes, controlled by the `--vtgate-balancer-mode` flag:
136+
VTGate provides four balancer modes, controlled by the `--vtgate-balancer-mode` flag:
122137

123138
### Balancer Mode Selection
124139

125140
* **`--vtgate-balancer-mode=cell`** (default): Uses local cell affinity random choice (default policy described above)
126141
* **`--vtgate-balancer-mode=prefer-cell`**: Uses the prefer-cell balancer algorithm
127142
* **`--vtgate-balancer-mode=random`**: Uses uniform random selection across all tablets
143+
* **`--vtgate-balancer-mode=session`**: Uses the session balancer algorithm to maintain session stickiness
128144

129145
### Configuration Flags
130146

131-
* **`--vtgate-balancer-mode`**: Specifies which balancer mode to use (cell, prefer-cell, or random). Defaults to `cell`.
147+
* **`--vtgate-balancer-mode`**: Specifies which balancer mode to use (cell, prefer-cell, random, or session). Defaults to `cell`.
132148

133149
* **`--balancer-vtgate-cells`**: Comma-separated list of cells that contain vtgates.
134150
* **Required** for `prefer-cell` mode
135151
* **Optional** for `random` mode (filters tablets to specified cells if provided)
136-
* Ignored for `cell` mode
152+
* Ignored for `cell` and `session` modes
137153

138154
* **`--balancer-keyspaces`**: Comma-separated list of keyspaces for which to use the configured balancer mode. If empty, applies to all keyspaces. This allows gradual rollout of balancer modes.
139155

content/en/docs/24.0/reference/programs/vtgate/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ vtgate \
263263
-v, --version print binary version
264264
--vmodule vModuleFlag comma-separated list of pattern=N settings for file-filtered logging
265265
--vschema-ddl-authorized-users string List of users authorized to execute vschema ddl operations, or '%' to allow all users.
266-
--vtgate-balancer-mode string Tablet balancer mode (options: cell, prefer-cell, random). Defaults to 'cell' which shuffles tablets in the local cell.
266+
--vtgate-balancer-mode string Tablet balancer mode (options: cell, prefer-cell, random, session). Defaults to 'cell' which shuffles tablets in the local cell.
267267
--vtgate-config-terse-errors prevent bind vars from escaping in returned errors
268268
--warming-reads-concurrency int Number of concurrent warming reads allowed (default 500)
269269
--warming-reads-percent int Percentage of reads on the primary to forward to replicas. Useful for keeping buffer pools warm

0 commit comments

Comments
 (0)