DevOpsInterviewPrep logo
← ☸️ Containers & Kubernetes
Foundational

Kubernetes Jobs and external effects: completion is not exactly-once execution

Separate Kubernetes Job completion from external transaction correctness. Use stable operation identity and reconciliation when a worker dies after committing an effect.

TL;DR: A Kubernetes Job manages Pods toward a completion target. Its program can run more than once, including after ambiguous failures. Make external effects idempotent or reconcile them by a stable operation key; a one-Pod configuration does not establish exactly-once business execution.

Controller progress and business progress differ

A Job controller observes Pod state. An external database or API observes the worker's requests. If a worker commits a payment export and its node disappears before completion is recorded, the controller may arrange another attempt while the external system already contains the export.

Kubernetes explicitly cautions that even a single-completion Job can sometimes start the same program twice in its Job documentation. Parallelism limits and restart policy describe orchestration behavior, not a transaction spanning Kubernetes and an external service.

rendering diagram…

Give the logical work an identity

Use a stable key for the business operation, such as an export period plus dataset revision. A Pod UID changes across attempts and therefore usually identifies the attempt, not the operation to deduplicate. Keep both: one connects logical work, the other helps diagnose each execution.

The external effect and deduplication record must have a sound atomicity story. In a database, a transaction can commit the result and its unique operation key together. Writing a “done” row before the effect can lose work after a crash; writing it afterward can duplicate work if the crash falls between them. For an external API, use its supported idempotency contract or reconcile the operation's durable identifier.

Failure pointExternal evidenceSafe next decision
Before requestNo operation existsRetry under the same logical key
After commit, before acknowledgementCommitted result may existQuery or safely replay the same key
After partial multi-step effectIncomplete progress recordResume or compensate from recorded state
Deterministic invalid inputRepeat will fail identicallyFail and correct input instead of retrying indefinitely

Bound retries without confusing them with correctness

backoffLimit limits failed attempts under the Job's rules; activeDeadlineSeconds bounds active time. They reduce endless resource consumption but cannot deduplicate an already committed external effect. restartPolicy: Never avoids in-Pod container restarts while allowing controller-created replacement Pods under the Job policy.

Choose the bounds from recovery requirements and expected operation duration, then test the observed behavior on the supported cluster version. More advanced indexed-Job and Pod-failure policies can classify failures and work items, but their availability and semantics must be checked for that version.

For a tabletop rehearsal, place a crash at each row in the table. The reviewer should identify the durable evidence used on retry and explain whether the effect can safely repeat. For an executable service test, inject the crash after commit and verify that a second attempt returns the existing result rather than creating another. No cluster success flag can substitute for that assertion.

Self-check: parallelism: 1, completions: 1, and restartPolicy: Never are configured. Is a unique external insert now guaranteed? No. Those settings do not supply an atomic business-operation ledger.

Use the duplicated batch effect to practice the distinction between attempt identity and operation identity.

RELATED CONCEPTS
PRACTICE THIS IN REAL QUESTIONS