Bird
Raised Fist0
LLDsystem_design~7 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. Which split strategy divides an amount so that everyone pays the same share regardless of individual preferences?
easy
A. Equal split
B. Exact split
C. Percentage split
D. Random split

Solution

  1. Step 1: Understand the definition of equal split

    Equal split means dividing the total amount evenly among all participants.
  2. Step 2: Compare with other splits

    Exact split assigns specific amounts, percentage split assigns based on percent, random split is not a standard method.
  3. Final Answer:

    Equal split -> Option A
  4. Quick Check:

    Equal split = same share for all [OK]
Hint: Equal split means everyone pays the same amount [OK]
Common Mistakes:
  • Confusing exact split with equal split
  • Thinking percentage split always equals equal split
  • Assuming random split is a valid standard method
2. Which of the following is the correct syntax to represent a percentage split of 40% for user A and 60% for user B in a system design context?
easy
A. {'A': '40%', 'B': '60%'}
B. {'A': 40, 'B': 60}
C. {'A': 0.4, 'B': 0.6}
D. {'A': 4, 'B': 6}

Solution

  1. Step 1: Understand percentage representation in decimals

    Percentages are often represented as decimals between 0 and 1 in code for calculations.
  2. Step 2: Evaluate options

    {'A': 0.4, 'B': 0.6} uses decimals summing to 1, correct for percentage split. {'A': 40, 'B': 60} uses integers but not decimals. {'A': '40%', 'B': '60%'} uses strings which are not directly usable. {'A': 4, 'B': 6} uses incorrect smaller numbers.
  3. Final Answer:

    {'A': 0.4, 'B': 0.6} -> Option C
  4. Quick Check:

    Decimal form for percentages = {'A': 0.4, 'B': 0.6} [OK]
Hint: Use decimals (0.4) not integers (40) for percentage splits [OK]
Common Mistakes:
  • Using integers instead of decimals for percentages
  • Using strings with % symbol in code
  • Not ensuring sum equals 1
3. Given a total amount of 100 and a split strategy: {'A': 30, 'B': 70} as exact amounts, what is the amount assigned to user B?
medium
A. 70
B. 100
C. 30
D. 0

Solution

  1. Step 1: Identify the split type and amounts

    The split is exact, so amounts are assigned directly as given.
  2. Step 2: Find user B's assigned amount

    User B is assigned 70 as per the exact split dictionary.
  3. Final Answer:

    70 -> Option A
  4. Quick Check:

    Exact split assigns given amounts = 70 [OK]
Hint: Exact split means use given amounts directly [OK]
Common Mistakes:
  • Adding amounts instead of reading assigned value
  • Confusing exact with percentage split
  • Assuming equal split when exact is given
4. In a percentage split system, if the sum of percentages provided is 110%, what is the main issue and how should it be fixed?
medium
A. The sum is valid, no fix needed
B. The sum should be exactly 0%, reset all percentages
C. The sum is less than 100%, add missing percentage
D. The sum exceeds 100%, fix by normalizing percentages to sum to 100%

Solution

  1. Step 1: Identify the problem with sum of percentages

    Percentages must sum to 100% (or 1 in decimal) to correctly split amounts.
  2. Step 2: Determine the fix

    If sum is 110%, it exceeds total amount. Normalize by scaling percentages so they sum to 100%.
  3. Final Answer:

    The sum exceeds 100%, fix by normalizing percentages to sum to 100% -> Option D
  4. Quick Check:

    Sum > 100% requires normalization [OK]
Hint: Percentages must sum to 100%, else normalize [OK]
Common Mistakes:
  • Ignoring sum validation
  • Assuming sum can be more than 100%
  • Trying to add missing percentage when sum is too high
5. You need to design a system that supports splitting a bill among users using equal, exact, or percentage strategies. Which approach best ensures scalability and correctness when handling thousands of users?
hard
A. Allow users to input any split without checks and calculate on demand
B. Use a unified split interface that validates input and applies the correct split logic per strategy
C. Store all splits as exact amounts without validation
D. Hardcode equal split only to simplify calculations

Solution

  1. Step 1: Identify requirements for scalability and correctness

    System must handle many users and ensure splits are valid and consistent.
  2. Step 2: Evaluate design approaches

    Unified interface with validation ensures correctness and flexibility. Hardcoding or no validation risks errors and poor scalability.
  3. Final Answer:

    Use a unified split interface that validates input and applies the correct split logic per strategy -> Option B
  4. Quick Check:

    Unified validated interface = scalable & correct [OK]
Hint: Validate splits and use unified logic for scalability [OK]
Common Mistakes:
  • Ignoring validation leading to incorrect splits
  • Hardcoding one strategy limits flexibility
  • Allowing unchecked input causes errors at scale