Overview

Two applications that fulfill the Command Query Responsibilities Segregation (CQRS) pattern implementation.

CQRS in simple terms

CQRS stands for Command Query Responsibility Segregation. It is a design pattern that enforces the separation of actions that modify the state of an application and the actions that leave the state of the application intact.

Two important terms here are:

Spring application - original architechture

This is implemented in the Spring Boot 102

Spring application - cqrs based architechture

We are going to split into two, the project that we built in spring-boot-102 tutorial. One that processes commands and another that processes queries. Below is the schematic representation of what this separation looks like.

Architecture schema

In the original architecture

In the CQRS based architecture

Technology

Step followed

# build.gradle
# compile 'com.h2database:h2' removed
compile 'mysql:mysql-connector-java' # added
touch application.properties
# content of the application.properties

spring.datasource.url=jdbc:mysql://localhost/springboot103
spring.datasource.username=spring
spring.datasource.password=spring
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect


TODO add code snippets
TODO add code snippets

Other main usage of CQRS

Event sourcing:

Definition:

Usage (with CQRS):

Resource: