SlideShare a Scribd company logo
1 of 20
Download to read offline
Event Sourcing and beyond
with Akka.NET Persistence
Konrad Dusza
Head of Engineering @ Bilander Group
Event sourcing and beyond with Akka.NET PersistenceVoltcode
Agenda
● Recap of the actor model and Akka.NET
● Persistence module - capabilities and use cases
● Akka.NET Persistence sample
● Additional Akka.NET Persistence features
Event sourcing and beyond with Akka.NET PersistenceVoltcode
Actors communicate by exchanging messages
asynchronously
Actors have internal state that is invisible from the
outside, no shared mutable state
Actors can decide to change their state upon
reception of a message - behavior specification
Each actor processes immutable messages
sequentially - one message at a time*
Actor model - “concurrent object-oriented programming”
Actor
State
Behavior
Messages
Event sourcing and beyond with Akka.NET PersistenceVoltcode
Actor model - “concurrent object-oriented programming”
Actors can create child actors
Actors are identified by addresses
Actors have mailboxes, where messages arrive
By default, messages are processed in the order
in which they arrived
/Anakin
Come to
the dark
side!
/Anakin/Luke /Anakin/Leia
Event sourcing and beyond with Akka.NET PersistenceVoltcode
Actor model - benefits
No deadlocks!
No shared state!
No global mutable state!
Fault isolation - “let it crash”!
Encapsulation!
Event sourcing and beyond with Akka.NET PersistenceVoltcode
Actor frameworks - features
● “Green” threads
● Supervision tree
● Remote deployment
● Routing
● Clustering
● Distributed Pub-sub
● Conflict-free Replicated Data Types (CRDTs)
● Hot code reloading
Event sourcing and beyond with Akka.NET PersistenceVoltcode
Akka.NET Persistence
When actor dies, its state is lost
Supervision tree will restart it, with a clean slate (state)
To recover the state, durable storage must be used.
Couldn’t we just store the actor state in durable storage and retrieve during restart?
Enter - Akka.Persistence
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Akka.Persistence - core features
State persistence for stateful actors
Record events based on messages for eventual recovery - Event Sourcing
Optionally persist state snapshots
At-least-once delivery using AtLeastOnceDelivery mixin for PersistentActor
Pluggable storage (MS, PostgreSQL, MySQL, Cassandra, SQLite, etc. )
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Hello persistent actor
What’s needed?
ActorSystem in our application
Actor inheriting from UntypedPersistentActor or ReceivePersistentActor
(or analogous AtLeastOnce* versions)
Define PersistenceId for the Actor
Register Command handlers that generate Events which change the state
(Commands come from the outside)
Register Recovery handlers (for Event replay, in case of failure)
Deploy actors using actor system (or indirectly via router)
Configured event journal data store
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Persistent actor with snapshots
What’s needed?
Configured snapshot store
Implement logic for triggering snapshot storage and retrieval
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Actor
1.Command
(not persisted)
2. Event
(persisted)
3. State update
4. State Snapshot
(optional, persisted)
Persistent actor - command processing flow
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Actor
1. Recovery triggered
2. Load snapshot state
(optional)
3. Process remaining persisted events
(with state updates)
Persistent actor - recovery flow
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Hello AtLeastOnceDelivery actor
Why?
By default, Akka message delivery is the weakest - at-most-once guarantee
Often in distributed systems, we need a stronger guarantee - at-least-once,
which can be used to guarantee exactly-once delivery
What’s needed?
Actor must inherit from AtLeastOnceDelivery.*Actor
Actor must send using new Deliver methods and handle Confirm messages
Duplicate messages handling
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
AtLeastOnceDeliveryActor
1. Deliver ( message )
AtLeastOnceDelivery message exchange
Actor
Keep on resending until
confirmed
2. Confirm delivery
Store
unconfirmed
delivery
Delivery
confirmed, time
to chill out :)
During recovery, messages with confirmed delivery are not
sent again. Unconfirmed messages are sent after recovery.
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Example - cash machine and bank processes
Scenario
User accesses his bank account via a CashMachine,
Allowed operations: withdraw, deposit money, check account balance
Actors
CashMachine (AtLeastOnceDeliveryActor, SQLite backend)
Banker (PersistentActor, MS SQL backend)
AkkaNetPersistenceSamples.sln
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Example - DebitAccount process
AkkaNetPersistenceSamples.sln
CashMachine
(Actor)
DebitAccount (amount)
Banker
(Actor)
Keep on resending until confirmed!
Confirm delivery
CashMachine
(GUI)
Guaranteed<DebitAccount> (amount)
Persist event
(MessageQueued<DebitAccount>)
Persist event (AccountDebited),
Update account state
Optionally - save state snapshot
User
clicks
“debit”
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Additional features (1)
● Clean up old messages and snapshots (!)
○ Messages can be deleted using DeleteMessages method (ToSeqNumber)
○ Snapshots can be deleted using DeleteSnapshot(s) methods
● Event adapters
○ Built-in support for event schema migrations (aka upcasting)
○ Translations between data model and domain model for events
○ Specialized event persistence on a per event type basis
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
● Persistent Finite State Machines
○ Persistence for Akka’s FSM
○ More explicit modeling of states and transitions between them, with event sourcing and snapshotting
● Persistent Query (new) / View (deprecated)
○ Query side of CQRS pattern
○ ReadJournal for materializing read side queries using Akka Streams
■ Subscribe to events, in a read-optimized manner
■ Materialize values of queries
■ Allow for querying events by tags, provided by event adapters
○ Akka.Persistence.Query - separate Nuget, still in beta.
○ Akka.Persistence.Query.Sql - ReadJournal implementation for ADO.NET stores.
Additional features (2)
Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode
Additional features (3)
● Cluster Sharding (with Akka.Cluster)
Library for implementing entities (objects with id) sharding with support for:
● automatic distribution - split entities across cluster nodes without manually providing their
target addresses
● rebalancing of entities (objects with id) - handle cluster membership changes (nodes coming in
and going)
Special actor “coordinator” takes care of shardig management. It requires an event journal accessible
by all of the participating nodes.
CRDTs (Akka.DistributedData) can be used to achieve the same functionality, but it is now in experimental
stage
Event sourcing and beyond with Akka.NET PersistenceVoltcode
Resources
Code samples (soon) available under:
https://github.com/voltcode/AkkaNetPersistenceSamples
Find out more about Akka.NET and the Actor Model:
http://getakka.net
https://github.com/akkadotnet/akka.net/
https://gitter.im/akkadotnet/akka.net
https://petabridge.com/bootcamp/
http://petabridge.com/blog
http://bartoszsypytkowski.com/
Many resources available for Akka (Lightbend documentation)
actor model, clusters in general (Erlang, Riak - basho)
Book(Scala) : Reactive Design Patterns

More Related Content

What's hot

Actor model in .NET - Akka.NET
Actor model in .NET - Akka.NETActor model in .NET - Akka.NET
Actor model in .NET - Akka.NETKonrad Dusza
 
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NETDotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NETpetabridge
 
CQRS + ES with Scala and Akka
CQRS + ES with Scala and AkkaCQRS + ES with Scala and Akka
CQRS + ES with Scala and AkkaBharadwaj N
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelMassimo Bonanni
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to AkkaKnoldus Inc.
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matterSkills Matter
 
## Introducing a reactive Scala-Akka based system in a Java centric company
## Introducing a reactive Scala-Akka based system in a Java centric company## Introducing a reactive Scala-Akka based system in a Java centric company
## Introducing a reactive Scala-Akka based system in a Java centric companyMilan Aleksić
 
Syncromatics Akka.NET Case Study
Syncromatics Akka.NET Case StudySyncromatics Akka.NET Case Study
Syncromatics Akka.NET Case Studypetabridge
 
Durable Functions vs Logic App : la guerra dei workflow!!
Durable Functions vs Logic App : la guerra dei workflow!!Durable Functions vs Logic App : la guerra dei workflow!!
Durable Functions vs Logic App : la guerra dei workflow!!Massimo Bonanni
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8Johan Andrén
 
Serverless Event Sourcing
Serverless Event SourcingServerless Event Sourcing
Serverless Event SourcingLuca Bianchi
 
Akka for big data developers
Akka for big data developersAkka for big data developers
Akka for big data developersTaras Fedorov
 
Axon Framework, Exploring CQRS and Event Sourcing Architecture
Axon Framework, Exploring CQRS and Event Sourcing ArchitectureAxon Framework, Exploring CQRS and Event Sourcing Architecture
Axon Framework, Exploring CQRS and Event Sourcing ArchitectureAshutosh Jadhav
 
Webinar - What's new in Axon 3
Webinar - What's new in Axon 3 Webinar - What's new in Axon 3
Webinar - What's new in Axon 3 Allard Buijze
 
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...Lightbend
 
Azure Service Fabric - weaving services in hyper-scale
Azure Service Fabric - weaving services in hyper-scaleAzure Service Fabric - weaving services in hyper-scale
Azure Service Fabric - weaving services in hyper-scaleSebastian Gebski
 
Workflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsWorkflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsMassimo Bonanni
 
DevOps.2D: two dimensions
of engineering
DevOps.2D: two dimensions
of  engineeringDevOps.2D: two dimensions
of  engineering
DevOps.2D: two dimensions
of engineeringAntons Kranga
 

What's hot (20)

Actor model in .NET - Akka.NET
Actor model in .NET - Akka.NETActor model in .NET - Akka.NET
Actor model in .NET - Akka.NET
 
Akka (1)
Akka (1)Akka (1)
Akka (1)
 
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NETDotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
 
CQRS + ES with Scala and Akka
CQRS + ES with Scala and AkkaCQRS + ES with Scala and Akka
CQRS + ES with Scala and Akka
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor model
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to Akka
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matter
 
## Introducing a reactive Scala-Akka based system in a Java centric company
## Introducing a reactive Scala-Akka based system in a Java centric company## Introducing a reactive Scala-Akka based system in a Java centric company
## Introducing a reactive Scala-Akka based system in a Java centric company
 
Syncromatics Akka.NET Case Study
Syncromatics Akka.NET Case StudySyncromatics Akka.NET Case Study
Syncromatics Akka.NET Case Study
 
Durable Functions vs Logic App : la guerra dei workflow!!
Durable Functions vs Logic App : la guerra dei workflow!!Durable Functions vs Logic App : la guerra dei workflow!!
Durable Functions vs Logic App : la guerra dei workflow!!
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8
 
Serverless Event Sourcing
Serverless Event SourcingServerless Event Sourcing
Serverless Event Sourcing
 
Akka for big data developers
Akka for big data developersAkka for big data developers
Akka for big data developers
 
Axon Framework, Exploring CQRS and Event Sourcing Architecture
Axon Framework, Exploring CQRS and Event Sourcing ArchitectureAxon Framework, Exploring CQRS and Event Sourcing Architecture
Axon Framework, Exploring CQRS and Event Sourcing Architecture
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
Webinar - What's new in Axon 3
Webinar - What's new in Axon 3 Webinar - What's new in Axon 3
Webinar - What's new in Axon 3
 
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
 
Azure Service Fabric - weaving services in hyper-scale
Azure Service Fabric - weaving services in hyper-scaleAzure Service Fabric - weaving services in hyper-scale
Azure Service Fabric - weaving services in hyper-scale
 
Workflow as code with Azure Durable Functions
Workflow as code with Azure Durable FunctionsWorkflow as code with Azure Durable Functions
Workflow as code with Azure Durable Functions
 
DevOps.2D: two dimensions
of engineering
DevOps.2D: two dimensions
of  engineeringDevOps.2D: two dimensions
of  engineering
DevOps.2D: two dimensions
of engineering
 

Similar to Event Sourcing and beyond with Akka.NET Persistence

Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And DesignYaroslav Tkachenko
 
Levelling up in Akka
Levelling up in AkkaLevelling up in Akka
Levelling up in AkkaSigmoid
 
Actors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesActors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesYaroslav Tkachenko
 
Avoiding the Pit of Despair - Event Sourcing with Akka and Cassandra
Avoiding the Pit of Despair - Event Sourcing with Akka and CassandraAvoiding the Pit of Despair - Event Sourcing with Akka and Cassandra
Avoiding the Pit of Despair - Event Sourcing with Akka and CassandraLuke Tillman
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_groupSkills Matter
 
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?João Pedro Martins
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den HoekRubiX BV
 
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...Lightbend
 
Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with AkkaMaciej Matyjas
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsMihail Gaberov
 
Scaling with Scala: refactoring a back-end service into the mobile age
Scaling with Scala: refactoring a back-end service into the mobile ageScaling with Scala: refactoring a back-end service into the mobile age
Scaling with Scala: refactoring a back-end service into the mobile ageDragos Manolescu
 
Device Simulator with Akka
Device Simulator with AkkaDevice Simulator with Akka
Device Simulator with AkkaMax Huang
 
Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Raymond Roestenburg
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Evan Chan
 
Conejo Architecture
Conejo ArchitectureConejo Architecture
Conejo Architecturepaulosuzart
 
Fabric - Realtime stream processing framework
Fabric - Realtime stream processing frameworkFabric - Realtime stream processing framework
Fabric - Realtime stream processing frameworkShashank Gautam
 
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Scala Italy
 

Similar to Event Sourcing and beyond with Akka.NET Persistence (20)

Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Akka (BeJUG)
Akka (BeJUG)Akka (BeJUG)
Akka (BeJUG)
 
Levelling up in Akka
Levelling up in AkkaLevelling up in Akka
Levelling up in Akka
 
Actors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesActors or Not: Async Event Architectures
Actors or Not: Async Event Architectures
 
Avoiding the Pit of Despair - Event Sourcing with Akka and Cassandra
Avoiding the Pit of Despair - Event Sourcing with Akka and CassandraAvoiding the Pit of Despair - Event Sourcing with Akka and Cassandra
Avoiding the Pit of Despair - Event Sourcing with Akka and Cassandra
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
 
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den Hoek
 
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...
 
Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with Akka
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIs
 
AWS IoT Deep Dive
AWS IoT Deep DiveAWS IoT Deep Dive
AWS IoT Deep Dive
 
Scaling with Scala: refactoring a back-end service into the mobile age
Scaling with Scala: refactoring a back-end service into the mobile ageScaling with Scala: refactoring a back-end service into the mobile age
Scaling with Scala: refactoring a back-end service into the mobile age
 
Device Simulator with Akka
Device Simulator with AkkaDevice Simulator with Akka
Device Simulator with Akka
 
Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015
 
Conejo Architecture
Conejo ArchitectureConejo Architecture
Conejo Architecture
 
Fabric - Realtime stream processing framework
Fabric - Realtime stream processing frameworkFabric - Realtime stream processing framework
Fabric - Realtime stream processing framework
 
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
 

Recently uploaded

chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
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
 
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
 
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
 
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
 
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
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
(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
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
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
 
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
 
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
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
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.
 
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
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Recently uploaded (20)

chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
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...
 
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
 
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
 
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
 
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
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
(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...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
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
 
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
 
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...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
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...
 
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
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

Event Sourcing and beyond with Akka.NET Persistence

  • 1. Event Sourcing and beyond with Akka.NET Persistence Konrad Dusza Head of Engineering @ Bilander Group
  • 2. Event sourcing and beyond with Akka.NET PersistenceVoltcode Agenda ● Recap of the actor model and Akka.NET ● Persistence module - capabilities and use cases ● Akka.NET Persistence sample ● Additional Akka.NET Persistence features
  • 3. Event sourcing and beyond with Akka.NET PersistenceVoltcode Actors communicate by exchanging messages asynchronously Actors have internal state that is invisible from the outside, no shared mutable state Actors can decide to change their state upon reception of a message - behavior specification Each actor processes immutable messages sequentially - one message at a time* Actor model - “concurrent object-oriented programming” Actor State Behavior Messages
  • 4. Event sourcing and beyond with Akka.NET PersistenceVoltcode Actor model - “concurrent object-oriented programming” Actors can create child actors Actors are identified by addresses Actors have mailboxes, where messages arrive By default, messages are processed in the order in which they arrived /Anakin Come to the dark side! /Anakin/Luke /Anakin/Leia
  • 5. Event sourcing and beyond with Akka.NET PersistenceVoltcode Actor model - benefits No deadlocks! No shared state! No global mutable state! Fault isolation - “let it crash”! Encapsulation!
  • 6. Event sourcing and beyond with Akka.NET PersistenceVoltcode Actor frameworks - features ● “Green” threads ● Supervision tree ● Remote deployment ● Routing ● Clustering ● Distributed Pub-sub ● Conflict-free Replicated Data Types (CRDTs) ● Hot code reloading
  • 7. Event sourcing and beyond with Akka.NET PersistenceVoltcode Akka.NET Persistence When actor dies, its state is lost Supervision tree will restart it, with a clean slate (state) To recover the state, durable storage must be used. Couldn’t we just store the actor state in durable storage and retrieve during restart? Enter - Akka.Persistence
  • 8. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Akka.Persistence - core features State persistence for stateful actors Record events based on messages for eventual recovery - Event Sourcing Optionally persist state snapshots At-least-once delivery using AtLeastOnceDelivery mixin for PersistentActor Pluggable storage (MS, PostgreSQL, MySQL, Cassandra, SQLite, etc. )
  • 9. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Hello persistent actor What’s needed? ActorSystem in our application Actor inheriting from UntypedPersistentActor or ReceivePersistentActor (or analogous AtLeastOnce* versions) Define PersistenceId for the Actor Register Command handlers that generate Events which change the state (Commands come from the outside) Register Recovery handlers (for Event replay, in case of failure) Deploy actors using actor system (or indirectly via router) Configured event journal data store
  • 10. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Persistent actor with snapshots What’s needed? Configured snapshot store Implement logic for triggering snapshot storage and retrieval
  • 11. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Actor 1.Command (not persisted) 2. Event (persisted) 3. State update 4. State Snapshot (optional, persisted) Persistent actor - command processing flow
  • 12. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Actor 1. Recovery triggered 2. Load snapshot state (optional) 3. Process remaining persisted events (with state updates) Persistent actor - recovery flow
  • 13. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Hello AtLeastOnceDelivery actor Why? By default, Akka message delivery is the weakest - at-most-once guarantee Often in distributed systems, we need a stronger guarantee - at-least-once, which can be used to guarantee exactly-once delivery What’s needed? Actor must inherit from AtLeastOnceDelivery.*Actor Actor must send using new Deliver methods and handle Confirm messages Duplicate messages handling
  • 14. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode AtLeastOnceDeliveryActor 1. Deliver ( message ) AtLeastOnceDelivery message exchange Actor Keep on resending until confirmed 2. Confirm delivery Store unconfirmed delivery Delivery confirmed, time to chill out :) During recovery, messages with confirmed delivery are not sent again. Unconfirmed messages are sent after recovery.
  • 15. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Example - cash machine and bank processes Scenario User accesses his bank account via a CashMachine, Allowed operations: withdraw, deposit money, check account balance Actors CashMachine (AtLeastOnceDeliveryActor, SQLite backend) Banker (PersistentActor, MS SQL backend) AkkaNetPersistenceSamples.sln
  • 16. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Example - DebitAccount process AkkaNetPersistenceSamples.sln CashMachine (Actor) DebitAccount (amount) Banker (Actor) Keep on resending until confirmed! Confirm delivery CashMachine (GUI) Guaranteed<DebitAccount> (amount) Persist event (MessageQueued<DebitAccount>) Persist event (AccountDebited), Update account state Optionally - save state snapshot User clicks “debit”
  • 17. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Additional features (1) ● Clean up old messages and snapshots (!) ○ Messages can be deleted using DeleteMessages method (ToSeqNumber) ○ Snapshots can be deleted using DeleteSnapshot(s) methods ● Event adapters ○ Built-in support for event schema migrations (aka upcasting) ○ Translations between data model and domain model for events ○ Specialized event persistence on a per event type basis
  • 18. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode ● Persistent Finite State Machines ○ Persistence for Akka’s FSM ○ More explicit modeling of states and transitions between them, with event sourcing and snapshotting ● Persistent Query (new) / View (deprecated) ○ Query side of CQRS pattern ○ ReadJournal for materializing read side queries using Akka Streams ■ Subscribe to events, in a read-optimized manner ■ Materialize values of queries ■ Allow for querying events by tags, provided by event adapters ○ Akka.Persistence.Query - separate Nuget, still in beta. ○ Akka.Persistence.Query.Sql - ReadJournal implementation for ADO.NET stores. Additional features (2)
  • 19. Voltcode Actor model in .NET - Akka.NetVoltcode Event sourcing and beyond with Akka.NET PersistenceVoltcode Additional features (3) ● Cluster Sharding (with Akka.Cluster) Library for implementing entities (objects with id) sharding with support for: ● automatic distribution - split entities across cluster nodes without manually providing their target addresses ● rebalancing of entities (objects with id) - handle cluster membership changes (nodes coming in and going) Special actor “coordinator” takes care of shardig management. It requires an event journal accessible by all of the participating nodes. CRDTs (Akka.DistributedData) can be used to achieve the same functionality, but it is now in experimental stage
  • 20. Event sourcing and beyond with Akka.NET PersistenceVoltcode Resources Code samples (soon) available under: https://github.com/voltcode/AkkaNetPersistenceSamples Find out more about Akka.NET and the Actor Model: http://getakka.net https://github.com/akkadotnet/akka.net/ https://gitter.im/akkadotnet/akka.net https://petabridge.com/bootcamp/ http://petabridge.com/blog http://bartoszsypytkowski.com/ Many resources available for Akka (Lightbend documentation) actor model, clusters in general (Erlang, Riak - basho) Book(Scala) : Reactive Design Patterns