Ensuring uniqueness in Event Sourcing is a common challenge. Several approaches are explored: using unique indexes on relational databases (e.g., Marten with PostgreSQL inline snapshots), leveraging stream identifiers as natural unique keys, and the Reservation pattern for more complex cases like unique usernames or emails. The Reservation pattern involves claiming a resource in durable storage before executing business logic, with compensating actions (via Saga or Outbox patterns) to handle failures in distributed environments. The post also questions whether uniqueness is truly required in the first place, noting that the real business problem often lies elsewhere.
1 Impression