Hi Joao, Thanks for writing this up. Two notes, on questions 3 and 6.
3. Condition-only has a cost too. Since a park goes through the existing suspend path, a parked job would show as SUSPENDED, and parks would count in the SUSPENDED lifecycle metrics together with manual suspends. It does avoid the CRD change, and after a downgrade an older operator would still read the status and resume parked jobs like a manual unsuspend. So to me it comes down to whether a separate state in kubectl and the metrics is worth the upgrade and downgrade constraints of a new enum value. 6. I found nothing in JIRA that would make this unnecessary. The closest is FLINK-41262 (PR #1237, open), which would remove the JobManager on a savepoint suspend, but only when HA is off, so with HA on the JobManager is still retained after a savepoint suspend. Best regards, Sepuri Sai Krishna On Mon, Nov 23, 2026 at 7:29 PM Joao Boto <[email protected]> wrote: > > Hi everyone, > > I'd like to discuss scale-to-zero for FlinkDeployments. This is a pre-FLIP > discussion, not a FLIP: I have a draft design ( > https://docs.google.com/document/d/1EnpC9RqvfLE0Y14YtpCLmQp0adHzLlAa1G6tp7MfSd4), > but I'm not asking for a design review. > What I'd like to settle first is narrower, whether this is worth solving in > the operator at all, whether the operator is the right home, and whether > the shape below is the one worth writing up. > If the list thinks it is, I'll file a proper FLIP and we can review it > there. > > > *The problem* > Event-driven jobs (Kafka topics, webhooks, low-volume domain events) are > idle most of the time, and an idle streaming job still costs a JobManager > and at least one TaskManager. > The operator already scales such a job down to its minimum parallelism and > never stops it. The only way to stop it is spec.job.state: suspended, a > field the user or their GitOps tool owns, and the status API cannot express > what happened: a stopped job reports jobStatus.state=FINISHED, the same as > a job that ended, and lifecycleState derives SUSPENDED only from the last > reconciled spec. > > So every team that wants scale-to-zero writes an external controller that > patches the spec, invents its own markers to tell its parks from manual > suspends, and rediscovers the same safety rules. flink-siesta ( > https://github.com/patrk/flink-siesta) and Solstice ( > https://github.com/Ergane-Foundation/solstice) both do this by writing > spec.job.state, and so does an external controller we run in production. > > *The proposal, in five bullets* > > 1. Park holders: an annotation under park.flink.apache.org/ per actor > (idle controller, maintenance, ...). Level-triggered and independent, like > finalizers: the operator parks while at least one holder exists and > resumes when the last one is removed. The operator never writes holder > annotations. > 2. A PARKED lifecycle value and a Parked condition. The condition > carries the phase in its reason (Parking, Resuming, ...), so kubectl wait > --for=condition=Parked means "zero pods". No new status fields: what a > resume needs is already in jobStatus.checkpointInfo / savepointInfo. > 3. Park and resume reuse the existing suspend/restore path: take a > checkpoint (or a savepoint), remove the JobManager, restore from HA > metadata or the recorded savepoint. The operator never writes > spec.job.state, so GitOps ownership and manual suspends are untouched, > and a manual suspend always wins. > 4. Rules enforced by the operator: a job must have reached RUNNING > before it can be parked, a spec change resumes a parked job, and > parks/resumes are bounded to keep a fleet from restarting at once. > 5. Three configs: park.enabled (default false), park.max-concurrent, > park.state-mode. > > *What a user still needs* > > A parked job has no JobManager, so nothing inside Flink can observe that > work has arrived. A wake signal has to come from outside; I think that is > inherent to scale-to-zero rather than a gap in the proposal. Rather than > ship an extension point with no implementation behind it, the proposal > would ship a reference wiring: a KEDA ScaledObject on the job's > consumer-group lag, scaling a one-pod helper Deployment that removes the > holder when it starts and adds it back in preStop. KEDA's cooldown is then > the idle cooldown: > > apiVersion: keda.sh/v1alpha1 > > kind: ScaledObject > > metadata: > > name: my-topic-job-park > > spec: > > scaleTargetRef: > > name: my-topic-job-park # the one-pod helper Deployment > > minReplicaCount: 0 > > maxReplicaCount: 1 # one pod is the whole signal > > cooldownPeriod: 3600 > > triggers: > > - type: kafka > > metadata: > > bootstrapServers: my-cluster-kafka-bootstrap:9092 > > consumerGroup: my-topic-job > > topic: my-topic > > lagThreshold: "1" > > > That is the whole external footprint: a Deployment, a ScaledObject and a > Role, about 70 lines of YAML, no controller code and no new operator > dependency. > The helper needs patch on FlinkDeployments, which is the same authority as > writing spec.job.state today, so the feature adds no new capability, only a > safer place to put it. > > *What it deliberately does not do* > > - No engine changes, and no source-specific clients in the operator. > - No operator-side idle detection in the first version. It is tempting > (the autoscaler already collects backlog and busy time), but a Kafka source > only registers its pendingRecords metric after its first non-empty poll, so > metrics cannot yet distinguish "idle" from "never received data". That > needs a small connector change (register the gauge from reader start, > plus a has-consumed-at-least-once guard), which I would rather land > separately than use to block this. Same conclusion for a probe SPI: > nothing usable ships with it today. > - Session jobs and blue/green children are out of scope. > - Bounded jobs are documented as unsupported: the operator cannot tell a > bounded job from a streaming one. > > *Where this comes from* > > We run the external (spec-writing) version in our clusters, the > operator-side implementation proposed here is not written yet. > Six failure modes we hit are what the design is built around, and each maps > to one rule: > > - suspension flapping on a scaler's "inactive" signal > - parking a job before its first run, which then had no wake signal > - upgrades deferred indefinitely while suspended > - stale ownership markers resuming a manually suspended job > - a retained JobManager after savepoint suspends > - and burst resumes on shared spec changes. > > > Evidence, if it helps judge the benefit: we run the external (spec-writing) > version on about 500 FlinkDeployments in production and staging, nearly all > of them wired to a KEDA ScaledObject exactly as above. > A quarter of their deployment-time is spent parked: roughly 125 jobs parked > at any moment, some 21,000 park-hours a week, with an average job parking > and resuming about once a day. > A resume takes 85s at p50 and 2-3 minutes at p99, and the "parked with > pending work" condition that a naive implementation gets wrong is observed > about 900 times a month across the fleet, which is why the safety rules > above are in the design. > > *Questions* > > 1. Is it worth it? Given that a wake signal has to come from outside > anyway, does an operator-owned park state deliver enough over "an external > controller writes spec.job.state", which works today? What would make it > clearly worth having in the operator? > 2. Is the operator the right home? It already owns suspend/restore, > recovery, rollback and upgrades, which is why I think the state has to live > there, a separate controller can only participate by writing the spec. > If you'd prefer a separate component, how should it interact with > recovery and rollback? > 3. Is a PARKED lifecycle value justified, or should this be > condition-only? Adding values to persisted enums has downgrade implications > which the draft documents. > 4. Holders versus a single park flag: holders let independent actors not > cancel each other's parks. Is that the right complexity for a first > version? > 5. Is a KEDA example the right reference implementation, or should > the project > own a small scaler? > 6. Is anything already planned in this area that would make this > unnecessary? > > > As proposed, it would be off by default, add no spec fields and write only > status, but that includes a new lifecycleState value, and the CRD schema > enumerates the allowed values, so the CRD has to be upgraded before the > operator. > I'll summarise the replies in this thread and file the FLIP if the > direction holds, if it doesn't, I'll say so here and close the thread. > > Thanks, > Joao Boto
