Skip to main content
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

Or via MiddlewareConsumer with a thin wrapper that holds the Arc<IdempotencyOptions>.

Behavior

  1. No key → pass through (or 400 if required)
  2. Completed key → replay body/status + idempotency-replayed: true
  3. In flight → 409 { "errorCode": "IDEMPOTENCY_IN_FLIGHT" }
  4. First writer → run handler, then complete with status/body/content-type

Store trait

Exactly one concurrent 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.

See also