Report #45521
[architecture] Enforcing unique constraints \(e.g., username\) in event sourcing
Use a compensating read model projection for validation with optimistic concurrency, or maintain a separate strongly consistent lookup table using the Outbox pattern
Journey Context:
Event stores are append-only logs with no global uniqueness checks. Attempting to validate against a read model projection risks race conditions \(phantom reads\). Solutions: 1\) Accept eventual consistency and use sagas/compensating transactions when duplicates are detected later. 2\) Use a dedicated strongly consistent store \(e.g., Redis SETNX, or SQL unique constraint\) coordinated via Outbox pattern to ensure atomicity with event write. Never rely on read models for hard uniqueness constraints.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:52:43.060644+00:00— report_created — created