Contents · 5 sections
1Why key-based partitioning pins the heaviest key on one worker2Split each key into pieces that fit on one partition, then pack the splits with LPT3Events in the current window are counted while they are routed; the new function is used on the next window4In production the busiest worker is only 9.8% above the mean5A change in the distribution is reflected from the next checkpoint; after a restart the previous function is reusedSHARE
The heaviest key carries 5.2% of the traffic, so key-based partitioning can load the busiest worker at about eight times the mean: how CheckCo recomputes routing after each checkpoint
A distributed stream processor tags each event with a key, such as an event type, and sends it to a downstream subtask. A common policy is to partition by key: every event of the same key goes to the same worker. That is required when downstream operators keep per-key state, and it is often used even in stateless pipelines so that output stays together. In Flink this is built-in KeyBy.
Real event streams are rarely uniform. A few keys contribute most of the traffic. If those heavy keys are given in full to a single worker, the busiest subtask caps the throughput of the whole pipeline. The paper measures a production ingestion pipeline that processes over 100 billion events per day, with parallelism P=128. On 6 October 2026, the heaviest key accounted for 5.2% of all events. Even if that key were split evenly across two workers, it alone would put about 3.3 times the mean load on each of them, because 5.2% already exceeds 2/P≈1.6%. A method such as PKG (Partial Key Grouping), which only picks the less loaded of two candidate workers, therefore cannot bring the load back to the mean.
Why key-based partitioning pins the heaviest key on one worker
That day has 1,315 event types. The top 10 keys account for 32.9% of events, and the heaviest key is about 69 times the per-key mean and 2.6×10^5 times the median key. On the daily totals, only 36 keys exceed the target load L=⌈N/P⌉, the mean share of one worker. Those are the keys CheckCo later splits.
Under KeyBy, the heaviest key alone would give its subtask at least 6.7 times the mean load. The paper cannot compare KeyBy directly in production: CheckCo has been running on this stream for over a year, and no KeyBy trace remains. It therefore simulates KeyBy from the day’s per-key totals, assigning each key to one of 128 subtasks uniformly at random, as a stand-in for Flink’s hash-based keyBy. Over 3,000 independent trials the mean imbalance ratio is 8.03, the p99 across trials is 12.67, and the floor is that 6.7× bound. The imbalance ratio R is the busiest worker’s load divided by the mean load; R=1 is perfect balance. At 8.03, the busiest subtask would have to process about eight times the mean load to keep up with the stream.
Balance is not free if every key is sprayed across every worker. The number of workers that receive a key is its fan-out. Each extra worker adds a shuffle channel and downstream state. The question is how many workers each key needs, not whether the stream can be spread.

Split each key into pieces that fit on one partition, then pack the splits with LPT
CheckCo does this in two steps. It first cuts each key, in proportion to its estimated frequency, into pieces that fit on one partition, called splits. It then packs those splits onto the P workers with the Longest Processing Time (LPT) greedy rule. Light keys keep a single split; heavy keys receive roughly as many splits as their load requires.
The paper gives a four-key toy example. Let K={A,B,C,D} and P=2, with estimated frequencies ĉ(A)=60, ĉ(B)=20, ĉ(C)=12, and ĉ(D)=8. The total is N=100, so the target load is L=⌈100/2⌉=50. Then σ(A)=⌈60/50⌉=2, and the other three keys get 1. A is cut into two splits of size 30; B, C, and D have sizes 20, 12, and 8.
LPT packs splits from largest to smallest, always onto the currently least-loaded worker, and breaks ties by worker identifier so the assignment is deterministic. First ⟨A,0⟩=30 goes to w0; then ⟨A,1⟩=30 goes to w1; then both workers have load 30, so B=20 goes to w0 by worker identifier, making the loads 50 and 30; then C=12 goes to w1; then D=8 also goes to w1. Both workers end at 50, equal to the mean N/P. If all of A stayed on one worker, the loads would be 60 and 40, a max-to-mean ratio of 1.2 instead of 1.0.
Online routing is a lookup plus a modulo. Each event carries a non-negative unique identifier uid, the split index is i=uid(e) mod σ(k), and the destination is π(k,i). In the example, an A event with uid=7 has 7 mod 2=1 and goes to worker 1; uid=8 goes to worker 0. C has a single split, so any uid goes to worker 1. The paper assumes that, within each key, the residues of uid modulo σ(k) are close to uniform; if the identifiers are consecutive, each split receives ⌊c/σ(k)⌋ or ⌈c/σ(k)⌉ of the events. It does not say who assigns uid, and it treats the production result that 112 of 128 subtasks finish within −3.1% to +1.4% of the mean as consistent with that assumption. A key that first appears in the current window and is still missing from the estimate is sent to partition P−1 until the next checkpoint.
Events in the current window are counted while they are routed; the new function is used on the next window
CheckCo needs no prior statistics. Each CollectorOperator subtask counts keys locally and forwards events unchanged. At a checkpoint barrier those local maps are merged into one frequency map, and the PartitionerOperator runs the algorithm of the previous section to obtain a new partitioning function π.
The timing is staggered. Events in window Wx are routed with the function π_{x−1} computed at the previous checkpoint, and they are counted by key at the same time. At barrier x those counts are merged and π_x is computed. π_x then routes the next window Wx+1, whose counts will be used to build π_{x+1}. The traffic seen in one window changes routing only in the next. The paper therefore assumes that the key distribution changes little from one window to the next. A shorter checkpoint interval makes that assumption easier to meet, at the cost of more frequent merges. Hoot says
The four-key toy example from the article is reused only to show when routing changes at the first checkpoint, not as a production measurement.
Source
Staggered windows and Figure 2: paper §IV windowed operation. Cold start πcold(k,0)=k mod P: §IV-C. The four-key frequencies and packing reuse the article's previous-section toy example (paper Table II): ĉ(A)=60, B=20, C=12, D=8, P=2, L=⌈100/2⌉=50; A is cut into two splits of 30, both workers end at 50; if all of A stayed on one worker the loads would be 60 and 40.Before the first checkpoint completes, no estimate is available. Every key then has a single split and is sent to k mod P, which concentrates each key on one partition just as KeyBy does. If the stream is skewed, so is the load in this cold-start phase. Split-based routing takes effect only after the first checkpoint completes.
In the production pipeline the downstream operator is a file writer that serialises valid events into object storage. It holds no per-key routing state, so remapping splits between windows is safe. The paper also states that CheckCo targets this ingestion-and-file-writing setting, where there is no keyed state to migrate, rather than general stateful operators.
In production the busiest worker is only 9.8% above the mean
The experiments run on a production Flink 2.1.3 cluster with 16 TaskManagers of 8 slots each, parallelism 128, and a 10-minute checkpoint interval. 6 October has no restart and is used for the steady-state evaluation. Imbalance ratios are computed from the events each subtask actually received, not from the oracle estimates.
That day, CheckCo’s cumulative 24-hour imbalance ratio ends at 1.10, so the busiest subtask is only 9.8% above the mean. The ratio settles within the first hour and then stays between 1.07 and 1.10. Over 5-minute intervals the mean is 1.21, the p99 is 1.42, and 97% of intervals are at or below 1.3. The simulated KeyBy cumulative ratio for the same day is 8.03. Peak throughput is 1.75×10^6 events per second. The file writer commits its files when a checkpoint completes, so an event becomes visible in object storage only then, and visibility is governed by the checkpoint interval rather than by routing.
| Metric | KeyBy | CheckCo |
|---|---|---|
| Cumulative 24 h imbalance ratio | 8.03 (simulated) | 1.10 |
| p99 over simulation trials | 12.67 (simulated) | — |
| 5-min imbalance ratio (mean) | — | 1.21 |
| 5-min imbalance ratio (p99) | — | 1.42 |
| Peak throughput (events/s) | not measured | 1.75×10^6 |
Numbers are from the paper’s Table III for 6 October 2026. CheckCo values are measured in production. The KeyBy imbalance is a simulation on that day’s per-key totals, because no KeyBy trace of this stream is available. KeyBy throughput was not measured.

Of the 128 subtasks, 112 end the day within −3.1% and +1.4% of the mean. The 16 most loaded are those with the highest indices, 112 through 127. A simulation that uses only the per-key counts shows a similar pattern, so the paper attributes it to the deterministic packing of LPT rather than to the production environment.
Over the 30 days from 18 September to 17 October 2026, the daily cumulative ratio has a median of 1.09 and ranges from 1.04 to 1.12. The job was restarted 85 times on 26 of those days, and the median is 1.09 both on days with restarts and on the four days without, so those restarts did not visibly change the daily cumulative ratio.
A change in the distribution is reflected from the next checkpoint; after a restart the previous function is reused
Because π_x is built from the counts of Wx and applied to Wx+1, a shift inside a window is reflected in routing only from the next checkpoint on. On 6 October the largest 5-minute imbalance ratio, 3.63, occurred at 12:15–12:20 UTC (Coordinated Universal Time) and lasted one interval. The ratio stayed between 1.24 and 1.41 until the 12:42 checkpoint, then returned to its usual level. Such episodes last at most a few checkpoint intervals and barely move the cumulative ratio, which stays at 1.10 across this one.
On restart, the partitioning function is recomputed from the counts restored from broadcast state, so routing resumes with the pre-failure function rather than with cold-start k mod P. On 17 October the job was restarted at 14:12, 18:35, and 20:27 UTC. The cold-start rule, computed on the per-key counts of 6 October, would give a ratio of 8.15; no interval near that level appears after any of the three restarts. After the first restart the pipeline drains its backlog at up to 3.83×10^6 events per second, more than twice the normal rate, while the 5-minute imbalance stays between 1.13 and 1.25. Over that day the cumulative ratio is 1.07 and the 5-minute mean is 1.23 (p99 1.34), in line with the restart-free day.

In a one-shot simulation that gives CheckCo the exact counts of the day, the imbalance ratio is again 1.10 and the total fan-out is 1,378, within 5% of the KeyBy minimum of 1,315, because only keys above the target load are split. In the same simulation D-Choices reaches 1.01 with a fan-out of 3,136, about 2.3 times as large, and W-Choices is near perfect with a fan-out of 15,977, about 12 times as large. That simulation hands CheckCo the exact counts once, so it evaluates the routing function itself, not the dynamic oracle. The simulated 1.10 matches production, and the paper reads this as consistent with the remaining imbalance coming mainly from split granularity rather than from the lag between estimation and use. In production the counts are built from the live stream and carried across restarts in broadcast state; over 30 days the daily cumulative ratio stayed between 1.04 and 1.12.
The KeyBy figure of 8.03 is a simulation on that day’s per-key totals, not a production A/B measurement; CheckCo’s 1.10 is the cumulative production ratio of the busiest worker to the mean. Remapping splits between windows depends on the downstream writer holding no per-key routing state.
How did this read for you?
Hoot made a note. Thanks for the feedback.
One tap, no sign-in; tap again to undo. Only anonymous counts are kept, never who you are.
Discussion
Add experiment details, reproduction notes or a different take. Requires a GitHub sign-in.
Loading the discussion…