SlideShare a Scribd company logo
1 of 30
AXON FRAMEWORK
EXPLORING CQRS AND EVENT
SOURCING ARCHITECTURE
1. CQRS (Command and Query Responsibility Segregation).
2. Event Sourcing.
3. Axon Framework
4. SAGA
POINTS COVERED
What is CQRS?
Command and Query Responsibility Segregation, it is a software building pattern
that works on separating the part of an application that changes the state of an
application and the part that queries the state of the application.
Simple concept, which is, have the “write” part of an application distinctly separate from
the “read’ part of an application.
Remember...
CQRS is not seen as an “Architecture” but a “Pattern”. This open ups the component
based approach.
Layered arch. vs Component
based approach
In layered architecture the components are
arranged in layers, and can make direct calls
to the layers below it. Whereas in component
based approach components are semi-
autonomous and collaborate with each other
using messaging system.
CQRS components
What is Event Sourcing?
1. Changes made to state are tracked as events.
2. Events are stored in event store(any database).
3. Use stored events and summation of all these events always arrive at the current
state.
Note : - Event Sourcing is not part of CQRS.
What is Axon Framework?
By name it says is a framework that helps developers implement Command and Query
Responsibility Segregation pattern to build a scalable and extensible application. It does
so by providing implementation to the building blocks of the framework like EventBus,
CommandBus, EventStore, aggregate, repositories etc...
Overview of some DDD concepts
Domain Objects : Objects that model domain. Hold the state of the application.
Entity : Domain objects with an identity.
Aggregate : A logical grouping of domain objects to form an atomic and cohesive whole.
Aggregate Root : A grouping object that has been designed to be a container object.
Axon Framework Architecture
Axon components
Command
Represents that something should happen within a system. In axon it's a plain
object that represents the intent with necessary information required.
1. Plain POJO object.
2. Doesn't need to implement any interface or extend any class.
3. Should be immutable.
continuing...
Command Handler
Component that performs a task based on the command that it receives. Usually
command handlers are plain methods with @CommandHandler annotation. Performs
operations based on the intent captured in command it receives.
Command Handler can be created via two ways
1. Implementing CommandHandler interface.
2. If using axon with spring, use @CommandHandler on a method to be turned into a
command handler.
continuing...
Command Bus
Component that routes the commands to their respective command handlers.
Command handlers subscribe themselves to the command bus with
CommandHandlerInvoker class.
When using axon with spring, axon auto configuration subscribes all
command handlers with the bus automatically. Four different types of command bus
are provided by the axon namely SimpleCommandBus, DistributedCommandBus,
AsynchronousCommandBus and DisruptorcommandBus.
continuing...
Command Gateway
It is possible to use command bus directly to send out commands, but it's
usually recommended to use command gateway. Command gateway provides simpler
APIs to send out commands than Command Bus.
Axon provides DefaultCommandGateway as an implementation for the
CommandGateway.
continuing...
Event
Represents that something has happened within the application. In axon it’s
plain object with data representing the state change. Raised as a result of command
process.
1. Plain POJO object.
2. Must implement Serializable interface.
3. Should be immutable.
continuing...
1. Event Message
Any message wrapped in an EventMessage object. EventMessage object
contains timestamp attribute.
1. Domain Event
Event objects that are originated from aggregate. Wrapped in
DomainEventMessage(which extends EventMessage) object. The DomainEventMessage
additionally contains type and identifier of the aggregate that has raised an event.
continuing...
Event Handler
Performs an action on receiving the event of type defined as the first
parameter of the method. The method is annotated with @EventHandler annotation
that represent that method as event handler.
If you are using axon with spring, then axon will automatically register these
handlers with the Event Bus.
continuing...
Event Bus
Similar to the Command Bus Event Bus is a component that routes the events
to the event handlers. EventHandlerInvoker class is responsible for invoking handler
methods.
Axon provides SimpleEventBus as an implementation for Event Bus.
Aggregate
Domain objects annotated with @Aggregate annotation. Aggregate Root is
annotated with @AggregateRoot annotation.
1. Regular Aggregate Root
Aggregates state is stored in the persistent medium.
1. Event Sourcing Aggregate Root
Events resulted from the aggregate are stored to the persistence medium.
Repository
Repository provides mechanism to store and retrieve aggregate to and from the
persistence medium.
1. Standard Repository
Stores regular aggregates. Axon provides JPA backed repository for this
purpose.
1. Event Sourcing Repository
Stores events raised from aggregates. Axon provides
GenericEventSourcingRepository for this purpose.
Event Store (READ-ONLY and APPEND-ONLY)
It is a type of Event Bus that stores the events in the persistence medium.
Repositories need event store to store and load events from aggregates.
Axon provides out-of-the-box, the EmbeddedEventStore. It delegates the
actual storage and retrieval of events to the EventStorageEngine.
EventStore stores uses DomainEventEntry and SnapshotEventEntry domains
to store events in the persistence medium. These domains have properties like
aggregate type, identifier, payload, payload type, sequence number etc.
EventStorageEngine
EventStorageEngine stores events in it’s compatible data source. Axon
provides different StorageEngine implementations for different storage mediums.
1. JPAEventStorageEngine.
2. MongoEventStorageEngine.
3. JDBCEventStorageEngine.
4. SequenceEventStorageEngine.
5. InMemoryEventStorageEngine.
Snapshotting
Re-creating current state of the Aggregate object from stored events is a time-
consuming process when your application is in production, as your application is
loaded with thousands of events. Here event snapshotting comes to the rescue.
A snapshot event is a domain event that summarizes an arbitrary amount of event
into one. By regularly creating and storing of snapshot event, the event store does not
have to load all the events to re-create the current state of an Aggregate.
Snapshot Trigger
Snapshotting can be triggered by a number of factors like a number of events
stored in since the last snapshot, time-based etc..
The definition of when snapshot should be triggered is provided by
SnapShotTriggerDefinition interface.
EventCountSnapShotTriggerDefinition triggers snapshotting when a number of
events required to load an aggregate exceed a certain threshold.
SAGA
BASE Transaction?
Basic Availability Soft State Eventual Consistency
Basically Available — The system must ensure the availability of data. There
will be an answer for every request.
Soft State — The state of the system could change over time, so even during times
without input there may be changes going on due to ‘eventual consistency,’ thus the
state of the system is always ‘soft.’
Eventually consistent— The system will eventually become consistent once it stops
receiving input. The data will propagate to everywhere it should sooner or later, but the
system will continue to receive input and is not checking the consistency of every
transaction before it moves onto the next one.
SAGA?
➢In CQRS, Sagas are responsible for managing these BASE transactions.
They respond on Events produced by Commands and may produce new
commands, invoke external applications, etc. In the context of Domain
Driven Design, it is not uncommon for Sagas to be used as coordination
mechanism between several bounded contexts.
➢Saga has a starting point and an end, both triggered by Events.
Continuing...
Contrary to ACID, BASE transactions cannot be easily rolled back. To roll back,
compensating actions need to be taken to revert anything that has occurred
as part of the transaction.
Example
Examples
Find examples on CQRS and Event Sourcing implementations using Axon framework on
github.
Banking App - https://github.com/meta-magic/cqrs-axon-
example/tree/master/Bankingapp
Issue Traking App - https://github.com/meta-magic/cqrs-axon-
example/tree/master/IssueTrackingApp
Order Process App - https://github.com/meta-magic/cqrs-axon-
example/tree/master/ecommapp
END

More Related Content

What's hot

Introducing Saga Pattern in Microservices with Spring Statemachine
Introducing Saga Pattern in Microservices with Spring StatemachineIntroducing Saga Pattern in Microservices with Spring Statemachine
Introducing Saga Pattern in Microservices with Spring StatemachineVMware Tanzu
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationSamuel ROZE
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQAraf Karsh Hamid
 
Kafka as an event store - is it good enough?
Kafka as an event store - is it good enough?Kafka as an event store - is it good enough?
Kafka as an event store - is it good enough?Guido Schmutz
 
CQRS and Event Sourcing
CQRS and Event Sourcing CQRS and Event Sourcing
CQRS and Event Sourcing Inho Kang
 
Microservices Testing Strategies JUnit Cucumber Mockito Pact
Microservices Testing Strategies JUnit Cucumber Mockito PactMicroservices Testing Strategies JUnit Cucumber Mockito Pact
Microservices Testing Strategies JUnit Cucumber Mockito PactAraf Karsh Hamid
 
Microservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingMicroservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingBen Wilcock
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...Chris Richardson
 
Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018Araf Karsh Hamid
 
Event-driven microservices
Event-driven microservicesEvent-driven microservices
Event-driven microservicesAndrew Schofield
 
Communication in a Microservice Architecture
Communication in a Microservice ArchitectureCommunication in a Microservice Architecture
Communication in a Microservice ArchitecturePer Bernhardt
 
OSMC 2022 | Ignite: Observability with Grafana & Prometheus for Kafka on Kube...
OSMC 2022 | Ignite: Observability with Grafana & Prometheus for Kafka on Kube...OSMC 2022 | Ignite: Observability with Grafana & Prometheus for Kafka on Kube...
OSMC 2022 | Ignite: Observability with Grafana & Prometheus for Kafka on Kube...NETWAYS
 
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...Chris Richardson
 
Going Serverless with CQRS on AWS
Going Serverless with CQRS on AWSGoing Serverless with CQRS on AWS
Going Serverless with CQRS on AWSAnton Udovychenko
 
Microservices with event source and CQRS
Microservices with event source and CQRSMicroservices with event source and CQRS
Microservices with event source and CQRSMd Ayub Ali Sarker
 
Design patterns for microservice architecture
Design patterns for microservice architectureDesign patterns for microservice architecture
Design patterns for microservice architectureThe Software House
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다Arawn Park
 

What's hot (20)

Introducing Saga Pattern in Microservices with Spring Statemachine
Introducing Saga Pattern in Microservices with Spring StatemachineIntroducing Saga Pattern in Microservices with Spring Statemachine
Introducing Saga Pattern in Microservices with Spring Statemachine
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQ
 
Kafka as an event store - is it good enough?
Kafka as an event store - is it good enough?Kafka as an event store - is it good enough?
Kafka as an event store - is it good enough?
 
CQRS and Event Sourcing
CQRS and Event Sourcing CQRS and Event Sourcing
CQRS and Event Sourcing
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Microservices Testing Strategies JUnit Cucumber Mockito Pact
Microservices Testing Strategies JUnit Cucumber Mockito PactMicroservices Testing Strategies JUnit Cucumber Mockito Pact
Microservices Testing Strategies JUnit Cucumber Mockito Pact
 
Microservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingMicroservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event Sourcing
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018
 
Event-driven microservices
Event-driven microservicesEvent-driven microservices
Event-driven microservices
 
Communication in a Microservice Architecture
Communication in a Microservice ArchitectureCommunication in a Microservice Architecture
Communication in a Microservice Architecture
 
OSMC 2022 | Ignite: Observability with Grafana & Prometheus for Kafka on Kube...
OSMC 2022 | Ignite: Observability with Grafana & Prometheus for Kafka on Kube...OSMC 2022 | Ignite: Observability with Grafana & Prometheus for Kafka on Kube...
OSMC 2022 | Ignite: Observability with Grafana & Prometheus for Kafka on Kube...
 
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
 
Going Serverless with CQRS on AWS
Going Serverless with CQRS on AWSGoing Serverless with CQRS on AWS
Going Serverless with CQRS on AWS
 
Microservices with event source and CQRS
Microservices with event source and CQRSMicroservices with event source and CQRS
Microservices with event source and CQRS
 
Design patterns for microservice architecture
Design patterns for microservice architectureDesign patterns for microservice architecture
Design patterns for microservice architecture
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
 

Similar to Axon Framework, Exploring CQRS and Event Sourcing Architecture

Our way to microservices
Our way to microservicesOur way to microservices
Our way to microservicesAndi Pangeran
 
Lagom - Persistent Entity
Lagom - Persistent EntityLagom - Persistent Entity
Lagom - Persistent EntityKnoldus Inc.
 
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...Codemotion
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1Hussain Behestee
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3DHIRAJ PRAVIN
 
Reactive programming with akka
Reactive programming with akkaReactive programming with akka
Reactive programming with akkaWebdesign Factory
 
Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.Nida Ismail Shah
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 FrameworkEmprovise
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelMichael Heron
 
Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016
Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016
Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016DevOpsDays Tel Aviv
 
WPF Windows Presentation Foundation A detailed overview Version1.2
WPF Windows Presentation Foundation A detailed overview Version1.2WPF Windows Presentation Foundation A detailed overview Version1.2
WPF Windows Presentation Foundation A detailed overview Version1.2Shahzad
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2javatrainingonline
 
Net framework session03
Net framework session03Net framework session03
Net framework session03Vivek chan
 
Evolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka MicroservicesEvolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka MicroservicesStefano Rocco
 

Similar to Axon Framework, Exploring CQRS and Event Sourcing Architecture (20)

Our way to microservices
Our way to microservicesOur way to microservices
Our way to microservices
 
Lagom - Persistent Entity
Lagom - Persistent EntityLagom - Persistent Entity
Lagom - Persistent Entity
 
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
Massimo Bonanni - Workflow as code with Azure Durable Functions - Codemotion ...
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Flux architecture
Flux architectureFlux architecture
Flux architecture
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3
 
Reactive programming with akka
Reactive programming with akkaReactive programming with akka
Reactive programming with akka
 
Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 Framework
 
SECh1214
SECh1214SECh1214
SECh1214
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
 
Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016
Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016
Event-driven Infrastructure - Mike Place, SaltStack - DevOpsDays Tel Aviv 2016
 
WPF Windows Presentation Foundation A detailed overview Version1.2
WPF Windows Presentation Foundation A detailed overview Version1.2WPF Windows Presentation Foundation A detailed overview Version1.2
WPF Windows Presentation Foundation A detailed overview Version1.2
 
Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
 
Event sourcing
Event sourcingEvent sourcing
Event sourcing
 
Net framework session03
Net framework session03Net framework session03
Net framework session03
 
Evolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka MicroservicesEvolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka Microservices
 
A4WSN
A4WSNA4WSN
A4WSN
 
TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6
 

Recently uploaded

WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 

Recently uploaded (20)

WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 

Axon Framework, Exploring CQRS and Event Sourcing Architecture

  • 1. AXON FRAMEWORK EXPLORING CQRS AND EVENT SOURCING ARCHITECTURE
  • 2. 1. CQRS (Command and Query Responsibility Segregation). 2. Event Sourcing. 3. Axon Framework 4. SAGA POINTS COVERED
  • 3. What is CQRS? Command and Query Responsibility Segregation, it is a software building pattern that works on separating the part of an application that changes the state of an application and the part that queries the state of the application. Simple concept, which is, have the “write” part of an application distinctly separate from the “read’ part of an application. Remember... CQRS is not seen as an “Architecture” but a “Pattern”. This open ups the component based approach.
  • 4. Layered arch. vs Component based approach In layered architecture the components are arranged in layers, and can make direct calls to the layers below it. Whereas in component based approach components are semi- autonomous and collaborate with each other using messaging system.
  • 6. What is Event Sourcing? 1. Changes made to state are tracked as events. 2. Events are stored in event store(any database). 3. Use stored events and summation of all these events always arrive at the current state. Note : - Event Sourcing is not part of CQRS.
  • 7. What is Axon Framework? By name it says is a framework that helps developers implement Command and Query Responsibility Segregation pattern to build a scalable and extensible application. It does so by providing implementation to the building blocks of the framework like EventBus, CommandBus, EventStore, aggregate, repositories etc...
  • 8. Overview of some DDD concepts Domain Objects : Objects that model domain. Hold the state of the application. Entity : Domain objects with an identity. Aggregate : A logical grouping of domain objects to form an atomic and cohesive whole. Aggregate Root : A grouping object that has been designed to be a container object.
  • 10. Axon components Command Represents that something should happen within a system. In axon it's a plain object that represents the intent with necessary information required. 1. Plain POJO object. 2. Doesn't need to implement any interface or extend any class. 3. Should be immutable.
  • 11. continuing... Command Handler Component that performs a task based on the command that it receives. Usually command handlers are plain methods with @CommandHandler annotation. Performs operations based on the intent captured in command it receives. Command Handler can be created via two ways 1. Implementing CommandHandler interface. 2. If using axon with spring, use @CommandHandler on a method to be turned into a command handler.
  • 12. continuing... Command Bus Component that routes the commands to their respective command handlers. Command handlers subscribe themselves to the command bus with CommandHandlerInvoker class. When using axon with spring, axon auto configuration subscribes all command handlers with the bus automatically. Four different types of command bus are provided by the axon namely SimpleCommandBus, DistributedCommandBus, AsynchronousCommandBus and DisruptorcommandBus.
  • 13. continuing... Command Gateway It is possible to use command bus directly to send out commands, but it's usually recommended to use command gateway. Command gateway provides simpler APIs to send out commands than Command Bus. Axon provides DefaultCommandGateway as an implementation for the CommandGateway.
  • 14. continuing... Event Represents that something has happened within the application. In axon it’s plain object with data representing the state change. Raised as a result of command process. 1. Plain POJO object. 2. Must implement Serializable interface. 3. Should be immutable.
  • 15. continuing... 1. Event Message Any message wrapped in an EventMessage object. EventMessage object contains timestamp attribute. 1. Domain Event Event objects that are originated from aggregate. Wrapped in DomainEventMessage(which extends EventMessage) object. The DomainEventMessage additionally contains type and identifier of the aggregate that has raised an event.
  • 16. continuing... Event Handler Performs an action on receiving the event of type defined as the first parameter of the method. The method is annotated with @EventHandler annotation that represent that method as event handler. If you are using axon with spring, then axon will automatically register these handlers with the Event Bus.
  • 17. continuing... Event Bus Similar to the Command Bus Event Bus is a component that routes the events to the event handlers. EventHandlerInvoker class is responsible for invoking handler methods. Axon provides SimpleEventBus as an implementation for Event Bus.
  • 18. Aggregate Domain objects annotated with @Aggregate annotation. Aggregate Root is annotated with @AggregateRoot annotation. 1. Regular Aggregate Root Aggregates state is stored in the persistent medium. 1. Event Sourcing Aggregate Root Events resulted from the aggregate are stored to the persistence medium.
  • 19. Repository Repository provides mechanism to store and retrieve aggregate to and from the persistence medium. 1. Standard Repository Stores regular aggregates. Axon provides JPA backed repository for this purpose. 1. Event Sourcing Repository Stores events raised from aggregates. Axon provides GenericEventSourcingRepository for this purpose.
  • 20. Event Store (READ-ONLY and APPEND-ONLY) It is a type of Event Bus that stores the events in the persistence medium. Repositories need event store to store and load events from aggregates. Axon provides out-of-the-box, the EmbeddedEventStore. It delegates the actual storage and retrieval of events to the EventStorageEngine. EventStore stores uses DomainEventEntry and SnapshotEventEntry domains to store events in the persistence medium. These domains have properties like aggregate type, identifier, payload, payload type, sequence number etc.
  • 21. EventStorageEngine EventStorageEngine stores events in it’s compatible data source. Axon provides different StorageEngine implementations for different storage mediums. 1. JPAEventStorageEngine. 2. MongoEventStorageEngine. 3. JDBCEventStorageEngine. 4. SequenceEventStorageEngine. 5. InMemoryEventStorageEngine.
  • 22. Snapshotting Re-creating current state of the Aggregate object from stored events is a time- consuming process when your application is in production, as your application is loaded with thousands of events. Here event snapshotting comes to the rescue. A snapshot event is a domain event that summarizes an arbitrary amount of event into one. By regularly creating and storing of snapshot event, the event store does not have to load all the events to re-create the current state of an Aggregate.
  • 23. Snapshot Trigger Snapshotting can be triggered by a number of factors like a number of events stored in since the last snapshot, time-based etc.. The definition of when snapshot should be triggered is provided by SnapShotTriggerDefinition interface. EventCountSnapShotTriggerDefinition triggers snapshotting when a number of events required to load an aggregate exceed a certain threshold.
  • 24. SAGA
  • 25. BASE Transaction? Basic Availability Soft State Eventual Consistency Basically Available — The system must ensure the availability of data. There will be an answer for every request. Soft State — The state of the system could change over time, so even during times without input there may be changes going on due to ‘eventual consistency,’ thus the state of the system is always ‘soft.’ Eventually consistent— The system will eventually become consistent once it stops receiving input. The data will propagate to everywhere it should sooner or later, but the system will continue to receive input and is not checking the consistency of every transaction before it moves onto the next one.
  • 26. SAGA? ➢In CQRS, Sagas are responsible for managing these BASE transactions. They respond on Events produced by Commands and may produce new commands, invoke external applications, etc. In the context of Domain Driven Design, it is not uncommon for Sagas to be used as coordination mechanism between several bounded contexts. ➢Saga has a starting point and an end, both triggered by Events.
  • 27. Continuing... Contrary to ACID, BASE transactions cannot be easily rolled back. To roll back, compensating actions need to be taken to revert anything that has occurred as part of the transaction.
  • 29. Examples Find examples on CQRS and Event Sourcing implementations using Axon framework on github. Banking App - https://github.com/meta-magic/cqrs-axon- example/tree/master/Bankingapp Issue Traking App - https://github.com/meta-magic/cqrs-axon- example/tree/master/IssueTrackingApp Order Process App - https://github.com/meta-magic/cqrs-axon- example/tree/master/ecommapp
  • 30. END

Editor's Notes

  1. The part that changes the state of the application(changes to the domain model)