---
slug: "IdempotentWrite"
name: "IdempotentWrite"
type: "Primitives"
layer: "Infrastructure"
ref: "IdempotentWrite#7226"
sema_id: "sema:IdempotentWrite#mh:SHA-256:7226e14f5caed42394b33c28989972451a03b43ba531e8cb6a9975a0fee4ab2c"
tags: ["Infrastructure","Primitives"]
updated: 2026-11-11
mindscape: "bootstrap"
index_url: https://mindscape.pages.dev/bootstrap/index.json
url: https://mindscape.pages.dev/bootstrap/IdempotentWrite/
related: ["Cache","Equivalence","StateLock","StateSnapshot","sema:UniqueHandle#mh:SHA-256:c3fb079be6908528bb340de26feb85f429a61fc13db10e728ea0ec3fffb19110"]
---

# IdempotentWrite

Safe retries via unique keys

Layer: Infrastructure · Category: Primitives

## Mechanism

A technical primitive where every write request includes a unique 'Idempotency Key'. The receiver maintains a [Cache](https://mindscape.pages.dev/bootstrap/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://mindscape.pages.dev/bootstrap/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://mindscape.pages.dev/bootstrap/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).

## Builds on

- [Cache](https://mindscape.pages.dev/bootstrap/Cache.md) (Infrastructure; References)
- [Equivalence](https://mindscape.pages.dev/bootstrap/Equivalence.md) (Infrastructure; References)
- [StateLock](https://mindscape.pages.dev/bootstrap/StateLock.md) (Society; References)

## Used by

- [StateSnapshot](https://mindscape.pages.dev/bootstrap/StateSnapshot.md) (Infrastructure; References)

## Identity

- Sema ID: `sema:IdempotentWrite#mh:SHA-256:7226e14f5caed42394b33c28989972451a03b43ba531e8cb6a9975a0fee4ab2c`
- Ref: `IdempotentWrite#7226`
- Supersedes:
  - `sema:IdempotentWrite#mh:SHA-256:6c557713e21198238066f28ec889d6c877caab1f34d58c41baca371919e051af`
  - `sema:IdempotentWrite#mh:SHA-256:9b95e06ae2e4eec89639328bae9c7988f4b5873ff676a1a5f040bf73373e7857`
  - `sema:IdempotentWrite#mh:SHA-256:e919903ac4044c9761bbdae612c360150f12e679dcc608ee7389f793debda186`
  - `sema:IdempotentWrite#mh:SHA-256:ebf5e8d3d5a4802033179f871bf4dfd0be7c611ab7534ab8b8e07e5f21eab7d0`
  - `sema:IdempotentWrite#mh:SHA-256:fb8b8f05286097c6456e4273ad99a144d856554828ef15b9bd351cfcb45ae8a3`

## Links

- [Pattern page](https://mindscape.pages.dev/bootstrap/IdempotentWrite/)
- [View in the interactive graph](https://mindscape.pages.dev/bootstrap/#IdempotentWrite)
- [JSON](https://mindscape.pages.dev/bootstrap/IdempotentWrite.json)
- [Index of all patterns](https://mindscape.pages.dev/bootstrap/index.json)
