SlideShare a Scribd company logo
Akka Persistence | Event Sourcing
Sidharth Khattri
Senior Software Consultant
Knoldus Software
Agenda
● What is Event Sourcing
● What are Domain Events
● What are Commands
● What is CQRS
● When to use Event Sourcing
● What is Akka Persistence
● Command side of Akka Persistence
Agenda
● What is Event Sourcing
● What are Domain Events
● What are Commands
● What is CQRS
● When to use Event Sourcing
● What is Akka Persistence
● Command side of Akka Persistence
What is Event Sourcing?
● storing all changes of a system as event log
● changes here means Domain Events
● changes are persisted in Event Store
● event store is append only storage
● no updates to Event Store, they're immutable
● event log can be replayed to construct current state
Agenda
● What is Event Sourcing
● What are Domain Events
● What are Commands
● What is CQRS
● When to use Event Sourcing
● What is Akka Persistence
● Command side of Akka Persistence
What are Domain Events?
● something that already took place in a system
● named as past-participle verbs
● statement of facts
● data transfer objects DTOs
● immutable, because they're facts
● represents state change in a system
Agenda
● What is Event Sourcing
● What are Domain Events
● What are Commands
● What is CQRS
● When to use Event Sourcing
● What is Akka Persistence
● Command side of Akka Persistence
What are Commands?
● something that triggers a Domain Event
● named as imperative verbs
● are requests but not statement of facts
● data transfer objects DTOs
● immutable, because they're are triggers
● can be rejected
Agenda
● What is Event Sourcing
● What are Domain Events
● What are Commands
● What is CQRS
● When to use Event Sourcing
● What is Akka Persistence
● Command side of Akka Persistence
What is CQRS?
● CQRS stands for command query responsibility segregation
● commands as write sides and query as read sides
● commands involve domain model interaction
● queries involve reporting module interaction
What is CQRS?
● aggregate roots receives Commands and publish Events
● aggregate is a group of associated objects
● an aggregate has one root, which is an Entity
● aggregate root is the only object accessible from outside world
Architecture Without CQRS
Architecture With CQRS
Agenda
● What is Event Sourcing
● What are Domain Events
● What are Commands
● What is CQRS
● When to use Event Sourcing
● What is Akka Persistence
● Command side of Akka Persistence
When to use Event Sourcing?
● when keeping audit/event logs have great significance
● for building scalable systems
● for predicting future needs based on event logs
● for better debugging
Agenda
● What is Event Sourcing
● What are Domain Events
● What are Commands
● What is CQRS
● When to use Event Sourcing
● What is Akka Persistence
● Command side of Akka Persistence
What is Akka Persistence?
● provides reactive way of facilitating DDD/CQRS event
sourced architecture
● is implicitly event-driven
Agenda
● What is Event Sourcing
● What are Domain Events
● What are Commands
● What is CQRS
● When to use Event Sourcing
● What is Akka Persistence
● Command side of Akka Persistence
What is PersistenceActor?
● PersistenceActor is a trait which supports Event Sourcing
● it can act as an Aggregate Root (AR) for DDD
● its behavior is defined by receiveRecover and receiveCommand
● receiveCommand acts as command handler
● receiveRecover helps in replaying events
Command side of Akka Persistence
● Command
case class CreateUser(id: String, firstName: String, lastName: String, email: String)
● Event
case class UserCreated(id: String, firstName: String, lastName: String, email: String)
Imperative verb
Immutable
Past-participle verb
Immutable
object Protocols {
case class Command(data: String)
case class Event(data: String)
}
final case class ExampleState(events: List[String] = Nil) {
def updated(event: Event): ExampleState = copy(event.data :: events)
def size: Int = events.length
override def toString: String = events.reverse.toString()
}
Persistence example protocols
For maintaining
Persistence example state
class PersistenceExample extends PersistenceActor with ActorLogging {
override def persistenceId: String = "persistence-example-1"
var state = ExampleState()
def updateState(event: Event): Unit = state = state.updated(event)
def numEvents: Int = state.size
val receiveRecover: Receive = {
case event: Event => updateState(event)
}
val receiveCommand: Receive = {
case Command(data) =>
persist(Event(s"$data-${numEvents + 1}")) { event =>
updateState(event)
}
}
}
PersistenceActor Details
● persistenceId method
→ id of entity for which events should be replayed
→ remains same across different actor incarnations
● persist method
→ persists events asynchronously
→ handler is only called on successful persistence
→ between call to persist and execution of handler no new commands are received
→ event handlers can update state, notify listeners and reply senders
PersistenceActor Details
override def recovery = Recovery(toSequenceNr = 457)
● recovery method
→ journals are automatically recovered on start and restart
→ new messages sent to persistence actor during recovery do not interfere with
replayed messages
→ recovery can be disabled by using Recovery.none()
→ initialization after recovery can be done can be done by handling
RecoveryCompleted
References
● http://doc.akka.io/docs/akka/2.4.0/scala/persistence.html
● http://martinfowler.com/eaaDev/EventSourcing.html
● http://cqrs.nu/faq
● https://github.com/ironfish/akka-persistence-mongo-samples
● http://pkaczor.blogspot.in/2014/04/reactive-ddd-with-akka.html
Thank You

More Related Content

PDF
Resilient Applications with Akka Persistence - Scaladays 2014
PDF
Akka Cluster in Production
PPTX
CQRS + ES with Scala and Akka
PDF
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...
PDF
Reactive Jersey Client
PDF
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
PDF
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
PDF
NoSQL design pitfalls with Java
Resilient Applications with Akka Persistence - Scaladays 2014
Akka Cluster in Production
CQRS + ES with Scala and Akka
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...
Reactive Jersey Client
Modern Cloud-Native Jakarta EE Frameworks: tips, challenges, and trends.
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
NoSQL design pitfalls with Java

What's hot (20)

PDF
Do's and don'ts when deploying akka in production
PDF
Building stateful systems with akka cluster sharding
PPTX
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
PDF
Bootstrapping Microservices with Kafka, Akka and Spark
PDF
Lagom - Mircoservices "Just Right"
PDF
A Tale of Two APIs: Using Spark Streaming In Production
PDF
UDF/UDAF: the extensibility framework for KSQL (Hojjat Jafapour, Confluent) K...
PDF
Building Stateful Microservices With Akka
PDF
Avoiding the Pit of Despair - Event Sourcing with Akka and Cassandra
PDF
Akka Streams And Kafka Streams: Where Microservices Meet Fast Data
PDF
Akka, Spark or Kafka? Selecting The Right Streaming Engine For the Job
PPTX
CQRS Evolved - CQRS + Akka.NET
PDF
Service discovery with Eureka and Spring Cloud
PDF
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
PDF
Moving from Big Data to Fast Data? Here's How To Pick The Right Streaming Engine
PPTX
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
PDF
Akka and Kubernetes: Reactive From Code To Cloud
PDF
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
PDF
Streaming Microservices With Akka Streams And Kafka Streams
PDF
Reactive Streams: Handling Data-Flow the Reactive Way
Do's and don'ts when deploying akka in production
Building stateful systems with akka cluster sharding
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Bootstrapping Microservices with Kafka, Akka and Spark
Lagom - Mircoservices "Just Right"
A Tale of Two APIs: Using Spark Streaming In Production
UDF/UDAF: the extensibility framework for KSQL (Hojjat Jafapour, Confluent) K...
Building Stateful Microservices With Akka
Avoiding the Pit of Despair - Event Sourcing with Akka and Cassandra
Akka Streams And Kafka Streams: Where Microservices Meet Fast Data
Akka, Spark or Kafka? Selecting The Right Streaming Engine For the Job
CQRS Evolved - CQRS + Akka.NET
Service discovery with Eureka and Spring Cloud
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Moving from Big Data to Fast Data? Here's How To Pick The Right Streaming Engine
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Akka and Kubernetes: Reactive From Code To Cloud
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Streaming Microservices With Akka Streams And Kafka Streams
Reactive Streams: Handling Data-Flow the Reactive Way
Ad

Viewers also liked (20)

PDF
Akka persistence == event sourcing in 30 minutes
PDF
Akka Persistence and Eventuate
PDF
Akka persistence webinar
PDF
Event-sourced architectures with Akka
PDF
Consistency without Consensus: CRDTs in Production at SoundCloud
PDF
CRDTs for engineers
ODP
Clojure basics
PPTX
Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015
PDF
scalaphx-akka-http
PDF
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
ODP
Reactive programming with scala and akka
PDF
Akka Streams
PDF
Event Sourcing using Akka on AWS
PPTX
Akka-http
PPTX
CQRS+ESをAkka Persistenceを使って実装してみる。
PPTX
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
PDF
Akka Http , Routes, Streams with Scala
PDF
DDDing Tools = Akka Persistence
PDF
The Cloud-natives are RESTless @ JavaOne
PPTX
Expert Fridays - Сергей Укустов: "CRDT"
Akka persistence == event sourcing in 30 minutes
Akka Persistence and Eventuate
Akka persistence webinar
Event-sourced architectures with Akka
Consistency without Consensus: CRDTs in Production at SoundCloud
CRDTs for engineers
Clojure basics
Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015
scalaphx-akka-http
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
Reactive programming with scala and akka
Akka Streams
Event Sourcing using Akka on AWS
Akka-http
CQRS+ESをAkka Persistenceを使って実装してみる。
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
Akka Http , Routes, Streams with Scala
DDDing Tools = Akka Persistence
The Cloud-natives are RESTless @ JavaOne
Expert Fridays - Сергей Укустов: "CRDT"
Ad

Similar to Akka Persistence | Event Sourcing (20)

PDF
Using Akka Persistence to build a configuration datastore
PDF
Event-sourced architectures with Akka - Sander Mak
PPTX
Cqrs and event sourcing in azure
PDF
CQRS and Event Sourcing in Action
PDF
Introduction to Event Sourcing,CQRS and Axon
PPTX
Actors, akka, streams
PPTX
CQRS and Event Sourcing with Axon Framework
PPT
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
PDF
Event Sourcing - what could possibly go wrong?
PDF
Scala in increasingly demanding environments - DATABIZ
PDF
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
PDF
The Fine Art of Time Travelling: implementing Event Sourcing
PDF
CQRS & Event Sourcing
PDF
Akka PersistenceのJournalのライフサイクル管理
PDF
Event Sourcing on AWS Using Akka in Java
PPTX
DDD meets CQRS and event sourcing
PDF
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
PPTX
Axon Framework, Exploring CQRS and Event Sourcing Architecture
PDF
fram^ TechTalk #1 - CQRS and Event Sourcing (ES)
PDF
Implementing Event Sourcing in .NET
Using Akka Persistence to build a configuration datastore
Event-sourced architectures with Akka - Sander Mak
Cqrs and event sourcing in azure
CQRS and Event Sourcing in Action
Introduction to Event Sourcing,CQRS and Axon
Actors, akka, streams
CQRS and Event Sourcing with Axon Framework
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Event Sourcing - what could possibly go wrong?
Scala in increasingly demanding environments - DATABIZ
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
The Fine Art of Time Travelling: implementing Event Sourcing
CQRS & Event Sourcing
Akka PersistenceのJournalのライフサイクル管理
Event Sourcing on AWS Using Akka in Java
DDD meets CQRS and event sourcing
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
Axon Framework, Exploring CQRS and Event Sourcing Architecture
fram^ TechTalk #1 - CQRS and Event Sourcing (ES)
Implementing Event Sourcing in .NET

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
PPTX
Self-Healing Test Automation Framework - Healenium
PPTX
Kanban Metrics Presentation (Project Management)
PPTX
Java 17 features and implementation.pptx
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
PPTX
GraalVM - A Step Ahead of JVM Presentation
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
DAPR - Distributed Application Runtime Presentation
PPTX
Introduction to Azure Virtual WAN Presentation
PPTX
Introduction to Argo Rollouts Presentation
PPTX
Intro to Azure Container App Presentation
PPTX
Insights Unveiled Test Reporting and Observability Excellence
PPTX
Introduction to Splunk Presentation (DevOps)
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
PPTX
AWS: Messaging Services in AWS Presentation
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
PPTX
Managing State & HTTP Requests In Ionic.
Angular Hydration Presentation (FrontEnd)
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Self-Healing Test Automation Framework - Healenium
Kanban Metrics Presentation (Project Management)
Java 17 features and implementation.pptx
Chaos Mesh Introducing Chaos in Kubernetes
GraalVM - A Step Ahead of JVM Presentation
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
DAPR - Distributed Application Runtime Presentation
Introduction to Azure Virtual WAN Presentation
Introduction to Argo Rollouts Presentation
Intro to Azure Container App Presentation
Insights Unveiled Test Reporting and Observability Excellence
Introduction to Splunk Presentation (DevOps)
Code Camp - Data Profiling and Quality Analysis Framework
AWS: Messaging Services in AWS Presentation
Amazon Cognito: A Primer on Authentication and Authorization
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Managing State & HTTP Requests In Ionic.

Recently uploaded (20)

PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
GDM (1) (1).pptx small presentation for students
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Pre independence Education in Inndia.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Cell Structure & Organelles in detailed.
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
Microbial disease of the cardiovascular and lymphatic systems
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
Renaissance Architecture: A Journey from Faith to Humanism
GDM (1) (1).pptx small presentation for students
102 student loan defaulters named and shamed – Is someone you know on the list?
Pre independence Education in Inndia.pdf
TR - Agricultural Crops Production NC III.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Insiders guide to clinical Medicine.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
STATICS OF THE RIGID BODIES Hibbelers.pdf
01-Introduction-to-Information-Management.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Cell Structure & Organelles in detailed.
Anesthesia in Laparoscopic Surgery in India
2.FourierTransform-ShortQuestionswithAnswers.pdf

Akka Persistence | Event Sourcing

  • 1. Akka Persistence | Event Sourcing Sidharth Khattri Senior Software Consultant Knoldus Software
  • 2. Agenda ● What is Event Sourcing ● What are Domain Events ● What are Commands ● What is CQRS ● When to use Event Sourcing ● What is Akka Persistence ● Command side of Akka Persistence
  • 3. Agenda ● What is Event Sourcing ● What are Domain Events ● What are Commands ● What is CQRS ● When to use Event Sourcing ● What is Akka Persistence ● Command side of Akka Persistence
  • 4. What is Event Sourcing? ● storing all changes of a system as event log ● changes here means Domain Events ● changes are persisted in Event Store ● event store is append only storage ● no updates to Event Store, they're immutable ● event log can be replayed to construct current state
  • 5. Agenda ● What is Event Sourcing ● What are Domain Events ● What are Commands ● What is CQRS ● When to use Event Sourcing ● What is Akka Persistence ● Command side of Akka Persistence
  • 6. What are Domain Events? ● something that already took place in a system ● named as past-participle verbs ● statement of facts ● data transfer objects DTOs ● immutable, because they're facts ● represents state change in a system
  • 7. Agenda ● What is Event Sourcing ● What are Domain Events ● What are Commands ● What is CQRS ● When to use Event Sourcing ● What is Akka Persistence ● Command side of Akka Persistence
  • 8. What are Commands? ● something that triggers a Domain Event ● named as imperative verbs ● are requests but not statement of facts ● data transfer objects DTOs ● immutable, because they're are triggers ● can be rejected
  • 9. Agenda ● What is Event Sourcing ● What are Domain Events ● What are Commands ● What is CQRS ● When to use Event Sourcing ● What is Akka Persistence ● Command side of Akka Persistence
  • 10. What is CQRS? ● CQRS stands for command query responsibility segregation ● commands as write sides and query as read sides ● commands involve domain model interaction ● queries involve reporting module interaction
  • 11. What is CQRS? ● aggregate roots receives Commands and publish Events ● aggregate is a group of associated objects ● an aggregate has one root, which is an Entity ● aggregate root is the only object accessible from outside world
  • 14. Agenda ● What is Event Sourcing ● What are Domain Events ● What are Commands ● What is CQRS ● When to use Event Sourcing ● What is Akka Persistence ● Command side of Akka Persistence
  • 15. When to use Event Sourcing? ● when keeping audit/event logs have great significance ● for building scalable systems ● for predicting future needs based on event logs ● for better debugging
  • 16. Agenda ● What is Event Sourcing ● What are Domain Events ● What are Commands ● What is CQRS ● When to use Event Sourcing ● What is Akka Persistence ● Command side of Akka Persistence
  • 17. What is Akka Persistence? ● provides reactive way of facilitating DDD/CQRS event sourced architecture ● is implicitly event-driven
  • 18. Agenda ● What is Event Sourcing ● What are Domain Events ● What are Commands ● What is CQRS ● When to use Event Sourcing ● What is Akka Persistence ● Command side of Akka Persistence
  • 19. What is PersistenceActor? ● PersistenceActor is a trait which supports Event Sourcing ● it can act as an Aggregate Root (AR) for DDD ● its behavior is defined by receiveRecover and receiveCommand ● receiveCommand acts as command handler ● receiveRecover helps in replaying events
  • 20. Command side of Akka Persistence ● Command case class CreateUser(id: String, firstName: String, lastName: String, email: String) ● Event case class UserCreated(id: String, firstName: String, lastName: String, email: String) Imperative verb Immutable Past-participle verb Immutable
  • 21. object Protocols { case class Command(data: String) case class Event(data: String) } final case class ExampleState(events: List[String] = Nil) { def updated(event: Event): ExampleState = copy(event.data :: events) def size: Int = events.length override def toString: String = events.reverse.toString() } Persistence example protocols For maintaining Persistence example state
  • 22. class PersistenceExample extends PersistenceActor with ActorLogging { override def persistenceId: String = "persistence-example-1" var state = ExampleState() def updateState(event: Event): Unit = state = state.updated(event) def numEvents: Int = state.size val receiveRecover: Receive = { case event: Event => updateState(event) } val receiveCommand: Receive = { case Command(data) => persist(Event(s"$data-${numEvents + 1}")) { event => updateState(event) } } }
  • 23. PersistenceActor Details ● persistenceId method → id of entity for which events should be replayed → remains same across different actor incarnations ● persist method → persists events asynchronously → handler is only called on successful persistence → between call to persist and execution of handler no new commands are received → event handlers can update state, notify listeners and reply senders
  • 24. PersistenceActor Details override def recovery = Recovery(toSequenceNr = 457) ● recovery method → journals are automatically recovered on start and restart → new messages sent to persistence actor during recovery do not interfere with replayed messages → recovery can be disabled by using Recovery.none() → initialization after recovery can be done can be done by handling RecoveryCompleted
  • 25. References ● http://doc.akka.io/docs/akka/2.4.0/scala/persistence.html ● http://martinfowler.com/eaaDev/EventSourcing.html ● http://cqrs.nu/faq ● https://github.com/ironfish/akka-persistence-mongo-samples ● http://pkaczor.blogspot.in/2014/04/reactive-ddd-with-akka.html

Editor's Notes

  • #5: In systems built around event sourcing, everything that happens (events) is persisted is a event log instead of just persisting the current state. An event log is a place which records all the events that happened in a system.
  • #7: Event is something that took place in a domain. These are always named with a past-participle verb, example EmailChanged. Since it is something that has already happened it can be considered as a statement of fact. Both Events and Commands are DTOs (Data transfer objects) and both are immutable. Events are immutable because they represent domain actions that happened in the past.
  • #9: Command is something which makes the Event happen. It is used to request changes to the Domain. Since it is a request it can be rejected, it is not a statement of fact. It is a verb with imperative mood. Both Events and Commands are DTOs (Data transfer objects) and both are immutable. Commands are immutable because their only usage is to be sent from the client to server side to trigger and event.
  • #23: Successfully persisted events are internally sent back to the persistent actor as individual messages that trigger event handler executions. An event handler may close over persistent actor state and mutate it. The sender of a persisted event is the sender of the corresponding command. This allows event handlers to reply to the sender of a command (not shown).