Event Sourcing

The concept of event sourcing is to store (persisted) all the change history of the business entity and arranged according to the chronological order of the changes (time-ordered sequence).

When an entity's status is changed, a message eventwill be sent to save the entity's change history. We can persist the change immediately when the event arrives, or snapshotperiodically if the entity has a large number of events that we want to optimize. Event Sourced systems such as finance, banking or insurance are frequently used, the purpose is to store all changes in the system so that they can be processed later. this if needed.

Its strength is that we can reconstruct the state of the entity at any time, by replaying all the events that occurred up to that time. This is useful in reproducing bugs or rolling back the entity's state if an error occurs. However, this replaying all must be done with caution, because it is very possible that when replaying events commandthat affect other services, for example the OrderPlaced event is emitted, it is very possible that the OrderFulfilled event will be executed. appear more than once.

Event sourcing is often used as part of CQRS to synchronize changes Commandwith Query. However, not all systems must have sourced events, but it depends on each bounded contextAggregate's business or operations. Sourcing events should not be published outside their bounded context to avoid unnecessary dependencies between bounded contexts.

Last updated