nestrs-idempotency deduplicates mutating requests by Idempotency-Key (configurable header). First writer executes the handler and stores status + body; replays return the cached response with idempotency-replayed: true. In-flight collisions return 409.
Install
Options
Middleware
MiddlewareConsumer with a thin wrapper that holds the Arc<IdempotencyOptions>.
Behavior
- No key → pass through (or 400 if
required) - Completed key → replay body/status +
idempotency-replayed: true - In flight → 409
{ "errorCode": "IDEMPOTENCY_IN_FLIGHT" } - First writer → run handler, then
completewith status/body/content-type
Store trait
begin_or_get wins (Ok(None)); others get IdempotencyBusy.
Security
- Scope by authenticated user/tenant — never share a global key namespace.
- Prefer Redis TTL in multi-instance deploys.
- Details: security notes.