CQRS and Event Sourcing | Oliver Sturm

Learn how CQRS and Event Sourcing patterns can improve system scalability, maintainability, and performance by separating command and query aspects, and providing a single source of truth for the system.

Key takeaways
  • CQRS (Command Query Responsibility Segregation) and Event Sourcing are patterns that help separate the command and query aspects of an application.
  • In CQRS, there are two main parts: command processing and query processing, which are executed separately and can have different data models.
  • Event Sourcing records every command as an event, creating a database of all changes made to the system.
  • The event log is the source of truth, and the current state of the system can be derived from it at any time.
  • Read models are used to provide a simplified view of the data for querying, and are derived from the event log.
  • Commands can be validated before being executed, and can trigger different events based on their outcome.
  • Event Sourcing can improve data consistency and availability by providing a single source of truth, and can be used to implement eventual consistency.
  • CQRS and Event Sourcing can be used together to improve system scalability and maintainability.
  • The command processor and query processor can be scaled independently, which can help improve performance and reduce latency.
  • Event Sourcing can be used to improve data access patterns, such as scanning and filtering data, by providing a more efficient and scalable way to retrieve data.
  • The read model service can encapsulate multiple read models, which can be used to provide different views of the data.
  • The event log can be used to implement caching and session management, and to provide a single source of truth for the system.
  • CQRS and Event Sourcing can be used to improve system performance and reduce latency by separating the command and query aspects of the application.
  • The command processor can be used to handle commands concurrently, which can improve system performance and reduce latency.