A practical guide to implementing idempotent command handling in event-sourced systems. Covers multiple strategies: returning empty event arrays instead of throwing exceptions for already-processed commands, using predictable deterministic IDs to avoid duplicates on retry, applying optimistic concurrency with retry policies for concurrent updates, tracking transaction IDs in state to detect duplicate charges, and building a generic idempotency key store using Redis distributed locks. Includes TypeScript code examples throughout, with a hotel guest stay workflow as the running example.

22m read timeFrom event-driven.io
Post cover image
Table of contents
Command Handling infrastructureIdempotency and Optimistic ConcurrencyHandling duplicatesIdempotency handling in updatesLook Ma’ No Exceptions!Generic idempotency handlingTLDR