TL;DR
While the "power of two choices" is a staple for load balancing in distributed stream processing, it completely breaks down at large scale under heavy data skew. This paper introduces D-Choices and W-Choices, two novel algorithms that dynamically detect "heavy hitter" keys and allocate more choices to them. When deployed on Apache Storm, these techniques improve throughput by up to 150% and reduce latency by 60% compared to state-of-the-art methods.
What Problem Does This Paper Address?
Distributed Stream Processing Engines (DSPEs) like Apache Storm and Flink rely on data parallelism to handle massive streams of real-time data. For stateful operations, systems use key grouping to ensure all tuples with the same key are routed to the same worker instance.
However, real-world data is notoriously skewed (e.g., a few trending topics on Twitter dominate the stream). To mitigate this, popular solutions like Partial Key Grouping (PKG) use the "power of two choices": each key is hashed to two candidate workers, and the tuple is sent to the least loaded one.
The authors identify a critical scalability paradox: the power of two choices fails as the system scales up. As you add more workers ($n$), the ideal average load per worker ($1/n$) decreases. If a single "hot key" generates more traffic than two workers can handle, those two allocated workers become severe bottlenecks, leading to massive load imbalance.
Methods
The authors propose splitting the incoming stream's key distribution into two parts: a head (a small number of high-frequency "hot" keys) and a tail (the remaining low-frequency "cold" keys).
- Finding the Head Online: Upstream sources run a lightweight, distributed version of the
SpaceSavingalgorithm to track heavy hitters in real time without needing massive routing tables. - Handling the Tail: The tail keys are routed using standard PKG (2 choices), which is perfectly adequate for low-frequency keys.
- Handling the Head (The Core Innovation): The authors introduce two strategies for the hot keys:
- W-Choices: Hot keys can be routed to any of the available workers ($d = n$). This provides ideal load balancing but can have a higher memory footprint if the state per key is large.
- D-Choices: A more sophisticated approach that analytically computes the minimum number of choices $d$ ($2 < d < n$) required to keep the system's load imbalance below a user-defined threshold ($\epsilon$). This minimizes both memory usage and downstream state aggregation costs.
Datasets
The algorithms were evaluated using both synthetic and real-world datasets:
- Wikipedia (WP): A log of page visits (22M messages, 2.9M unique keys) exhibiting natural skew.
- Twitter (TW): A massive dataset of words extracted from tweets (1.2G messages, 31M unique keys).
- Cashtags (CT): Twitter data centered around stock market tickers (690k messages, 2.9k keys), specifically used to evaluate how the algorithms handle concept drift (keys changing popularity over time).
- Synthetic Zipf (ZF): Datasets generated with varying skew exponents ($z$ from 0.1 to 2.0) to precisely control and test the limits of the algorithms.
Key Insights and Ideas
- The Scalability Paradox: Counterintuitively, adding more hardware (workers) to a PKG-balanced system makes it less resilient to extreme skew because it lowers the capacity threshold of the two chosen workers relative to the total stream volume.
- Targeted Replication: You don't need to replicate the state of every key to achieve perfect balance. Applying a greedy $d$-choice routing mechanism strictly to the top fraction of a percent of keys (the head) eliminates almost all skew-induced imbalance.
- Predictable Bounds: The authors successfully derived an accurate mathematical lower bound for $d$ in D-Choices, proving that a system can dynamically calculate exactly how much replication is needed on the fly.
Key Results
The algorithms were implemented in Apache Storm and tested on a cluster with 80 workers under heavy skew ($z = 2.0$):
- Throughput Boost: D-Choices and W-Choices achieved a 150% throughput improvement over PKG and a 230% improvement over standard Key Grouping. They matched the performance of Shuffle Grouping (which ignores keys entirely to achieve perfect balance).
- Latency Reduction: The proposed methods reduced the 99th percentile latency by 60% compared to PKG and by 75% compared to Key Grouping.
- Memory Efficiency: While Shuffle Grouping requires replicating state across all workers for all keys, D-Choices achieved the same performance while using up to 80% less memory, keeping the overhead minimal.
Limitations and Future Work
- Concept Drift Sensitivity: In environments where key popularity shifts rapidly (like the Cashtags dataset), the heavy-hitter algorithm takes time to adapt, temporarily increasing imbalance during the transition phase.
- State Aggregation Costs: Although D-Choices minimizes the number of choices $d$, splitting a stateful operator across multiple workers still introduces a downstream reconciliation/aggregation cost that scales with $d$. Optimizing this state reconciliation remains an open avenue for future engineering.
Summary updated