But for Flink isn't it true that a fusion break does not convert nondeterministic output to stable input anyhow? Only waiting for a checkpoint does that?
Kenn On Mon, Nov 30, 2026 at 7:22 AM Jan Lukavský <[email protected]> wrote: > Hi Alisha, > > I think this boils down to several options we have to tackle this: > a) break fusion just before every @RequiresStableInput ParDo (this is > known to come with performance penalty even for pipelines that don't need > it), or > > b) add @Deterministic annotation that will allow to fuse annotated ParDos > into the stage that should be stable, or > > c) add @NonDeterministic annotation that will explicitly _forbid_ fusing > into stable stage (before the stable ParDo) > > d) add a brand new "fusion break" marker to the pipeline directly from SDK > > The rest would be non-reliable guesses and therefore would need b), c) or > d) nevertheless. > > Now, currently the default in Beam model is that _any_ DoFn _can_ be > non-deterministic. This would suggest a correct approach would be b), but > that implies a lot of boiler plate code, as majority of real-life DoFns are > likely deterministic (at least those without external data sources). Option > d) is too low level, applies only to portable pipelines and works with > internal concept (fusion) that is not otherwise visible to the SDK. > > I'm therefore leaning towards option c) - this actually adds an option for > pipeline authors to resolve the fusion instability bug that can currently > be solved only via artifical Repartition/Reshuffle. > > To make this more clear to users we might not introduce it as an > annotation, but maybe something like ParDo.ofNonDeterministic() (Java SDK), > which might be more comprehensible. > > The question (probably for Beam 3.0) would be if we should change our > assumption that DoFns can be non-deterministic by default and rather > motivate users to use deterministic logic and mark the > non-determinstic/non-stable (e.g. fetches from external db) explicitly. > > I'd also like to head what others think about this. > > Jan > On 11/25/26 08:20, Alisha wrote: > > Hi all, > > I'd like to restart the discussion on > https://github.com/apache/beam/issues/24655 (originally raised by Jan in > the Dec 2022 thread "@RequiresStableInput and Pipeline fusion"). I've been > working on @RequiresStableInput in the Flink runner (#41448, #41514, > #41519) and would like to help move this one forward. > > == The problem == > > A runner can only guarantee stable input at the boundary of an executable > stage. If GreedyPipelineFuser fuses NonDeterministicDoFn -> StableDoFn into > one stage, the runner makes the input to the *stage* stable, but on retry > the leading DoFn re-runs and the StableDoFn sees different input. > RequiresStableInputIT reproduces this with MapElements(PairWithRandomKeyFn) > followed by a stable DoFn. Today the only workaround is an explicit > Reshuffle (or other fusion break) right before the stable DoFn. > > The counter-concern (Kenn, on the issue): always breaking fusion is > expensive. Dataflow saw major regressions when it did this, because many > SDK transforms put a cheap projection between a checkpoint and the stable > DoFn (e.g. GBK -> drop keys -> write files). For context, the original > Dataflow implementation (PR 5787 in the design doc, > s.apache.org/requires-stable-input) was exactly this: every stable ParDo > T was replaced by Reshuffle + T, so that's the behaviour the regression > numbers refer to. > > == Options == > > 1. Unconditional fusion break in the fuser > GreedyPipelineFuser (and the Python fn_api fuser) ends the stage before > any ParDo with requires_stable_input = true, unless its input is already a > stage boundary. This also covers the "ParDo immediately after a GBK" corner > case left open in the design doc's future work. > + Simple, correct by default, no new user-facing API. > - Extra materialization for the GBK -> projection -> sink pattern. As > far as I understand, this only affects runners using the shared fuser > (portable Flink/Spark/Samza, etc.), not Dataflow. > > 2. Opt-in determinism marker (the direction from the issue) > Add a determinism property (e.g. @Deterministic in Java, plus a field > next to requires_stable_input in the proto so it works cross-language). A > PCollection is stable if it comes from a stage boundary/checkpoint, or from > a deterministic transform applied to stable input. The fuser keeps fusing > only through stable chains. The default is non-deterministic, i.e. break > fusion. (This isn't covered in the original design doc.) > + Correct by default, and recovers the performance of option 1 wherever > transforms are marked. > - New API surface. Determinism belongs to the user fn, not the > transform (MapElements can't be blanket-marked). Mis-annotation silently > brings the bug back, and it is hard to test. > - Realistically most adoption comes from SDK-internal transforms > (Values, Keys, file-write internals), IO authors, and auto-insertion by > SQL/YAML, where the logic is easier to analyze. > > 3. Heuristics > Infer non-determinism from signals like @StartBundle/@FinishBundle, > state/timers, or side inputs. > - As Jan noted, these aren't sufficient. At best they work as a > negative signal ("never treat as deterministic"), not as a way to prove > determinism. > > 4. Keep fusion as is: validate and document > Runners check the pipeline requirements and reject (or warn on) a > stable ParDo fused behind non-boundary transforms, as Luke suggested in the > original thread. Document Reshuffle as the required pattern. Also tie this > to the Redistribute work: either Redistribute is defined as an > unconditional fusion break, or we add an explicit "must break fusion" hint, > so deprecating Reshuffle doesn't remove the workaround. > + Cheapest, no behaviour change. > - Leaves a silent correctness hole for anyone who doesn't read the docs. > > Note: a fusion break is necessary but not sufficient. It only puts the > stable DoFn at the start of a stage; each runner still has to make that > stage's input stable (e.g. buffering until checkpoint on Flink). As Luke > suggested in the original thread, runners can check requires_stable_input > on the ExecutableStage to decide this. > > == Strawman == > > - Phase 1: option 1 in the shared fusers (correctness first), possibly > behind an opt-out option for users who knowingly rely on the old behaviour. > Add a portable ValidatesRunner test based on RequiresStableInputIT without > the Reshuffle. > - Phase 2: option 2 with a proto-level determinism field. Mark the obvious > SDK-internal transforms first, then explore auto-marking for SQL/YAML. > - In parallel: settle the fusion-break semantics of Redistribute, or add > an explicit hint. > > == Questions for the list == > > - Is a default fusion break in GreedyPipelineFuser acceptable for the > portable runners, given that the regression data we have comes from > Dataflow? > - Should determinism be a DoFn-level or a transform-level property, and > should it live in ParDoPayload or in a transform annotation? > - Which SDK transforms sit between a checkpoint and a stable DoFn today, > so they could be marked first? (Pointers welcome.) > - Any objection to tying this to the Redistribute/fusion-hint discussion? > > I'm happy to write this up as a design doc once there's rough agreement on > the direction. > > Thanks, > Alisha > >
