0
0
LLDsystem_design~7 mins

Split strategies (equal, exact, percentage) in LLD - System Design Guide

Choose your learning style9 modes available
Problem Statement
When distributing tasks or traffic among multiple targets, naive splitting can cause uneven load, incorrect allocation, or unpredictable results. This leads to resource wastage, unfair user experience, or inaccurate experiment results.
Solution
Split strategies define clear rules to divide load or tasks precisely. Equal split divides resources evenly, exact split assigns fixed amounts, and percentage split allocates based on defined ratios. This ensures predictable, fair, and controlled distribution.
Architecture
Incoming Load
Split Strategy
(Equal/Exact/

This diagram shows incoming load routed to a split strategy component, which then distributes the load to multiple targets (T1, T2, T3, T4) based on the chosen split method.

Trade-offs
✓ Pros
Equal split ensures balanced load distribution without complex calculations.
Exact split allows precise control over resource allocation per target.
Percentage split supports flexible, ratio-based distribution adapting to dynamic needs.
Clear split strategies improve predictability and fairness in task assignment.
✗ Cons
Equal split may not suit targets with different capacities or priorities.
Exact split requires upfront knowledge of exact amounts, reducing flexibility.
Percentage split can cause rounding errors leading to slight imbalance.
Implementing multiple split strategies increases system complexity.
Use when distributing load or tasks among multiple targets with known capacities or when controlled allocation is needed, especially at scales above hundreds of requests per second.
Avoid when targets have highly variable or unknown capacities, or when distribution can be handled by simpler random or round-robin methods under low load (below 100 req/sec).
Real World Examples
Netflix
Uses percentage split to route user traffic to different versions of their streaming service for A/B testing, ensuring controlled exposure.
Uber
Applies exact split to allocate fixed numbers of ride requests to different driver pools based on region capacity.
Amazon
Employs equal split to balance incoming API requests evenly across multiple backend servers to prevent overload.
Code Example
The before code randomly assigns load without control, causing imbalance. The after code shows three split strategies: equal split divides load evenly with remainder handling; exact split assigns fixed amounts per target with validation; percentage split allocates load based on given ratios, handling rounding by assigning remainder to last target.
LLD
### Before: naive random split without control
import random

def naive_split(targets, load):
    distribution = {t: 0 for t in targets}
    for _ in range(load):
        chosen = random.choice(targets)
        distribution[chosen] += 1
    return distribution

### After: implementing equal, exact, and percentage split strategies

def equal_split(targets, load):
    base = load // len(targets)
    remainder = load % len(targets)
    distribution = {t: base for t in targets}
    for i in range(remainder):
        distribution[targets[i]] += 1
    return distribution


def exact_split(targets, exact_allocations):
    # exact_allocations is dict {target: exact_load}
    total = sum(exact_allocations.values())
    distribution = {t: exact_allocations.get(t, 0) for t in targets}
    if total != sum(distribution.values()):
        raise ValueError("Exact allocations sum mismatch")
    return distribution


def percentage_split(targets, percentages, load):
    # percentages is dict {target: percent_float} summing to 1.0
    distribution = {}
    allocated = 0
    for t in targets[:-1]:
        count = int(load * percentages.get(t, 0))
        distribution[t] = count
        allocated += count
    distribution[targets[-1]] = load - allocated  # assign remainder
    return distribution
OutputSuccess
Alternatives
Round-robin
Distributes load sequentially in a fixed order without considering capacity or ratios.
Use when: Use when targets are homogeneous and simple, low-latency distribution is needed.
Weighted load balancing
Assigns weights to targets and distributes load proportionally, similar to percentage split but often dynamic.
Use when: Choose when target capacities change frequently and dynamic adjustment is required.
Summary
Split strategies control how load or tasks are divided among multiple targets.
Equal, exact, and percentage splits offer different ways to balance or allocate load precisely.
Choosing the right split strategy depends on target capacities, load predictability, and fairness requirements.