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

An introduction to AWS CloudFormation - Pop-up Loft Tel Aviv
An introduction to AWS CloudFormation - Pop-up Loft Tel AvivAn introduction to AWS CloudFormation - Pop-up Loft Tel Aviv
An introduction to AWS CloudFormation - Pop-up Loft Tel AvivAmazon Web Services
 
Event driven microservices with axon and spring boot-excitingly boring
Event driven microservices with axon and spring boot-excitingly boringEvent driven microservices with axon and spring boot-excitingly boring
Event driven microservices with axon and spring boot-excitingly boringAllard Buijze
 
Real World Event Sourcing and CQRS
Real World Event Sourcing and CQRSReal World Event Sourcing and CQRS
Real World Event Sourcing and CQRSMatthew Hawkins
 
Implementing Domain Events with Kafka
Implementing Domain Events with KafkaImplementing Domain Events with Kafka
Implementing Domain Events with KafkaAndrei Rugina
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootMikalai Alimenkou
 
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREMicroservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREAraf Karsh Hamid
 
Big Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb ShardingBig Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb ShardingAraf Karsh Hamid
 
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
 
Stream Processing with Apache Kafka and .NET
Stream Processing with Apache Kafka and .NETStream Processing with Apache Kafka and .NET
Stream Processing with Apache Kafka and .NETconfluent
 
Event-driven microservices
Event-driven microservicesEvent-driven microservices
Event-driven microservicesAndrew Schofield
 
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.Richard Langlois P. Eng.
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services ArchitectureAraf Karsh Hamid
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootKashif Ali Siddiqui
 
Infrastructure as Code in AWS using Cloudformation
Infrastructure as Code in AWS using CloudformationInfrastructure as Code in AWS using Cloudformation
Infrastructure as Code in AWS using CloudformationJohn Reilly Pospos
 
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
 
AWS Builders - Industry Edition: DevSecOps on AWS - 시작은 IAM 부터
AWS Builders - Industry Edition: DevSecOps on AWS - 시작은 IAM 부터AWS Builders - Industry Edition: DevSecOps on AWS - 시작은 IAM 부터
AWS Builders - Industry Edition: DevSecOps on AWS - 시작은 IAM 부터Amazon Web Services Korea
 

What's hot (20)

An introduction to AWS CloudFormation - Pop-up Loft Tel Aviv
An introduction to AWS CloudFormation - Pop-up Loft Tel AvivAn introduction to AWS CloudFormation - Pop-up Loft Tel Aviv
An introduction to AWS CloudFormation - Pop-up Loft Tel Aviv
 
Event driven microservices with axon and spring boot-excitingly boring
Event driven microservices with axon and spring boot-excitingly boringEvent driven microservices with axon and spring boot-excitingly boring
Event driven microservices with axon and spring boot-excitingly boring
 
Real World Event Sourcing and CQRS
Real World Event Sourcing and CQRSReal World Event Sourcing and CQRS
Real World Event Sourcing and CQRS
 
Implementing Domain Events with Kafka
Implementing Domain Events with KafkaImplementing Domain Events with Kafka
Implementing Domain Events with Kafka
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREMicroservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SRE
 
Big Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb ShardingBig Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb Sharding
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
 
Microservices with event source and CQRS
Microservices with event source and CQRSMicroservices with event source and CQRS
Microservices with event source and CQRS
 
Stream Processing with Apache Kafka and .NET
Stream Processing with Apache Kafka and .NETStream Processing with Apache Kafka and .NET
Stream Processing with Apache Kafka and .NET
 
Event-driven microservices
Event-driven microservicesEvent-driven microservices
Event-driven microservices
 
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.
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services Architecture
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring Boot
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
Microservices Decomposition Patterns
Microservices Decomposition PatternsMicroservices Decomposition Patterns
Microservices Decomposition Patterns
 
Infrastructure as Code in AWS using Cloudformation
Infrastructure as Code in AWS using CloudformationInfrastructure as Code in AWS using Cloudformation
Infrastructure as Code in AWS using Cloudformation
 
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...
 
AWS Builders - Industry Edition: DevSecOps on AWS - 시작은 IAM 부터
AWS Builders - Industry Edition: DevSecOps on AWS - 시작은 IAM 부터AWS Builders - Industry Edition: DevSecOps on AWS - 시작은 IAM 부터
AWS Builders - Industry Edition: DevSecOps on AWS - 시작은 IAM 부터
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 

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

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

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)