SlideShare a Scribd company logo
Microservice
Architecture
with CQRS & Event Sourcing
Ben Wilcock
Freelance Software Architect [UK]
https://twitter.com/benbravo73
https://www.linkedin.com/in/benwilcock
http://benwilcock.wordpress.com
What is CQRS?
2
‘Command & Query Responsibility Segregation’
CQRS is an architectural pattern for developing software
whereby the bits of the system that are responsible for changing
the system’s state (the ‘write-parts’) are physically separated
from the bits of the system that manage views (the ‘read-parts’)
This is in contrast to CRUD architecture where traditionally the
same component has responsibility for both the reads (the
views) and the writes (the state changes)
What is Event Sourcing (ES)?
3
Event Sourcing uses a timeline to describe state
When Event Sourcing, state is recorded as a complete series of
the events resulting from the actions taken within the domain
These persisted events can then be used to re-establish the state
of the actors within the domain at any point in time
This is in contrast to CRUD architecture where traditionally only
the current state of an entity is stored (and not the history of
events describing how it arrived at this current state)
Event sourcing complements CQRS, but CQRS does not require
event-sourcing in order to be successful
What are the Principles behind CQRS/ES?
Separation of Concerns (SoC)
A design principle for separating a
computer program into distinct
sections, such that each section
addresses a separate concern
Do one thing and do it well
A philosophy at the heart of UNIX
development that leads to small and
highly-cohesive applications
Event-Driven Architecture
Also known as Message-driven
architecture, this is a software
architecture pattern that promotes
the production, detection,
consumption and reaction to events
over other forms of integration
4
Domain-Driven Design (DDD)
A software development approach
whereby the implementation is
strongly linked to the business
domain in which it’s used
Loose-coupling
An approach to interconnecting
components such that those
components depend on each other to
the least extent practicable
Event sourcing
A mechanism for persisting
application's state by storing the
history of events or changes that
caused the system to arrive at its
current state
What are the Benefits of CQRS?
Scalability
In mosts systems the number of reads
vastly exceeds writes - yet the architecture
rarely reflects this
In CQRS the read-side is separate from the
write-side, so each can be scaled and
performance-optimised independently
Simplicity
In most systems a single model is used to
manage, describe, store and view data
This sounds simple, but it adds complexity
as contradicting requirements (writing and
reading) must be handled by a single model
With CQRS the write-model and the read-
model can be different
Flexibility
The clear separation of methods that
change state from the methods that view
state makes change simpler
Change can be made with greater
confidence and with more predictable
effects
Business Focus
Commands are intuitive and instantly
recognisable as business related actions
In CQRS this business focus together with
Domain Driven Design can result in
applications that are more responsive to
change and cheaper to maintain
5
What are the Benefits of Event Sourcing?
History has Business Value
By storing events, you never discard
information that may have future value
Events allow you to see the state of the
system at any point in the past
You can use this insight to answer historical
business questions as they arise
Easy Integration
Events are also a useful way of
communicating with other systems
Integration based on events offers very low
levels of coupling as the event producers
don’t need to know anything about the event
consumers (and vice versa)
Simplicity
By saving only events, you are avoiding the
complex business of persisting complex
domain objects to a relational store -
otherwise known as the “object-relational
impedance mismatch”
Performance
Events are simple, standalone and
immutable, so you can use faster append-
only operations to store them
Flexibility
A sequence of events can be "projected" into
any desired structural representation or
"view" at any time
6
What does CQRS/ES Architecture look like?
Multiple views
or ‘projections’
can be built to
satisfy
disparate
client
requirements
& limitations
Integrations are
unlimited, event-based
and loosely-coupled
Interactions are
modeled as
simple
‘Commands’,
‘Events’ and
‘Queries’
Events are
stored and
then forwarded
to the event
exchange
command-side
(Rules and Behavior)
query-side
(Presentation and Facts)
7
Read-side can
be scaled,
optimised and
secured
independently
of the Write-
side
Command
processing
results in
Events being
created
Why choose CQRS/ES for your architecture?
Here are my Top 5 reasons to consider CQRS/ES for your architecture
1. The number of reads, queries and views usually far exceeds the number of writes,
so a separation of these concerns can make development simpler and faster
2. Events are ubiquitous; every business process has them, so modelling systems on
events and storing past events has real business value
3. Often when choosing CRUD architecture, we under-estimate the complexity of
the logic required to manage the life-cycle of our business entities - this has
major impacts later, particularly on scalability
4. Event-based integration is far easier to manage and maintain than traditional
‘canonical model’ based integration techniques
5. Having independent data projections and views is really useful, particularly if you
have multiple disparate clients that require access to similar information - such as
mobile, web, public api’s etc.
8
Who uses CQRS & Event Sourcing?
The CQRS / ES approach to application architecture works well with Microservices, so it’s
popular with organisations that need cost effective scaling, organisations like...
9
An Industry Perspective on CQRS/ES
10
CQRS [Axon] - ASSESS
CQRS can work very well in specific places.
In those specific situations, however, a lot
of work is left to the developer to properly
execute CQRS.
Axon is a framework that can help with this
on the JVM, and we’ve used it with some
success.
Although it’s not perfect, it continues to
evolve and may make much more sense
than trying to write everything from
scratch.
My Axon Sample: https://goo.gl/uGGISx
Event Sourcing - TRIAL
Event Sourcing ensures that all changes to
application state are stored as a sequence of
events.
Complementary to the capture of
meaningful business events, the technique
has positive implications for analytics in
driving greater customer insight.
Not only can we query events, we can also
use the event log as history, and as a
foundation to automatically adjust the state
to cope with retroactive changes.
CQRS/ES is still considered a new and innovative approach to software design. Here’s what
ThoughtWorks said about CQRS and Event Sourcing in their 2015 Tech Radar...
Hungry for more?
Check out my Axon based CQRS/ES
Microservice sample code on GitHub:
https://goo.gl/uGGISx
For a conversation about how I could help your
team to achieve great things, contact me using
the social media links below:
11
Ben Wilcock
Freelance Software Architect [UK]
https://twitter.com/benbravo73
https://www.linkedin.com/in/benwilcock
http://benwilcock.wordpress.com

More Related Content

What's hot

What's hot (20)

Communication in a Microservice Architecture
Communication in a Microservice ArchitectureCommunication in a Microservice Architecture
Communication in a Microservice Architecture
 
Agile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven DesignAgile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven Design
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
Microservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaMicroservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and Kafka
 
CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event Sourcing
 
Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture
 
Event-driven microservices
Event-driven microservicesEvent-driven microservices
Event-driven microservices
 
Microservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, KanbanMicroservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, Kanban
 
Microservices Architecture & Testing Strategies
Microservices Architecture & Testing StrategiesMicroservices Architecture & Testing Strategies
Microservices Architecture & Testing Strategies
 
Building Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache KafkaBuilding Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache Kafka
 
[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들
[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들
[115]쿠팡 서비스 클라우드 마이그레이션 통해 배운것들
 
Microservices Architecture - Cloud Native Apps
Microservices Architecture - Cloud Native AppsMicroservices Architecture - Cloud Native Apps
Microservices Architecture - Cloud Native Apps
 
Managing multiple event types in a single topic with Schema Registry | Bill B...
Managing multiple event types in a single topic with Schema Registry | Bill B...Managing multiple event types in a single topic with Schema Registry | Bill B...
Managing multiple event types in a single topic with Schema Registry | Bill B...
 
Saturn 2018: Managing data consistency in a microservice architecture using S...
Saturn 2018: Managing data consistency in a microservice architecture using S...Saturn 2018: Managing data consistency in a microservice architecture using S...
Saturn 2018: Managing data consistency in a microservice architecture using S...
 
Microservice Architecture Patterns, by Richard Langlois P. Eng.
Microservice Architecture Patterns, by Richard Langlois P. Eng.Microservice Architecture Patterns, by Richard Langlois P. Eng.
Microservice Architecture Patterns, by Richard Langlois P. Eng.
 
Zuul @ Netflix SpringOne Platform
Zuul @ Netflix SpringOne PlatformZuul @ Netflix SpringOne Platform
Zuul @ Netflix SpringOne Platform
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)
 
Using patterns and pattern languages to make better architectural decisions
Using patterns and pattern languages to make better architectural decisions Using patterns and pattern languages to make better architectural decisions
Using patterns and pattern languages to make better architectural decisions
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
 

Viewers also liked

Recommender system algorithm and architecture
Recommender system algorithm and architectureRecommender system algorithm and architecture
Recommender system algorithm and architecture
Liang Xiang
 

Viewers also liked (9)

Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloud
 
Introduction to Kafka with Spring Integration
Introduction to Kafka with Spring IntegrationIntroduction to Kafka with Spring Integration
Introduction to Kafka with Spring Integration
 
Spring integration with the Java DSL
Spring integration with the Java DSLSpring integration with the Java DSL
Spring integration with the Java DSL
 
Introduction To Functional Reactive Programming Poznan
Introduction To Functional Reactive Programming PoznanIntroduction To Functional Reactive Programming Poznan
Introduction To Functional Reactive Programming Poznan
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Integration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices ArchitecturesIntegration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices Architectures
 
Scaling wix with microservices architecture devoxx London 2015
Scaling wix with microservices architecture devoxx London 2015Scaling wix with microservices architecture devoxx London 2015
Scaling wix with microservices architecture devoxx London 2015
 
Recommender system algorithm and architecture
Recommender system algorithm and architectureRecommender system algorithm and architecture
Recommender system algorithm and architecture
 

Similar to Microservice Architecture with CQRS and Event Sourcing

Dynamic Service Level Agreement Verification in Cloud Computing
Dynamic Service Level Agreement Verification in Cloud Computing Dynamic Service Level Agreement Verification in Cloud Computing
Dynamic Service Level Agreement Verification in Cloud Computing
IJCSIS Research Publications
 
Cloud MicroService Architecture
Cloud MicroService ArchitectureCloud MicroService Architecture
Cloud MicroService Architecture
Yakov Liskoff
 
Correlation Architecture
Correlation ArchitectureCorrelation Architecture
Correlation Architecture
sboray
 

Similar to Microservice Architecture with CQRS and Event Sourcing (20)

10 Key Digital Infrastructure Considerations
10 Key Digital Infrastructure Considerations10 Key Digital Infrastructure Considerations
10 Key Digital Infrastructure Considerations
 
SaaS Application Scalability: Best Practices from Architecture to Cloud Infra...
SaaS Application Scalability: Best Practices from Architecture to Cloud Infra...SaaS Application Scalability: Best Practices from Architecture to Cloud Infra...
SaaS Application Scalability: Best Practices from Architecture to Cloud Infra...
 
International Journal of Computer Science, Engineering and Information Techno...
International Journal of Computer Science, Engineering and Information Techno...International Journal of Computer Science, Engineering and Information Techno...
International Journal of Computer Science, Engineering and Information Techno...
 
CONFIGURATION INERPSAAS MULTI-TENANCY
CONFIGURATION INERPSAAS MULTI-TENANCYCONFIGURATION INERPSAAS MULTI-TENANCY
CONFIGURATION INERPSAAS MULTI-TENANCY
 
Configuration inerpsaas multi tenancy
Configuration inerpsaas multi tenancyConfiguration inerpsaas multi tenancy
Configuration inerpsaas multi tenancy
 
Modern webtechnologies
Modern webtechnologiesModern webtechnologies
Modern webtechnologies
 
An Overview of Windows Azure
An Overview of Windows AzureAn Overview of Windows Azure
An Overview of Windows Azure
 
NOS DevDays 2014 | CQRS+ES
NOS DevDays 2014 | CQRS+ESNOS DevDays 2014 | CQRS+ES
NOS DevDays 2014 | CQRS+ES
 
Dynamic Service Level Agreement Verification in Cloud Computing
Dynamic Service Level Agreement Verification in Cloud Computing Dynamic Service Level Agreement Verification in Cloud Computing
Dynamic Service Level Agreement Verification in Cloud Computing
 
Cisco Secure Enclaves Architecture
Cisco Secure Enclaves ArchitectureCisco Secure Enclaves Architecture
Cisco Secure Enclaves Architecture
 
Refactoring to Microservice Architecture
Refactoring to Microservice ArchitectureRefactoring to Microservice Architecture
Refactoring to Microservice Architecture
 
Microservices: A Step Towards Modernizing Healthcare Applications
Microservices: A Step Towards Modernizing Healthcare ApplicationsMicroservices: A Step Towards Modernizing Healthcare Applications
Microservices: A Step Towards Modernizing Healthcare Applications
 
Cloud Design Patterns - PRESCRIPTIVE ARCHITECTURE GUIDANCE FOR CLOUD APPLICAT...
Cloud Design Patterns - PRESCRIPTIVE ARCHITECTURE GUIDANCE FOR CLOUD APPLICAT...Cloud Design Patterns - PRESCRIPTIVE ARCHITECTURE GUIDANCE FOR CLOUD APPLICAT...
Cloud Design Patterns - PRESCRIPTIVE ARCHITECTURE GUIDANCE FOR CLOUD APPLICAT...
 
Cloud MicroService Architecture
Cloud MicroService ArchitectureCloud MicroService Architecture
Cloud MicroService Architecture
 
Governance in the age of cloud
Governance in the age of cloudGovernance in the age of cloud
Governance in the age of cloud
 
Correlation Architecture
Correlation ArchitectureCorrelation Architecture
Correlation Architecture
 
BUSINESS SILOS INTEGRATION USING SERVICE ORIENTED ARCHITECTURE
BUSINESS SILOS INTEGRATION USING SERVICE ORIENTED ARCHITECTUREBUSINESS SILOS INTEGRATION USING SERVICE ORIENTED ARCHITECTURE
BUSINESS SILOS INTEGRATION USING SERVICE ORIENTED ARCHITECTURE
 
WebApplicationArchitectureAzure.pptx
WebApplicationArchitectureAzure.pptxWebApplicationArchitectureAzure.pptx
WebApplicationArchitectureAzure.pptx
 
WebApplicationArchitectureAzure.pdf
WebApplicationArchitectureAzure.pdfWebApplicationArchitectureAzure.pdf
WebApplicationArchitectureAzure.pdf
 
Reimagine Application Modernization with Serverless Architecture
Reimagine Application Modernization with Serverless ArchitectureReimagine Application Modernization with Serverless Architecture
Reimagine Application Modernization with Serverless Architecture
 

Recently uploaded

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
 

Recently uploaded (20)

Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
 

Microservice Architecture with CQRS and Event Sourcing

  • 1. Microservice Architecture with CQRS & Event Sourcing Ben Wilcock Freelance Software Architect [UK] https://twitter.com/benbravo73 https://www.linkedin.com/in/benwilcock http://benwilcock.wordpress.com
  • 2. What is CQRS? 2 ‘Command & Query Responsibility Segregation’ CQRS is an architectural pattern for developing software whereby the bits of the system that are responsible for changing the system’s state (the ‘write-parts’) are physically separated from the bits of the system that manage views (the ‘read-parts’) This is in contrast to CRUD architecture where traditionally the same component has responsibility for both the reads (the views) and the writes (the state changes)
  • 3. What is Event Sourcing (ES)? 3 Event Sourcing uses a timeline to describe state When Event Sourcing, state is recorded as a complete series of the events resulting from the actions taken within the domain These persisted events can then be used to re-establish the state of the actors within the domain at any point in time This is in contrast to CRUD architecture where traditionally only the current state of an entity is stored (and not the history of events describing how it arrived at this current state) Event sourcing complements CQRS, but CQRS does not require event-sourcing in order to be successful
  • 4. What are the Principles behind CQRS/ES? Separation of Concerns (SoC) A design principle for separating a computer program into distinct sections, such that each section addresses a separate concern Do one thing and do it well A philosophy at the heart of UNIX development that leads to small and highly-cohesive applications Event-Driven Architecture Also known as Message-driven architecture, this is a software architecture pattern that promotes the production, detection, consumption and reaction to events over other forms of integration 4 Domain-Driven Design (DDD) A software development approach whereby the implementation is strongly linked to the business domain in which it’s used Loose-coupling An approach to interconnecting components such that those components depend on each other to the least extent practicable Event sourcing A mechanism for persisting application's state by storing the history of events or changes that caused the system to arrive at its current state
  • 5. What are the Benefits of CQRS? Scalability In mosts systems the number of reads vastly exceeds writes - yet the architecture rarely reflects this In CQRS the read-side is separate from the write-side, so each can be scaled and performance-optimised independently Simplicity In most systems a single model is used to manage, describe, store and view data This sounds simple, but it adds complexity as contradicting requirements (writing and reading) must be handled by a single model With CQRS the write-model and the read- model can be different Flexibility The clear separation of methods that change state from the methods that view state makes change simpler Change can be made with greater confidence and with more predictable effects Business Focus Commands are intuitive and instantly recognisable as business related actions In CQRS this business focus together with Domain Driven Design can result in applications that are more responsive to change and cheaper to maintain 5
  • 6. What are the Benefits of Event Sourcing? History has Business Value By storing events, you never discard information that may have future value Events allow you to see the state of the system at any point in the past You can use this insight to answer historical business questions as they arise Easy Integration Events are also a useful way of communicating with other systems Integration based on events offers very low levels of coupling as the event producers don’t need to know anything about the event consumers (and vice versa) Simplicity By saving only events, you are avoiding the complex business of persisting complex domain objects to a relational store - otherwise known as the “object-relational impedance mismatch” Performance Events are simple, standalone and immutable, so you can use faster append- only operations to store them Flexibility A sequence of events can be "projected" into any desired structural representation or "view" at any time 6
  • 7. What does CQRS/ES Architecture look like? Multiple views or ‘projections’ can be built to satisfy disparate client requirements & limitations Integrations are unlimited, event-based and loosely-coupled Interactions are modeled as simple ‘Commands’, ‘Events’ and ‘Queries’ Events are stored and then forwarded to the event exchange command-side (Rules and Behavior) query-side (Presentation and Facts) 7 Read-side can be scaled, optimised and secured independently of the Write- side Command processing results in Events being created
  • 8. Why choose CQRS/ES for your architecture? Here are my Top 5 reasons to consider CQRS/ES for your architecture 1. The number of reads, queries and views usually far exceeds the number of writes, so a separation of these concerns can make development simpler and faster 2. Events are ubiquitous; every business process has them, so modelling systems on events and storing past events has real business value 3. Often when choosing CRUD architecture, we under-estimate the complexity of the logic required to manage the life-cycle of our business entities - this has major impacts later, particularly on scalability 4. Event-based integration is far easier to manage and maintain than traditional ‘canonical model’ based integration techniques 5. Having independent data projections and views is really useful, particularly if you have multiple disparate clients that require access to similar information - such as mobile, web, public api’s etc. 8
  • 9. Who uses CQRS & Event Sourcing? The CQRS / ES approach to application architecture works well with Microservices, so it’s popular with organisations that need cost effective scaling, organisations like... 9
  • 10. An Industry Perspective on CQRS/ES 10 CQRS [Axon] - ASSESS CQRS can work very well in specific places. In those specific situations, however, a lot of work is left to the developer to properly execute CQRS. Axon is a framework that can help with this on the JVM, and we’ve used it with some success. Although it’s not perfect, it continues to evolve and may make much more sense than trying to write everything from scratch. My Axon Sample: https://goo.gl/uGGISx Event Sourcing - TRIAL Event Sourcing ensures that all changes to application state are stored as a sequence of events. Complementary to the capture of meaningful business events, the technique has positive implications for analytics in driving greater customer insight. Not only can we query events, we can also use the event log as history, and as a foundation to automatically adjust the state to cope with retroactive changes. CQRS/ES is still considered a new and innovative approach to software design. Here’s what ThoughtWorks said about CQRS and Event Sourcing in their 2015 Tech Radar...
  • 11. Hungry for more? Check out my Axon based CQRS/ES Microservice sample code on GitHub: https://goo.gl/uGGISx For a conversation about how I could help your team to achieve great things, contact me using the social media links below: 11 Ben Wilcock Freelance Software Architect [UK] https://twitter.com/benbravo73 https://www.linkedin.com/in/benwilcock http://benwilcock.wordpress.com