Skip to main content

Load-Based Range Splitting

With key-range sharding, a range splits when it contains too many keys. However, a small range can receive most of the cluster's writes. One partition leader orders all writes to it, and that one node becomes the bottleneck. Load-based splitting detects a range that is overloaded for a sustained time, and splits it. Another node can then lead half of its writes. It is the automatic version of splitting a hot database shard.

Kahuna has two independent reasons to split a range into two partitions.

TriggerConditionPurpose
Count-basedThe sampled key count reaches RangeSplitThresholdPrevent one range from growing indefinitely
Load-basedWrite rate and WAL backlog remain high for a sustained windowRelieve a small but write-hot partition

Load-based splitting is disabled by default. It applies only to key spaces registered for key-range sharding.

Why Key Count Is Not Enough​

A key-count threshold doesn't split a small range, however many writes its leader must order.

Load-based splitting watches replication work and the backlog of the write-ahead log (WAL). When a range remains overloaded, Kahuna chooses a split key near the write centroid, aiming to place approximately half of the observed writes on each child range.

Before
[orders/0000, orders/9999) -> one hot partition

After
[orders/0000, orders/6200) -> partition A
[orders/6200, orders/9999) -> partition B

The split point follows where writes actually land. It isn't the alphabetical midpoint or the median stored key.

Monotonic appends, such as keys built from increasing IDs, put the newest writes at the end of the range. A split at the median would leave the lower child with cold keys, and all new writes would go to the upper child. For this reason, Kahuna can split near the 75th-percentile key. The new partition takes only the hot tail, and most of the cold keys remain in the lower child.

Leader Balancing Is Required​

Enable the leader balancer whenever load-based splitting is enabled.

There are two reasons.

  1. Nodes share partition load reports with each other only while leader balancing is enabled
  2. A split relieves a node only if a different, less-loaded node can lead one child

If leader balancing is disabled, the split coordinator sees zero load for partitions that other nodes lead. A split whose children remain on the same node can also add replication work, and that node's storage or CPU bottleneck doesn't decrease.

For embedded multi-node deployments, set both options.

var options = new EmbeddedKahunaOptions
{
RangeSplitLoadThreshold = 2_000,
EnableLeaderBalancer = true
};

For rollout and tuning, see Leader Balancing.

Split Decision​

All enabled gates must remain satisfied for RangeSplitLoadWindow before Kahuna splits a range.

  1. Write rate: replicated log operations per second must reach RangeSplitLoadThreshold
  2. WAL queue depth: pending WAL work must reach RangeSplitLoadMinQueueDepth
  3. Commit wait: when configured above zero, commit-wait latency must reach RangeSplitLoadMinCommitWaitMs

The queue-depth gate distinguishes a healthy busy partition from one that cannot keep up. High throughput with an empty queue does not trigger a split.

The sustained window filters short bursts and delayed gossip reports. Keep the window near or above 10 seconds; the default is 15 seconds with a 5-second polling interval.

After splitting, both children enter RangeSplitSettleWindow. This gives leadership time to stabilize and the balancer time to relocate a child before either range is evaluated again.

Configuration​

Kahuna Server exposes the primary range split and merge knobs as command-line flags. The same settings are available on EmbeddedKahunaOptions using the corresponding property names.

Server FlagEmbedded OptionDefaultDescription
--range-split-load-thresholdRangeSplitLoadThreshold0Minimum replicated writes per second. 0 disables load-based splitting
--range-split-load-min-queue-depthRangeSplitLoadMinQueueDepth8Minimum WAL queue depth required with the rate threshold
--range-split-load-windowRangeSplitLoadWindow15 secondsTime all load gates must remain continuously satisfied
--range-split-load-poll-intervalRangeSplitLoadPollInterval5 secondsFrequency of load-gate evaluation. Keep below the load window
not exposedRangeSplitLoadMinCommitWaitMs0Optional minimum commit-wait latency. 0 disables this additional gate
not exposedRangeSplitLoadImbalanceMax0.8Maximum acceptable write fraction on either child after selecting a split key
not exposedRangeSplitIndivisibleCooldown5 minutesDelay before reconsidering a range that cannot be split usefully
--range-split-settle-windowRangeSplitSettleWindow10 secondsPost-split delay before either child can be evaluated again
--range-move-quiesce-ttlRangeMoveQuiesceTtl30 secondsWrite-fence lifetime for a split or merge; exhausted windows refuse cutover with QuiesceExpired. Minimum 1 second
--range-move-settle-timeoutRangeMoveSettleTimeout10 secondsMaximum quiesce wait for in-flight transactions in the moving range before split or merge cutover
--range-split-thresholdRangeSplitThreshold1000 keysCount-based split threshold. 0 disables count-based splitting
--range-split-min-range-sizeRangeSplitMinRangeSize10 keysMinimum number of sampled keys required in each child
--range-merge-min-sizeRangeMergeMinSize10 keysAdjacent ranges below this size can merge. 0 disables auto-merge
--range-collection-intervalCollectionInterval60 secondsSampling cadence for split/merge checks and related maintenance

RangeSplitSettleWindow must be at least MinLeaderStability. Embedded startup returns an error for a shorter settle window. LeaderBalancerReportInterval must also remain shorter than LeaderBalancerReportTtl.

Count- and load-based splitting both honor the cluster partition limit and per-key-space range quota. A busy range does not bypass either limit. Configure --raft-max-partitions and --range-max-ranges-per-key-space to bound growth; 0 leaves each unbounded.

Hot Keys Cannot Be Split​

Splitting helps when writes can be divided across two key spans. It can't help when nearly all writes target one key.

Kahuna evaluates the best achievable write distribution before committing a load split. If either child would retain at least RangeSplitLoadImbalanceMax of writes, the range is considered indivisible and the split is refused. The same refusal metric is reported when a range is hot but too small to divide and most writes are concentrated on one key.

For a persistent hot-key pattern, change the application key design or shard the value at the application level. Repeatedly lowering thresholds cannot make one key divisible.

Metrics​

The Kahuna meter publishes these counters with a keyspace tag.

MetricMeaning
kahuna.range.splitsSuccessfully committed count- or load-based splits
kahuna.range.split.no_relief_skipsLoad splits skipped because no peer can host the new leadership
kahuna.range.split.indivisible_refusalsSplits refused because writes cannot be divided usefully
kahuna.range.split.incomplete_source_refusalsSplits refused because the source leader looked incomplete compared with another replica
kahuna.range.split.settle_skipsChecks skipped while a range is in its settle window
kahuna.range.merge.warm_skipsMerges refused because at least one range remains warm

The deployment must export the Kahuna meter through its telemetry pipeline before these instruments are visible externally.

Troubleshooting​

A Hot Range Never Splits​

Confirm these conditions.

  • The key space is registered for key-range routing
  • RangeSplitLoadThreshold is greater than zero
  • Leader balancing is enabled on all participating nodes
  • Both write rate and queue depth remain above their thresholds for the complete load window
  • The writes use persistent durability and therefore pass through Raft

Reads and ephemeral writes do not contribute to the load-split rate.

Splits Do Not Improve Throughput​

Check whether the child leadership moved to another node. Rising kahuna.range.split.no_relief_skips indicates that no relief target was available. Also verify the cluster has a less-loaded peer and inspect the leader-balancer metrics.

Splitting distributes Raft leadership and write coordination. It does not reduce total stored bytes because replicas continue to hold the data.

Ranges Merge and Split Repeatedly​

The warm-range merge guard normally prevents this cycle. If it occurs, increase the settle window or adjust the load threshold so a recently active range is not immediately considered cold enough to merge.

A Split Is Refused With SourceStateIncomplete​

This retryable refusal increments kahuna.range.split.incomplete_source_refusals. Before copying keys, Kahuna compares the source leader's apply fingerprint with the other replicas; if a replica has more committed transactional heads than the source leader at the same applied log id, the leader may be missing acknowledged state. The split can be retried on a later cadence after leadership or replica state converges.