ADR 003: Redis idempotency with cached responses¶
- Status: Accepted
- Date: 2026-08-03
- Phase: 3
Context¶
Clients retry POSTs on timeouts. Without protection, retries can double-post ledger entries or bank imports.
Decision¶
Use an Idempotency-Key header with Redis:
SET key NX EX 86400claims the key for 24 hours (key = prefix + method + path + Idempotency-Key)- Store a SHA-256 fingerprint of the request body with the claim
- On first success, store status code + body + fingerprint
- Same key + same body → replay the original cached response
- Same key + different body → 409 (not a second execution)
- Replays are marked with
Idempotency-Replayed: true
Accepted risk: fail-open¶
When Redis is unreachable, the middleware logs a warning and lets the request through. Availability wins over retry protection for that moment. Redis is therefore not a hard dependency for serving traffic — only for the idempotency guarantee. Prefer fixing Redis over flipping this to fail-closed for a public demo API.
Consequences¶
- Safe retries for mutating endpoints when Redis is healthy
- Tests inject a fake Redis client so CI stays offline
- Operators should monitor
idempotency.redis_unavailablewarnings