An idempotent embedding pipeline can receive the same event repeatedly and converge on one correct derived result. It uses deterministic identities, source and chunk checksums, explicit model versions, short job leases, bounded retries, optimistic write conditions, and reconciliation. External embedding calls happen outside database transactions; final writes succeed only if the source version remains current.
Store attempt count, available_at, lease owner/expiry, expected source checksum, model ID, and a sanitized error code. failed means human or policy attention; it is not an infinite retry loop.
Commit immediately, call the provider, then open a new short transaction. Before storing, verify source checksum, model ID, lease owner, and job status still match. Otherwise mark the result superseded.
Database conflict handling prevents duplicate keys, but the external provider may still be called twice. A complete strategy also deduplicates events, bounds financial work, handles ambiguous timeouts, and ensures repeated completion cannot overwrite newer content.
Run two workers against the same queue; prove each job is claimed once per lease. Crash a worker after the provider call but before commit. Expire the lease and retry. Change the source during processing and prove the stale result cannot become current. Reconcile all current source checksums against ready embeddings.
Design a PostgreSQL-backed embedding job state machine for [workload]. Include DDL, claim SQL with SKIP LOCKED, leases, retry classification, exponential backoff with jitter, stale-source protection, dead-letter review, metrics, and reconciliation. Show crash timelines.
Verification contract: Chaos tests must cover crash-before-call, crash-after-call, timeout ambiguity, duplicate event, stale source, expired lease, and poison input.