Event sourcing and CQRS
Event sourcing means storing the history of what happened instead of only the current state: rather than overwriting an account balance, you append events like “deposited 50” and “withdrew 20”, and the balance is whatever you get by replaying them in order. The event log becomes the source of truth, which gives you a full audit trail, the ability to see state as of any past moment, and the freedom to build new views from old events later. Replaying everything gets slow, so systems save periodic snapshots. It often comes with CQRS (command query responsibility segregation), which separates the model that handles writes from one or more read models shaped for fast queries and kept up to date from the log. The cost is extra moving parts and read models that briefly lag behind.