Course outline

MLOps / Pipelines and controlled delivery / Lesson 14

Idempotent Pipeline Retries

Design retried pipeline operations so duplicate attempts do not silently create conflicting releases.

About 3 min readContent reviewed
On this page

Lesson goals

  • Define an operation identity and desired retry behavior.
  • Detect conflicting payloads for the same identity.
  • Test durable and atomic behavior in the actual system.

Define the operation boundary

A pipeline step can be retried after a timeout even if its first attempt completed. An idempotent operation has the same intended effect when repeated with the same identity and payload. Define the operation key, payload identity, completion record, and conflict behavior before adding retries to a publishing step.

A response can be lost after a side effect succeeds, so retry logic must not infer failure solely from a missing response. Distinguish a repeated request from a new release and preserve evidence of both attempts. Access control and approval checks still apply on every relevant path.

Model a repeated attempt

The in-memory example stores one synthetic operation by key and returns the existing result on a repeat. It illustrates the desired logical behavior only: a local dictionary is neither durable nor safe for concurrent workers. A production system needs an appropriately atomic and durable implementation.

python Repeat one synthetic operation
completed = {}
def publish_once(key, artifact):
    if key not in completed:
        completed[key] = artifact
    return completed[key]

print(publish_once("run-7", "model-a"))
print(publish_once("run-7", "model-a"))
print(len(completed))

Both calls return model-a, while the dictionary retains one operation key.

Reject a conflicting payload

The same key paired with different artifact identity is not an ordinary retry. The second example detects that conflict rather than silently replacing the prior result. Define whether a new operation key and approval are needed, and verify the exact artifact identity in the release record.

python Detect a key conflict
completed = {"run-7": "model-a"}
key, artifact = "run-7", "model-b"
if key in completed and completed[key] != artifact:
    print("conflict")
else:
    print("acceptable")

The stored artifact differs from the new payload, so the example reports a conflict.

Handle concurrency and recovery

A real implementation must coordinate concurrent attempts and persist state across crashes. Use the storage system’s documented atomic mechanisms and test a failure between the side effect and completion record. A check followed by a separate write can race; the toy dictionary does not solve this distributed-systems problem.

Verify with fault injection

In a bounded test environment, repeat identical requests, send a conflicting payload, and simulate timeout and restart at each important boundary. Confirm one intended release effect, a visible conflict, and an auditable state. Check rollback and authorization separately, and monitor unresolved or stuck operations for human investigation.

Common errors and fixes

A retry creates a duplicate release.

Why it happens
The first attempt succeeded but its response was lost.
How to fix it
Use a durable operation identity and reconcile the existing result.
Prevent it next time
Test retries after successful side effects.

A different artifact silently replaces the first.

Why it happens
The same key was reused for a conflicting payload.
How to fix it
Reject and investigate the conflict.
Prevent it next time
Bind operation identity to an immutable payload identity.

Two workers both pass a preflight check and publish.

Why it happens
The check and write were not atomic.
How to fix it
Use the storage system’s supported atomic coordination.
Prevent it next time
Test concurrent attempts and crash boundaries.

2 practice exercises

1. A publish call times out after the artifact was stored. What should a retry check?

Show worked solution

Look up the same durable operation identity and verify its payload and completion state. Return or reconcile the existing result rather than creating another effect.

2. The same operation key arrives with a different artifact digest. Is it a retry?

Show worked solution

Treat it as a conflict, preserve both identities, and investigate. A distinct release should use the documented new identity and approval process.

Key takeaways

  • Retries need stable operation and payload identity.
  • Conflicting payloads require explicit handling.
  • Durability and atomicity must be tested in the real system.

Official references