SlideShare une entreprise Scribd logo
1  sur  57
CQRS 2.0 David Hoerster
ABOUT ME
5-Time .NET (Visual C#) MVP (April 2011)
Sr. Solutions Architect at Confluence
One of the organizers for Pittsburgh TechFest (http://pghtechfest.com)
Organizer of Pittsburgh Reactive Dev Group (http://meetup.com/reactive)
Past President of Pittsburgh .NET Users Group
Twitter - @DavidHoerster
Blog – http://blog.agileways.com
Email – david@agileways.com
GOALS
What are the principles behind CQRS
How can I apply them in my current development
How Akka(.NET) shares much in common wth CQRS
How CQRS + Akka(.NET) can help with building distributed, reactive
applications
PREFACE:
FIRST CONTACT
SOME CQRS BACKGROUND
CQRS BACKGROUND
Command Query Responsibility Segregation
 Coined by Greg Young
Heavily influenced by Domain Driven Design (DDD)
Evolution of Meyer’s CQS (Command Query Separation)
Separation of writes (command) and reads (query)
CQS is more at the unit level
CQRS is at a higher level  bounded context / service
WHAT IS CQRS?
Simply: separate paths for reads and writes
Communicate via messages
Commands and Events
 “CreateOrder” and “OrderCreated”
Reads are against a thin read model (preferably optimized)
CQRS VISUALIZED: BASIC
Client
Backend
Commands Queries
CQRS
VISUALIZED
Controller
Handler
Domain
Persistence
/ Read
Model
Read
Layer
Command
Side
Query
Side
CQRS EXTENDED
Can move from direct references to queued
Decouples handlers
Increased isolation of areas
Leads to single message causing several changes
 Raising of events and subscriptions to events
CQRS
VISUALIZED
Controller
Handler
Domain
Persistence
Read
Layer
Handler
Command/Event
Topics
Read Model
Command
Side
Query
Side
CQRS HANDLER
CQRS HANDLER
BENEFITS
Message Based
Segregation of Responsibilities – Separate Paths
Smaller, simpler classes
 Albeit more classes
Focused Approach to Domain
 Move away from anemic domain models
CQRS PRINCIPLES
Separate Paths for Command and Queries
Message-Based
Async Friendly
Thin read layer
Don’t fear lots of small classes
A CALL
Is CQRS Dead?
<rant>
"CQRS IS HARD"
Misunderstandings
 Has to be async
 Has to have queueing
 Need a separate read model
 Need to have Event Sourcing
Perceived as overly prescriptive, but little prescription
Confusing
 Command Handler vs. Event Handler vs. Domain
 Command vs. Event
HAS CQRS “FAILED”?
Focus on CQRS as architecture over
principles
Search for prescriptive guidance
 Infrastructure/Implementation debates
 Should domains have getters??
 “…there are times a getter can be pragmatic. The trick is
learning where to use them.” – Greg Young (DDD/CQRS
Group)
“This list has its heads up its own
[butts] about infrastructure. What
business problems are you working on?”
-- Greg Young (DDD/CQRS Group)
</rant>
POPULAR ARCHITECTURE TOPICS
Microservices
Event driven
Distributed computing
NoSQL
Async
BUT ISN’T CQRS…?
Message Driven
Responsive Read Model
Isolated Handlers
Async Friendly
Group Handlers into Clusterable Groups
NoSQL Friendly (Flattened Read Models)
CQRS CAN HELP DRIVE REACTIVE
APPS
CQRS EVOLVED
CQRS & THE REACTIVE MANIFESTO
Message Based
 Core of CQRS
Responsive
 Commands are ack/nack
 Queries are (can be) against an optimized read model
Resillient
 Not core to CQRS  Implementation
Elastic
 Not core to CQRS  Implementation
SIDE NOTE: REACTIVE VS.
PROACTIVE
Isn’t proactive a good thing?
A system taking upon itself to
check state is proactive
 It’s doing too much
A reactive system reacts to
events that occur
 It’s doing just the right amount
SIDE NOTE: REACTIVE VS.
PROACTIVE
Isn’t proactive a good thing?
A system taking upon itself to
check state is proactive
 It’s doing too much
A reactive system reacts to
events that occur
 It’s doing just the right amount
System
EvtEvt
System
EvtEvt
Proactive
Reactive
CQRS + REACTIVE
Resillient and Elastic core to
Reactive
CQRS’ core is Message-Based
and Responsive
Combining the two is powerful
ACTOR MODEL
CQRS lacks prescriptive guidance
Actor Model provides a message-based pattern
Provides prescriptive guidance
Makes for more generalized implementation
Actor Model is driving more reactive-based development
ACTOR MODEL
Actor Model is a system made of small units of concurrent
computation
 Formulated in the early 70’s
Each unit is an actor
Communicates to each other via messages
Actors can have children, which they can supervise
WHAT IS AN ACTOR?
Lightweight class that encapsulates state and behavior
 State can be persisted (Akka.Persistence)
 Behavior can be switched (Become/Unbecome)
Has a mailbox to receive messages
 Ordered delivery by default
 Queue
Can create child actors
Has a supervisory strategy for child actors
 How to handle misbehaving children
Are always thread safe
Have a lifecycle
 Started, stopped, restarted
ACTOR HIERARCHY
baseball
gameCoo
rdinator
gameInfo
-x
gameInfo
-y
playerSup
ervisor
batter-abatter-bbatter-c
c-01 c-11 c-32
AKKA: RESILIENCY
Actors supervise their children
When they misbehave, they are notified
Can punish (fail) all children, or tell the misbehaving on to try again
Protects rest of the system
AKKA.NET
Akka.NET is an open source framework
Actor Model for .NET
Port of Akka (for JVM/Scala)
http://getakka.net
NuGet – searching for “akka.net”, shows up low in the list
STARTING WITH AKKA.NET
Akka.NET is a hierarchical system
Root of the system is ActorSystem
Expensive to instantiate – create and hold!
ActorSystem can then be used to create Actors
CREATING AN ACTOR
An Actor has a unique address
Can be accessed/communicated to like a URI
Call ActorOf off ActorSystem, provide it a name
 URI (actor path) is created hierarchically
Actor Path = akka://myName/user/announcer
SENDING A MESSAGE
Messages are basis of actor communication
 Should be IMMUTABLE!!!
“Tell” an actor a message
Async call
 Immutable!!
RECEIVING A MESSAGE
Create your Actor
Derive from ReceiveActor
In constructor, register your
message subscriptions
Looks similar to a CQRS
Handler
RECEIVING A MESSAGE
Each actor has a mailbox
Messages are received in the actor’s mailbox (queue)
Actor is notified that there’s a message
 It receives the message
 Takes it out of the mailbox
 Next one is queued up
Ordered delivery by default
 Other mailboxes (like Priority) that are out-of-order
Actor
Mailbox
Msg
DEMO: HELLO AKKA.NET
ELEMENTS OF CQRS IN ACTOR
MODEL
Message-based
Potentially async
Focused code
Actor System is your Command Side
CQRS + ACTORS
Combining the principles of CQRS and the patterns of the Actor
Model
Message-based communication with concurrent processing
CQRS + ACTORS: MESSAGES
Messages in an Actor System include both Commands and Events
Still encapsulate intent
Still should still contain information necessary to process/handle
command or event
Basically, no big change here
CQRS + ACTORS: MESSAGES
CQRS + ACTORS: HANDLERS
Handlers begin to encapsulate your
Actor System
Generally a single Actor System per
handler
Have several actors at top level of
hierarchy to handle initial messages
Domain can be injected into the
Actor System via Create()
Handler
Client
Queue
Persistence
Other Handler
Direct call or via
queue
CQRS + ACTORS: HANDLERS
CQRS + ACTORS: HANDLERS
CQRS + ACTORS: HANDLERS
Handlers act as the entry point
 Web API
 Service subscribed to queue
CQRS  IHandle<T> for those messages “exposed”
Actor System is called by the CQRS Handler
Actor System has many other “internal” actors
CQRS + ACTORS: SERVICES
Word Counter Handler
super
Count Write Stats
A B G H Y Z
DEMO: HELLO CQRS +
AKKA.NET
Word Counter
Handler
CQRS + ACTORS: SERVICES
super
Count
A B
Word Writer
Handler
super
Write
G H
Word Stats
Handler
super
Stats
Y Z
Message Bus
CQRS + ACTORS + SERVICES
Service A Service B Service C
Message Bus
DW / DL /
Read Model
Cmds / Events Cmds / Events
API Gateway SvcCommands Queries
RM RMRM
Queries (?)
Service A
Service A
Service A
CQRS + ACTORS + SERVICES +
CLUSTER (AKKA.CLUSTER)
Service A Service B Service C
Message Bus
DW / DL /
Read Model
Cmds / Events Cmds / Events
API Gateway SvcCommands Queries
RM RMRM
Queries (?)
CQRS + ACTORS + SERVICES
Actors act as the workers for your handlers
Services encapsulate handler into a bounded context
CQRS is the messaging and communication pattern within system
Using these three helps build killer reactive applications
CONCLUSIONS
CQRS is not dead
Key principles of messaging, separate paths and responsibility
segregation
Apply CQRS to Reactive systems (e.g. an Akka.NET system) for best of
both
Encapsulate handlers into services for scalability and reliability

Contenu connexe

Tendances

Resilient Real-time Data Streaming across the Edge and Hybrid Cloud with Apac...
Resilient Real-time Data Streaming across the Edge and Hybrid Cloud with Apac...Resilient Real-time Data Streaming across the Edge and Hybrid Cloud with Apac...
Resilient Real-time Data Streaming across the Edge and Hybrid Cloud with Apac...Kai Wähner
 
Using Kafka: Anatomy of the Flowable event registry
Using Kafka: Anatomy of the Flowable event registryUsing Kafka: Anatomy of the Flowable event registry
Using Kafka: Anatomy of the Flowable event registryFlowable
 
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
 
Azure Service Bus
Azure Service BusAzure Service Bus
Azure Service BusBizTalk360
 
Reactive Programming for Real Use Cases
Reactive Programming for Real Use CasesReactive Programming for Real Use Cases
Reactive Programming for Real Use CasesAlex Soto
 
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Scrum Breakfast Vietnam
 
Azure DNS Private Resolver - Azure Example Scenarios _ Microsoft Learn.pdf
Azure DNS Private Resolver - Azure Example Scenarios _ Microsoft Learn.pdfAzure DNS Private Resolver - Azure Example Scenarios _ Microsoft Learn.pdf
Azure DNS Private Resolver - Azure Example Scenarios _ Microsoft Learn.pdfKenneth Nnadikwe
 
Integration Microservices
Integration MicroservicesIntegration Microservices
Integration MicroservicesKasun Indrasiri
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformVMware Tanzu
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud VMware Tanzu
 
Kafka and Machine Learning in Banking and Insurance Industry
Kafka and Machine Learning in Banking and Insurance IndustryKafka and Machine Learning in Banking and Insurance Industry
Kafka and Machine Learning in Banking and Insurance IndustryKai Wähner
 
Kafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
Kafka Streams vs. KSQL for Stream Processing on top of Apache KafkaKafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
Kafka Streams vs. KSQL for Stream Processing on top of Apache KafkaKai Wähner
 
Open core summit: Observability for data pipelines with OpenLineage
Open core summit: Observability for data pipelines with OpenLineageOpen core summit: Observability for data pipelines with OpenLineage
Open core summit: Observability for data pipelines with OpenLineageJulien Le Dem
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services ArchitectureAraf Karsh Hamid
 
Introduction to Microservices Patterns
Introduction to Microservices PatternsIntroduction to Microservices Patterns
Introduction to Microservices PatternsDimosthenis Botsaris
 
Data In Motion Paris 2023
Data In Motion Paris 2023Data In Motion Paris 2023
Data In Motion Paris 2023confluent
 
Introduction to the Microsoft Azure Cloud.pptx
Introduction to the Microsoft Azure Cloud.pptxIntroduction to the Microsoft Azure Cloud.pptx
Introduction to the Microsoft Azure Cloud.pptxEverestMedinilla2
 

Tendances (20)

Resilient Real-time Data Streaming across the Edge and Hybrid Cloud with Apac...
Resilient Real-time Data Streaming across the Edge and Hybrid Cloud with Apac...Resilient Real-time Data Streaming across the Edge and Hybrid Cloud with Apac...
Resilient Real-time Data Streaming across the Edge and Hybrid Cloud with Apac...
 
Azure: PaaS or IaaS
Azure: PaaS or IaaSAzure: PaaS or IaaS
Azure: PaaS or IaaS
 
Using Kafka: Anatomy of the Flowable event registry
Using Kafka: Anatomy of the Flowable event registryUsing Kafka: Anatomy of the Flowable event registry
Using Kafka: Anatomy of the Flowable event registry
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQ
 
Azure Service Bus
Azure Service BusAzure Service Bus
Azure Service Bus
 
Reactive Programming for Real Use Cases
Reactive Programming for Real Use CasesReactive Programming for Real Use Cases
Reactive Programming for Real Use Cases
 
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
 
Azure DNS Private Resolver - Azure Example Scenarios _ Microsoft Learn.pdf
Azure DNS Private Resolver - Azure Example Scenarios _ Microsoft Learn.pdfAzure DNS Private Resolver - Azure Example Scenarios _ Microsoft Learn.pdf
Azure DNS Private Resolver - Azure Example Scenarios _ Microsoft Learn.pdf
 
Integration Microservices
Integration MicroservicesIntegration Microservices
Integration Microservices
 
Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalR
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise Platform
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud
 
Kafka and Machine Learning in Banking and Insurance Industry
Kafka and Machine Learning in Banking and Insurance IndustryKafka and Machine Learning in Banking and Insurance Industry
Kafka and Machine Learning in Banking and Insurance Industry
 
Kafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
Kafka Streams vs. KSQL for Stream Processing on top of Apache KafkaKafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
Kafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
 
Open core summit: Observability for data pipelines with OpenLineage
Open core summit: Observability for data pipelines with OpenLineageOpen core summit: Observability for data pipelines with OpenLineage
Open core summit: Observability for data pipelines with OpenLineage
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services Architecture
 
Introduction to Microservices Patterns
Introduction to Microservices PatternsIntroduction to Microservices Patterns
Introduction to Microservices Patterns
 
Microsoft Azure
Microsoft AzureMicrosoft Azure
Microsoft Azure
 
Data In Motion Paris 2023
Data In Motion Paris 2023Data In Motion Paris 2023
Data In Motion Paris 2023
 
Introduction to the Microsoft Azure Cloud.pptx
Introduction to the Microsoft Azure Cloud.pptxIntroduction to the Microsoft Azure Cloud.pptx
Introduction to the Microsoft Azure Cloud.pptx
 

Similaire à CQRS Evolved - CQRS + Akka.NET

Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And DesignYaroslav Tkachenko
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
 
Developing Actors in Azure with .net
Developing Actors in Azure with .netDeveloping Actors in Azure with .net
Developing Actors in Azure with .netMarco Parenzan
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
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
 
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...Codemotion
 
Beyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingBeyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingFabio Tiriticco
 
Linux Assignment 3
Linux Assignment 3Linux Assignment 3
Linux Assignment 3Diane Allen
 
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...sparkfabrik
 
DevOps and the Future of Enterprise Security
DevOps and the Future of Enterprise SecurityDevOps and the Future of Enterprise Security
DevOps and the Future of Enterprise SecurityPriyanka Aash
 
Life & Work of Butler Lampson | Turing100@Persistent
Life & Work of Butler Lampson | Turing100@PersistentLife & Work of Butler Lampson | Turing100@Persistent
Life & Work of Butler Lampson | Turing100@PersistentPersistent Systems Ltd.
 
CQRS & Queue unlimited
CQRS & Queue unlimitedCQRS & Queue unlimited
CQRS & Queue unlimitedTim Mahy
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arpGary Pedretti
 
Kubernetes in 15 minutes
Kubernetes in 15 minutesKubernetes in 15 minutes
Kubernetes in 15 minutesrhirschfeld
 
Creating scalable message driven solutions akkadotnet
Creating scalable message driven solutions akkadotnetCreating scalable message driven solutions akkadotnet
Creating scalable message driven solutions akkadotnetDavid Hoerster
 
Lessons learned from writing over 300,000 lines of infrastructure code
Lessons learned from writing over 300,000 lines of infrastructure codeLessons learned from writing over 300,000 lines of infrastructure code
Lessons learned from writing over 300,000 lines of infrastructure codeYevgeniy Brikman
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 

Similaire à CQRS Evolved - CQRS + Akka.NET (20)

Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 
Akka.Net & .Net Core - .Net Inside 4° MeetUp
Akka.Net & .Net Core - .Net Inside 4° MeetUpAkka.Net & .Net Core - .Net Inside 4° MeetUp
Akka.Net & .Net Core - .Net Inside 4° MeetUp
 
Devoxx
DevoxxDevoxx
Devoxx
 
Developing Actors in Azure with .net
Developing Actors in Azure with .netDeveloping Actors in Azure with .net
Developing Actors in Azure with .net
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
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
 
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
 
Beyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingBeyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor Programming
 
Linux Assignment 3
Linux Assignment 3Linux Assignment 3
Linux Assignment 3
 
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
 
DevOps and the Future of Enterprise Security
DevOps and the Future of Enterprise SecurityDevOps and the Future of Enterprise Security
DevOps and the Future of Enterprise Security
 
Life & Work of Butler Lampson | Turing100@Persistent
Life & Work of Butler Lampson | Turing100@PersistentLife & Work of Butler Lampson | Turing100@Persistent
Life & Work of Butler Lampson | Turing100@Persistent
 
CQRS & Queue unlimited
CQRS & Queue unlimitedCQRS & Queue unlimited
CQRS & Queue unlimited
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
 
Kubernetes in 15 minutes
Kubernetes in 15 minutesKubernetes in 15 minutes
Kubernetes in 15 minutes
 
Akka (1)
Akka (1)Akka (1)
Akka (1)
 
Creating scalable message driven solutions akkadotnet
Creating scalable message driven solutions akkadotnetCreating scalable message driven solutions akkadotnet
Creating scalable message driven solutions akkadotnet
 
Lessons learned from writing over 300,000 lines of infrastructure code
Lessons learned from writing over 300,000 lines of infrastructure codeLessons learned from writing over 300,000 lines of infrastructure code
Lessons learned from writing over 300,000 lines of infrastructure code
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 

Plus de David Hoerster

Elm - Could this be the Future of Web Dev?
Elm - Could this be the Future of Web Dev?Elm - Could this be the Future of Web Dev?
Elm - Could this be the Future of Web Dev?David Hoerster
 
Reactive Development: Commands, Actors and Events. Oh My!!
Reactive Development: Commands, Actors and Events.  Oh My!!Reactive Development: Commands, Actors and Events.  Oh My!!
Reactive Development: Commands, Actors and Events. Oh My!!David Hoerster
 
Being RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceBeing RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceDavid Hoerster
 
Freeing Yourself from an RDBMS Architecture
Freeing Yourself from an RDBMS ArchitectureFreeing Yourself from an RDBMS Architecture
Freeing Yourself from an RDBMS ArchitectureDavid Hoerster
 
A Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed ApplicationA Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed ApplicationDavid Hoerster
 
Greenfield Development with CQRS and Windows Azure
Greenfield Development with CQRS and Windows AzureGreenfield Development with CQRS and Windows Azure
Greenfield Development with CQRS and Windows AzureDavid Hoerster
 
Greenfield Development with CQRS
Greenfield Development with CQRSGreenfield Development with CQRS
Greenfield Development with CQRSDavid Hoerster
 
jQuery and OData - Perfect Together
jQuery and OData - Perfect TogetherjQuery and OData - Perfect Together
jQuery and OData - Perfect TogetherDavid Hoerster
 

Plus de David Hoerster (9)

Elm - Could this be the Future of Web Dev?
Elm - Could this be the Future of Web Dev?Elm - Could this be the Future of Web Dev?
Elm - Could this be the Future of Web Dev?
 
Reactive Development: Commands, Actors and Events. Oh My!!
Reactive Development: Commands, Actors and Events.  Oh My!!Reactive Development: Commands, Actors and Events.  Oh My!!
Reactive Development: Commands, Actors and Events. Oh My!!
 
Being RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceBeing RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data Persistence
 
Mongo Baseball .NET
Mongo Baseball .NETMongo Baseball .NET
Mongo Baseball .NET
 
Freeing Yourself from an RDBMS Architecture
Freeing Yourself from an RDBMS ArchitectureFreeing Yourself from an RDBMS Architecture
Freeing Yourself from an RDBMS Architecture
 
A Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed ApplicationA Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed Application
 
Greenfield Development with CQRS and Windows Azure
Greenfield Development with CQRS and Windows AzureGreenfield Development with CQRS and Windows Azure
Greenfield Development with CQRS and Windows Azure
 
Greenfield Development with CQRS
Greenfield Development with CQRSGreenfield Development with CQRS
Greenfield Development with CQRS
 
jQuery and OData - Perfect Together
jQuery and OData - Perfect TogetherjQuery and OData - Perfect Together
jQuery and OData - Perfect Together
 

Dernier

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%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
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%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
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
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
 
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
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
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
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
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
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 

Dernier (20)

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%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
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%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
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
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
 
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
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
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...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
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?
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

CQRS Evolved - CQRS + Akka.NET

  • 1. CQRS 2.0 David Hoerster
  • 2. ABOUT ME 5-Time .NET (Visual C#) MVP (April 2011) Sr. Solutions Architect at Confluence One of the organizers for Pittsburgh TechFest (http://pghtechfest.com) Organizer of Pittsburgh Reactive Dev Group (http://meetup.com/reactive) Past President of Pittsburgh .NET Users Group Twitter - @DavidHoerster Blog – http://blog.agileways.com Email – david@agileways.com
  • 3. GOALS What are the principles behind CQRS How can I apply them in my current development How Akka(.NET) shares much in common wth CQRS How CQRS + Akka(.NET) can help with building distributed, reactive applications
  • 5.
  • 7. CQRS BACKGROUND Command Query Responsibility Segregation  Coined by Greg Young Heavily influenced by Domain Driven Design (DDD) Evolution of Meyer’s CQS (Command Query Separation) Separation of writes (command) and reads (query) CQS is more at the unit level CQRS is at a higher level  bounded context / service
  • 8. WHAT IS CQRS? Simply: separate paths for reads and writes Communicate via messages Commands and Events  “CreateOrder” and “OrderCreated” Reads are against a thin read model (preferably optimized)
  • 11. CQRS EXTENDED Can move from direct references to queued Decouples handlers Increased isolation of areas Leads to single message causing several changes  Raising of events and subscriptions to events
  • 15. BENEFITS Message Based Segregation of Responsibilities – Separate Paths Smaller, simpler classes  Albeit more classes Focused Approach to Domain  Move away from anemic domain models
  • 16. CQRS PRINCIPLES Separate Paths for Command and Queries Message-Based Async Friendly Thin read layer Don’t fear lots of small classes
  • 20. "CQRS IS HARD" Misunderstandings  Has to be async  Has to have queueing  Need a separate read model  Need to have Event Sourcing Perceived as overly prescriptive, but little prescription Confusing  Command Handler vs. Event Handler vs. Domain  Command vs. Event
  • 21. HAS CQRS “FAILED”? Focus on CQRS as architecture over principles Search for prescriptive guidance  Infrastructure/Implementation debates  Should domains have getters??  “…there are times a getter can be pragmatic. The trick is learning where to use them.” – Greg Young (DDD/CQRS Group) “This list has its heads up its own [butts] about infrastructure. What business problems are you working on?” -- Greg Young (DDD/CQRS Group)
  • 23. POPULAR ARCHITECTURE TOPICS Microservices Event driven Distributed computing NoSQL Async
  • 24. BUT ISN’T CQRS…? Message Driven Responsive Read Model Isolated Handlers Async Friendly Group Handlers into Clusterable Groups NoSQL Friendly (Flattened Read Models)
  • 25. CQRS CAN HELP DRIVE REACTIVE APPS
  • 27. CQRS & THE REACTIVE MANIFESTO Message Based  Core of CQRS Responsive  Commands are ack/nack  Queries are (can be) against an optimized read model Resillient  Not core to CQRS  Implementation Elastic  Not core to CQRS  Implementation
  • 28. SIDE NOTE: REACTIVE VS. PROACTIVE Isn’t proactive a good thing? A system taking upon itself to check state is proactive  It’s doing too much A reactive system reacts to events that occur  It’s doing just the right amount
  • 29. SIDE NOTE: REACTIVE VS. PROACTIVE Isn’t proactive a good thing? A system taking upon itself to check state is proactive  It’s doing too much A reactive system reacts to events that occur  It’s doing just the right amount System EvtEvt System EvtEvt Proactive Reactive
  • 30. CQRS + REACTIVE Resillient and Elastic core to Reactive CQRS’ core is Message-Based and Responsive Combining the two is powerful
  • 31. ACTOR MODEL CQRS lacks prescriptive guidance Actor Model provides a message-based pattern Provides prescriptive guidance Makes for more generalized implementation Actor Model is driving more reactive-based development
  • 32. ACTOR MODEL Actor Model is a system made of small units of concurrent computation  Formulated in the early 70’s Each unit is an actor Communicates to each other via messages Actors can have children, which they can supervise
  • 33. WHAT IS AN ACTOR? Lightweight class that encapsulates state and behavior  State can be persisted (Akka.Persistence)  Behavior can be switched (Become/Unbecome) Has a mailbox to receive messages  Ordered delivery by default  Queue Can create child actors Has a supervisory strategy for child actors  How to handle misbehaving children Are always thread safe Have a lifecycle  Started, stopped, restarted
  • 35. AKKA: RESILIENCY Actors supervise their children When they misbehave, they are notified Can punish (fail) all children, or tell the misbehaving on to try again Protects rest of the system
  • 36. AKKA.NET Akka.NET is an open source framework Actor Model for .NET Port of Akka (for JVM/Scala) http://getakka.net NuGet – searching for “akka.net”, shows up low in the list
  • 37. STARTING WITH AKKA.NET Akka.NET is a hierarchical system Root of the system is ActorSystem Expensive to instantiate – create and hold! ActorSystem can then be used to create Actors
  • 38. CREATING AN ACTOR An Actor has a unique address Can be accessed/communicated to like a URI Call ActorOf off ActorSystem, provide it a name  URI (actor path) is created hierarchically Actor Path = akka://myName/user/announcer
  • 39. SENDING A MESSAGE Messages are basis of actor communication  Should be IMMUTABLE!!! “Tell” an actor a message Async call  Immutable!!
  • 40. RECEIVING A MESSAGE Create your Actor Derive from ReceiveActor In constructor, register your message subscriptions Looks similar to a CQRS Handler
  • 41. RECEIVING A MESSAGE Each actor has a mailbox Messages are received in the actor’s mailbox (queue) Actor is notified that there’s a message  It receives the message  Takes it out of the mailbox  Next one is queued up Ordered delivery by default  Other mailboxes (like Priority) that are out-of-order Actor Mailbox Msg
  • 43. ELEMENTS OF CQRS IN ACTOR MODEL Message-based Potentially async Focused code Actor System is your Command Side
  • 44. CQRS + ACTORS Combining the principles of CQRS and the patterns of the Actor Model Message-based communication with concurrent processing
  • 45. CQRS + ACTORS: MESSAGES Messages in an Actor System include both Commands and Events Still encapsulate intent Still should still contain information necessary to process/handle command or event Basically, no big change here
  • 46. CQRS + ACTORS: MESSAGES
  • 47. CQRS + ACTORS: HANDLERS Handlers begin to encapsulate your Actor System Generally a single Actor System per handler Have several actors at top level of hierarchy to handle initial messages Domain can be injected into the Actor System via Create() Handler Client Queue Persistence Other Handler Direct call or via queue
  • 48. CQRS + ACTORS: HANDLERS
  • 49. CQRS + ACTORS: HANDLERS
  • 50. CQRS + ACTORS: HANDLERS Handlers act as the entry point  Web API  Service subscribed to queue CQRS  IHandle<T> for those messages “exposed” Actor System is called by the CQRS Handler Actor System has many other “internal” actors
  • 51. CQRS + ACTORS: SERVICES Word Counter Handler super Count Write Stats A B G H Y Z
  • 52. DEMO: HELLO CQRS + AKKA.NET
  • 53. Word Counter Handler CQRS + ACTORS: SERVICES super Count A B Word Writer Handler super Write G H Word Stats Handler super Stats Y Z Message Bus
  • 54. CQRS + ACTORS + SERVICES Service A Service B Service C Message Bus DW / DL / Read Model Cmds / Events Cmds / Events API Gateway SvcCommands Queries RM RMRM Queries (?)
  • 55. Service A Service A Service A CQRS + ACTORS + SERVICES + CLUSTER (AKKA.CLUSTER) Service A Service B Service C Message Bus DW / DL / Read Model Cmds / Events Cmds / Events API Gateway SvcCommands Queries RM RMRM Queries (?)
  • 56. CQRS + ACTORS + SERVICES Actors act as the workers for your handlers Services encapsulate handler into a bounded context CQRS is the messaging and communication pattern within system Using these three helps build killer reactive applications
  • 57. CONCLUSIONS CQRS is not dead Key principles of messaging, separate paths and responsibility segregation Apply CQRS to Reactive systems (e.g. an Akka.NET system) for best of both Encapsulate handlers into services for scalability and reliability