Domain Driven Design and Command-Query Responsibility Segregation Erik Rozendaal Software Development Client Domain Reporting Commands Events Query Results Application Flow Events Queries and Reporting Denormalizer Query Database Thin Query Layer updates query results Query Results Transactional Domain Command Handler Repository Aggregate Event Store 1: get aggregate 5: save aggregate 2: load events for aggregate 7: save events for aggregate 3: instantiate with event history 6: get change events 4: execute command Commands Events Benefits • Rich domain that only exposes behavior • Queries do not use the domain model • No need for object-relational mapping • Bullet-proof auditing and historical tracing • Easy integration with external systems • Performance and scalability • Testability Command-Query Separation • Separate Commands that change state from Queries that read state • All state changes are represented by domain Events • Aggregates receive Commands and publish Events • The Query database is updated as a result of the published Events • All Queries go directly to the Query database, the domain model is not involved