SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Microservices Design Patterns | Edureka
Microservices Design Patterns | EdurekaMicroservices Design Patterns | Edureka
Microservices Design Patterns | EdurekaEdureka!
 
An Overview of Designing Microservices Based Applications on AWS - March 2017...
An Overview of Designing Microservices Based Applications on AWS - March 2017...An Overview of Designing Microservices Based Applications on AWS - March 2017...
An Overview of Designing Microservices Based Applications on AWS - March 2017...Amazon Web Services
 
Building Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache KafkaBuilding Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache KafkaGuido Schmutz
 
Microservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaMicroservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaAraf Karsh Hamid
 
Building Event-Driven (Micro) Services with Apache Kafka
Building Event-Driven (Micro) Services with Apache KafkaBuilding Event-Driven (Micro) Services with Apache Kafka
Building Event-Driven (Micro) Services with Apache KafkaGuido Schmutz
 
Building Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache KafkaBuilding Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache KafkaGuido Schmutz
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOpsMatthew David
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDDennis Doomen
 
Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)WSO2
 
Modeling microservices using DDD
Modeling microservices using DDDModeling microservices using DDD
Modeling microservices using DDDMasashi Narumoto
 
A visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRSA visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRSLorenzo Nicora
 
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
 
Async API and Solace: Enabling the Event-Driven Future
Async API and Solace: Enabling the Event-Driven FutureAsync API and Solace: Enabling the Event-Driven Future
Async API and Solace: Enabling the Event-Driven FutureSolace
 
Async Messaging in CQRS: Part 1 - Masstransit + DDD Intro
Async Messaging in CQRS: Part 1 - Masstransit + DDD IntroAsync Messaging in CQRS: Part 1 - Masstransit + DDD Intro
Async Messaging in CQRS: Part 1 - Masstransit + DDD IntroGeorge Tourkas
 
CQRS and Event Sourcing in Action
CQRS and Event  Sourcing in ActionCQRS and Event  Sourcing in Action
CQRS and Event Sourcing in ActionKnoldus Inc.
 
Service Mesh - Observability
Service Mesh - ObservabilityService Mesh - Observability
Service Mesh - ObservabilityAraf Karsh Hamid
 
Dos and Don'ts of DevSecOps
Dos and Don'ts of DevSecOpsDos and Don'ts of DevSecOps
Dos and Don'ts of DevSecOpsPriyanka Aash
 

What's hot (20)

Microservices Design Patterns | Edureka
Microservices Design Patterns | EdurekaMicroservices Design Patterns | Edureka
Microservices Design Patterns | Edureka
 
An Overview of Designing Microservices Based Applications on AWS - March 2017...
An Overview of Designing Microservices Based Applications on AWS - March 2017...An Overview of Designing Microservices Based Applications on AWS - March 2017...
An Overview of Designing Microservices Based Applications on AWS - March 2017...
 
Azure dev ops
Azure dev opsAzure dev ops
Azure dev ops
 
Building Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache KafkaBuilding Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache Kafka
 
Microservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaMicroservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and Kafka
 
Event Storming and Saga
Event Storming and SagaEvent Storming and Saga
Event Storming and Saga
 
Building Event-Driven (Micro) Services with Apache Kafka
Building Event-Driven (Micro) Services with Apache KafkaBuilding Event-Driven (Micro) Services with Apache Kafka
Building Event-Driven (Micro) Services with Apache Kafka
 
Building Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache KafkaBuilding Event Driven (Micro)services with Apache Kafka
Building Event Driven (Micro)services with Apache Kafka
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDD
 
Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)
 
Modeling microservices using DDD
Modeling microservices using DDDModeling microservices using DDD
Modeling microservices using DDD
 
Devops insights
Devops insightsDevops insights
Devops insights
 
A visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRSA visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRS
 
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...
 
Async API and Solace: Enabling the Event-Driven Future
Async API and Solace: Enabling the Event-Driven FutureAsync API and Solace: Enabling the Event-Driven Future
Async API and Solace: Enabling the Event-Driven Future
 
Async Messaging in CQRS: Part 1 - Masstransit + DDD Intro
Async Messaging in CQRS: Part 1 - Masstransit + DDD IntroAsync Messaging in CQRS: Part 1 - Masstransit + DDD Intro
Async Messaging in CQRS: Part 1 - Masstransit + DDD Intro
 
CQRS and Event Sourcing in Action
CQRS and Event  Sourcing in ActionCQRS and Event  Sourcing in Action
CQRS and Event Sourcing in Action
 
Service Mesh - Observability
Service Mesh - ObservabilityService Mesh - Observability
Service Mesh - Observability
 
Dos and Don'ts of DevSecOps
Dos and Don'ts of DevSecOpsDos and Don'ts of DevSecOps
Dos and Don'ts of DevSecOps
 

Similar to CQRS 2.0 and Akka.NET for Building Reactive Apps

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
 

Similar to CQRS 2.0 and Akka.NET for Building Reactive Apps (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
 

More from 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
 

More from 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
 

Recently uploaded

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
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
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
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
 
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.
 
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
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
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
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
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
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
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
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 

Recently uploaded (20)

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
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
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
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...
 
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 ...
 
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
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
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
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
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
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
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
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 

CQRS 2.0 and Akka.NET for Building Reactive Apps

  • 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