Skip to content
serhij.zolotukhin edited this page Dec 7, 2025 · 1 revision

CQRS

Command Query Responsibility Segregation (разделение ответственности на команды и запросы)

Command sourcing

Commands are issued in a language that asks something to be done (imperative generally).
Events are representations of what has happened (past-tense generally)
Replay may trigger side-effects

Event Sourcing

Идея Event Sourcing в том чтобы записывать каждое событие,
которое меняет состояние приложения в базу данных.
Таким образом получается что мы храним не состояние наших сущностей,
а все события которые к ним относятся

advantage:

Complete Rebuild: We can discard the application state completely
    and rebuild it by re-running the events from the event log on an empty application.
Temporal Query: We can determine the application state at any point in time.
Event Replay: If we find a past event was incorrect,
    we can compute the consequences by reversing it and later events
    and then replaying the new event and later events.

Unmatched traceability and debugability
Very good performance characteristics
Replay can be side-effect free

disadvantage:

The event store is difficult to query since it requires typical queries to reconstruct the state of the business entities.
The application must use Command Query Responsibility Segregation (CQRS) to implement queries.
This in turn means that applications must handle eventually consistent data.

My side bar

Clone this wiki locally