---
library: "bootstrap"
slug: "IdempotentWrite"
name: "IdempotentWrite"
ref: "IdempotentWrite#7226"
hash: "sema:IdempotentWrite#mh:SHA-256:7226e14f5caed42394b33c28989972451a03b43ba531e8cb6a9975a0fee4ab2c"
type: "Primitives"
layer: "Infrastructure"
version: "0.11.0"
root: "a6a3d1ff0f982ee30430c5b42f3784c8ec901fd68482cfc1bc30899c1e5e48c5"
license: null
url: "https://semahash.org/vocabularies/bootstrap/patterns/IdempotentWrite"
---

# IdempotentWrite

Safe retries via unique keys

Infrastructure · Primitives

## Mechanism

A technical primitive where every write request includes a unique 'Idempotency Key'. The receiver maintains a [Cache](https://semahash.org/vocabularies/bootstrap/patterns/Cache.md) of processed keys. If it receives a duplicate key, it returns the stored result without re-executing the side effects. This makes 'At-Least-Once' delivery safe. It uses a keyed [StateLock](https://semahash.org/vocabularies/bootstrap/patterns/StateLock.md) to deduplicate requests, ensuring only the first write executes while subsequent ones return the cached result.

## Invariants

- Idempotence: Apply(Apply(Req)) stands in [Equivalence](https://semahash.org/vocabularies/bootstrap/patterns/Equivalence.md) with Apply(Req) — a repeated key returns the first result rather than executing again.
- Safety: Duplicate requests trigger zero additional side effects

## Preconditions

- Receiver has state storage for keys

## Postconditions

- Action executed exactly once (logically)

## Failure modes

- Key collision (two different requests use same key).

## Where this came from

—

## Builds on

- [Equivalence](https://semahash.org/vocabularies/bootstrap/patterns/Equivalence.md) (references)
- [Cache](https://semahash.org/vocabularies/bootstrap/patterns/Cache.md) (references)
- [StateLock](https://semahash.org/vocabularies/bootstrap/patterns/StateLock.md) (references)

## Used by

- [StateSnapshot](https://semahash.org/vocabularies/bootstrap/patterns/StateSnapshot.md) (references)

## Related

- [UniqueHandle](https://semahash.org/vocabularies/bootstrap/patterns/UniqueHandle.md)

## Identity

- Library: bootstrap 0.11.0 (root a6a3d1ff0f98)
- Ref: IdempotentWrite#7226
- Hash: sema:IdempotentWrite#mh:SHA-256:7226e14f5caed42394b33c28989972451a03b43ba531e8cb6a9975a0fee4ab2c

## Links

- Page: https://semahash.org/vocabularies/bootstrap/patterns/IdempotentWrite
- JSON: https://semahash.org/vocabularies/bootstrap/patterns/IdempotentWrite.json
- Library: https://semahash.org/vocabularies/bootstrap
- Library index: https://semahash.org/vocabularies/bootstrap/index.json
