Rescaling moves stable key groups rather than inventing new histories
Track stable key-group identity, parallel-owner reassignment, serializer compatibility, and skew while distinguishing logical redistribution from actual restore traffic.
On this page
The question for today
What you’ll understand
- Explain the role of fixed maximum parallelism and key groups.
- Calculate owner reassignment in an explicit contiguous grouping model.
- Identify compatibility and skew limits that extra parallelism does not solve.
Changing the number of workers should change where a key is processed, not which past events the key remembers. That requires stable identities below the worker level. Flink organizes keyed state into key groups that can be reassigned during restoration or rescaling. Follow those groups, the source-routing rule, and the saved state together; otherwise a load-balancing change can become an accidental reset or duplication of history.
Stable groups decouple keys from current workers
Flink 2.1 uses key groups as atomic redistribution units for keyed state, with their count determined by maximum parallelism. A key's group remains stable under a compatible key-selection and hashing setup, while ownership of groups changes with actual parallelism. The maximum-parallelism choice therefore influences future scaling and snapshot compatibility; it is not merely a display setting. Keep key types, equality, hash behavior, serializers, and operator identity compatible with the saved state. Increasing worker count cannot compensate for a changed key function that sends old and new records into different histories.
Key-group redistribution differs from operator-state redistribution. The latter follows its declared list or union semantics and can have different duplication and ownership behavior. Do not describe every saved source partition assignment or broadcast structure as keyed state. A rescale plan needs the relevant state type, its restore rules, and the connector's split ownership contract. Validate a checkpoint or savepoint intended for the operation rather than assuming any snapshot mode supports every topology change under all versions. The primary documentation and tested upgrade path determine the actual supported procedure.
Equal group counts are not equal resource demands
One group can contain a hot key or much larger values than another. Balanced counts of key groups therefore do not guarantee balanced event rates, CPU cost, resident bytes, timers, or checkpoint work. A single hot key remains a serial aggregation boundary under the ordinary keyed model. Splitting it requires an application transformation with a valid combine or sequencing argument, not merely assigning more workers. Inspect per-key or per-group skew and the state distribution before recommending a parallelism change from an aggregate utilization chart.
Physical rescale cost includes reading saved state, constructing backend structures, moving or fetching artifacts, reconnecting channels, and catching up source lag. A logical owner changes while an artifact may already be accessible in shared checkpoint storage; conversely, an unchanged logical owner may still need a full reload on a new machine. Count logical reassignment separately from network bytes. During the transition, external sink and transaction recovery rules continue to apply. A job reporting RUNNING does not by itself prove its final keyed state and visible outputs survived the rescale unchanged.
Reproduce state continuity before measuring speedup
Build a small trace with known per-key totals, a consistent snapshot, a parallelism change, and additional events. Verify every key's final value and source position, including keys assigned to different owners. Include skew and state schema evolution cases. Stable operator identifiers help associate saved state with intended operators; silently dropping unmatched state can make a fast restart look successful while losing history. Record restore duration, catch-up lag, state distribution, and visible output invariants alongside throughput so the claimed scaling benefit includes correctness.
The modular lab checks coverage in a separate toy, not Flink redistribution. Reset, explicitly set BOTH m=8 and a=3, predict all eight residues before repeating, then Play or Step. Reset and re-set BOTH m=8 and a=2; predict only four. Playback uses n=floor(2t), and edits retain t/recompute from zero. The modulus remains eight in both runs; changing stride does not simulate changing worker parallelism. Use the worked owner formula for rescaling and this finite orbit only to ask whether a hypothetical traversal actually reaches every stable group.
Work it through
Keep eight group identities while changing owners
Use M=8 equal-sized groups and j(g)=floor(gP/M). Compare P=2 and P=4. Each group holds ten MB of logical state; owner labels are reused only as labels for this example.
At P=2, groups 0–3 belong to owner 0 and groups 4–7 to owner 1. Total logical state is 8×10=80 MB.
At P=4, owners hold pairs: 0–1, 2–3, 4–5, and 6–7. Group identities and their saved contents remain unchanged.
Comparing numerical owner labels, six groups change label, representing 60 MB of logically reassigned state. This does not prove 60 MB of network transfer: restore placement and artifact access can move more or less physical data.
Parallel ownership changes while the eight stable histories still total 80 MB. Logical reassignment and physical recovery traffic are different measurements.
The living notebook
Explore the model
Interactive lab · modular
Check traversal coverage without changing group identity
For EACH run Reset, set BOTH m and a, predict, then Play or Step. Compare (8,3), period eight, with (8,2), period four; n=floor(2t), and edits retain t. This additive orbit checks toy coverage only and does not execute key hashing, worker reassignment, state transfer, or Flink rescaling.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forStable group identity, traversal coverage, and current owner assignment are separate concepts that need separate rules.
Pause & reason
Check your understanding
Your turn
Try it yourself
For M=12 and P=3, use j(g)=floor(gP/M) to assign groups 3, 4, 7, and 8. If group 4 has ten times the event rate of every other group, do equal four-group assignments prove balanced rate?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute each floor separately, then sum actual rates rather than counting groups alone.
Compare with the solution
Groups 3,4,7,8 map to owners 0,1,1,2 respectively. Each owner has four group identities, but owner 1's group 4 can dominate its load. Equal group counts do not prove balanced rates or state sizes, and maximum parallelism remains a separate stable count.
Keep the idea
Take it with you
- Stable key groups allow current owners to change without resetting history.
- Keyed and operator state follow different redistribution contracts.
- Correctness, skew, restore traffic, and catch-up need independent rescale evidence.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.