SlideShare a Scribd company logo
11
CQRS + ES with Scala and Akka
Bharadwaj
19th June 2016
Agenda
1. Event Sourcing  CQRS  Akka and Distribution  DDD
2. Demo
Bank Database
Question 1: Is the balance in your bank account a value from a column
on a row in a relational database?
Bank Database
Question 1: Is the balance in your bank account a value from a column
on a row in a relational database?
Question 2: How many of you would be comfortable if it were a value
from a column/row?
Bank Database
Question 1: Is the balance in your bank account a value from a column
on a row in a relational database?
Question 2: How many of you would be comfortable if it were a value
from a column/row?
“Bank balance is an equation”
Shopping Cart for a Event
• T1: Tickets go on sale at: ₹100
• T2: 10 Tickets sold
• T3: Ticket price increased to: ₹200
• T4: 2 tickets purchased between T1 and T2 get cancelled
• Every update or delete from a database results in
loss of data
• Databases with constant updates and deletes are
actually ‘shared mutable state’ of an application.
And ‘shared mutable state’ is evil
Event Sourcing
Journal of Immutable Facts aka Events in an append
only fashion
Event Sourcing
Journal of Immutable Facts aka Events in an append
only fashion
Event sourcing is actually just functional code
… thats NOT a practical database
• it will have too much data…
… thats NOT a practical database
• it will have too much data…
– storage will only getting cheaper
– tradeoff: data loss vs. volumes
– not for every problem: when data is important
… thats NOT a practical database
• it will have too much data…
– storage will only getting cheaper
– tradeoff: data loss vs. volumes
– not for every problem: when data is important
• every read will be a full table scan…
… thats NOT a practical database
• it will have too much data…
– storage will only getting cheaper
– tradeoff: data loss vs. volumes
– not for every problem: when data is important
• every read will be a full table scan…
– periodic rollup or snapshot
– snapshot: in functional programming, that is, current state = foldLeft (previous
states)
… thats NOT a practical database
• it will have too much data…
– storage will only getting cheaper
– tradeoff: data loss vs. volumes
– not for every problem: when data is important
• every read will be a full table scan…
– periodic rollup or snapshot
– snapshot: in functional programming, that is, current state = foldLeft (previous
states)
• how do you even model an application with this thing...
… thats NOT a practical database
• it will have too much data…
– storage will only getting cheaper
– tradeoff: data loss vs. volumes
– not for every problem: when data is important
• every read will be a full table scan…
– periodic rollup or snapshot
– snapshot: in functional programming, that is, current state = foldLeft (previous
states)
• how do you even model an application with this thing...
– CQRS 
CQRS
• Command Query Responsibility Segregation
• CQRS says read and write paths need to be handled separately by applications
• Segregation because reads and writes almost always have very different
properties in every system
– Difference in order of magnitude of each in a system
– Difference in SLA
• Build them separately so that both can be scale. Using a singular layer like ORM
for both cannot be scaled
How to keep the write-side journal and read-side data-
store best effort consistent?
Akka allows the events created via commands to be sent
across to the read side to keep read models consistent
and update them quickly
Akka Persistent Actor Plugins
• Journal
– Cassandra, Kafka, Hbase, JDBC
• Snapshots
– Cassandra, Kafka, Hbase, JDBC
Command and Event Distinction
• Commands generate Events
• Events are immutable facts that can be replayed to restore
application state
Persistent Actor
Snapshotting Persistent Actor
Persistence Query
• Persistent Query actors send responses to incoming query messages
• Polls the Journal
• Each persistence query tracks either of:
– a single persistence-id
– a ‘tag’ shared by events of different persistent-ids
• Different options to build ‘materialization’ (snapshot) in persistent queries depending on
how one may want to materialize and the capabilities exposed by underlying Journal store
• Different types of persistence query actors would be needed in an application based on the
domain and queries
Demo
Akka persistence magic
1. No direct function calls or message passing between read and write side
!
Akka persistence magic
1. No direct function calls or message passing between read and write side
!
2. Restart the application to see the automatic state recovery !!
Akka persistence magic
1. No direct function calls or message passing between read and write side
!
2. Restart the application to see the automatic state recovery !!
3. Underneath, Akka plumbs the read and write side when they are on the
same JVM to reduce round-trip and faster read side updates !!!
Akka persistence magic
1. No direct function calls or message passing between read and write side
!
2. Restart the application to see the automatic state recovery !!
3. Underneath, Akka plumbs the read and write side when they are on the
same JVM to reduce round-trip and faster read side updates !!!
4. Mix this with Akka clustering and a distributed journal to scale
horizontally !!!!
Akka Addendum
• Akka Persistence View is deprecated and Persistence Query takes its place
• Akka Persistence Actors (Write side) have to be cluster singletons
• Just using Akka Clustering with Akka Persistence severely limits the possibilities
since cluster singletons in clustering are always placed on the oldest node. To
control actor placement within the cluster, use Akka Sharding
• Different CQRS implementations with Akka:
– ‘Eventsourced’ was the first CQRS project on Akka. It supported up to Akka 2.2.0. Akka
persistence is influenced by it and was released in Akka 2.4.0. ‘Eventsourced’ is now legacy
– ‘Eventuate’ is an alternative to Akka persistence. It seems to have more features than Akka
persistence
– Experimental
How to design a system or app with ES and CQRS… ?
• How to model Persistent Actors? How to model Persistent Query’s?
• Designing commands and events and aggregates
How to design a system or app with ES and CQRS… ?
• How to model Persistent Actors? How to model Persistent Query’s?
• Designing commands and events and aggregates
• DDD  domain driven design
– Eventual consistency
– No distributed transactions
– Many more…
References
• Akka Persistence Documentation
• Greg Young: CQRS and Event Sourcing -
https://www.youtube.com/watch?v=JHGkaShoyNs
• Sander Mak: Event Sourced Architectures with Akka -
https://www.youtube.com/watch?v=vFVry457XLk
• Martin Krasser: Event Sourcing and CQRS with Akka Persistence and Eventuate
- https://www.youtube.com/watch?v=vFVry457XLk
CQRS + ES with Scala and Akka

More Related Content

What's hot

Akka and AngularJS – Reactive Applications in Practice
Akka and AngularJS – Reactive Applications in PracticeAkka and AngularJS – Reactive Applications in Practice
Akka and AngularJS – Reactive Applications in Practice
Roland Kuhn
 
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
 
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and moreTypesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Legacy Typesafe (now Lightbend)
 
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
Johan Andrén
 
Actor model in .NET - Akka.NET
Actor model in .NET - Akka.NETActor model in .NET - Akka.NET
Actor model in .NET - Akka.NET
Konrad Dusza
 
Introduction to Akka.NET and Akka.Cluster
Introduction to Akka.NET and Akka.ClusterIntroduction to Akka.NET and Akka.Cluster
Introduction to Akka.NET and Akka.Cluster
petabridge
 
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous ArchitecturesUnderstanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Lightbend
 
Akkurate Akka
Akkurate AkkaAkkurate Akka
Akkurate Akka
Yurii Ostapchuk
 
Do's and don'ts when deploying akka in production
Do's and don'ts when deploying akka in productionDo's and don'ts when deploying akka in production
Do's and don'ts when deploying akka in production
jglobal
 
Docker. Does it matter for Java developer ?
Docker. Does it matter for Java developer ?Docker. Does it matter for Java developer ?
Docker. Does it matter for Java developer ?
Izzet Mustafaiev
 
DevOps.2D: two dimensions
of engineering
DevOps.2D: two dimensions
of  engineeringDevOps.2D: two dimensions
of  engineering
DevOps.2D: two dimensions
of engineering
Antons Kranga
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
Manuel Bernhardt
 
Stream Collections - Scala Days
Stream Collections - Scala DaysStream Collections - Scala Days
Stream Collections - Scala Days
Greg Silin
 
Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
Jonas Bonér
 
Introduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupIntroduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users Group
Roy Russo
 
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
Wooga
 
Erlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughputErlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughput
Paolo Negri
 
Lightbend Training for Scala, Akka, Play Framework and Apache Spark
Lightbend Training for Scala, Akka, Play Framework and Apache SparkLightbend Training for Scala, Akka, Play Framework and Apache Spark
Lightbend Training for Scala, Akka, Play Framework and Apache Spark
Lightbend
 
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
petabridge
 
Java Colombo: Developing Highly Scalable Apps
Java Colombo: Developing Highly Scalable AppsJava Colombo: Developing Highly Scalable Apps
Java Colombo: Developing Highly Scalable AppsAfkham Azeez
 

What's hot (20)

Akka and AngularJS – Reactive Applications in Practice
Akka and AngularJS – Reactive Applications in PracticeAkka and AngularJS – Reactive Applications in Practice
Akka and AngularJS – Reactive Applications in Practice
 
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...
 
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and moreTypesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
 
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
 
Actor model in .NET - Akka.NET
Actor model in .NET - Akka.NETActor model in .NET - Akka.NET
Actor model in .NET - Akka.NET
 
Introduction to Akka.NET and Akka.Cluster
Introduction to Akka.NET and Akka.ClusterIntroduction to Akka.NET and Akka.Cluster
Introduction to Akka.NET and Akka.Cluster
 
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous ArchitecturesUnderstanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
 
Akkurate Akka
Akkurate AkkaAkkurate Akka
Akkurate Akka
 
Do's and don'ts when deploying akka in production
Do's and don'ts when deploying akka in productionDo's and don'ts when deploying akka in production
Do's and don'ts when deploying akka in production
 
Docker. Does it matter for Java developer ?
Docker. Does it matter for Java developer ?Docker. Does it matter for Java developer ?
Docker. Does it matter for Java developer ?
 
DevOps.2D: two dimensions
of engineering
DevOps.2D: two dimensions
of  engineeringDevOps.2D: two dimensions
of  engineering
DevOps.2D: two dimensions
of engineering
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
 
Stream Collections - Scala Days
Stream Collections - Scala DaysStream Collections - Scala Days
Stream Collections - Scala Days
 
Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
 
Introduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupIntroduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users Group
 
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
 
Erlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughputErlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughput
 
Lightbend Training for Scala, Akka, Play Framework and Apache Spark
Lightbend Training for Scala, Akka, Play Framework and Apache SparkLightbend Training for Scala, Akka, Play Framework and Apache Spark
Lightbend Training for Scala, Akka, Play Framework and Apache Spark
 
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
 
Java Colombo: Developing Highly Scalable Apps
Java Colombo: Developing Highly Scalable AppsJava Colombo: Developing Highly Scalable Apps
Java Colombo: Developing Highly Scalable Apps
 

Similar to CQRS + ES with Scala and Akka

BBL KAPPA Lesfurets.com
BBL KAPPA Lesfurets.comBBL KAPPA Lesfurets.com
BBL KAPPA Lesfurets.com
Cedric Vidal
 
Kafka & Hadoop in Rakuten
Kafka & Hadoop in RakutenKafka & Hadoop in Rakuten
Kafka & Hadoop in Rakuten
Rakuten Group, Inc.
 
SMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion Dubai
SMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion DubaiSMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion Dubai
SMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion Dubai
Codemotion Dubai
 
Multi-Datacenter Kafka - Strata San Jose 2017
Multi-Datacenter Kafka - Strata San Jose 2017Multi-Datacenter Kafka - Strata San Jose 2017
Multi-Datacenter Kafka - Strata San Jose 2017
Gwen (Chen) Shapira
 
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Erik Onnen
 
Spark and Couchbase: Augmenting the Operational Database with Spark
Spark and Couchbase: Augmenting the Operational Database with SparkSpark and Couchbase: Augmenting the Operational Database with Spark
Spark and Couchbase: Augmenting the Operational Database with Spark
Spark Summit
 
Multi-Cluster and Failover for Apache Kafka - Kafka Summit SF 17
Multi-Cluster and Failover for Apache Kafka - Kafka Summit SF 17Multi-Cluster and Failover for Apache Kafka - Kafka Summit SF 17
Multi-Cluster and Failover for Apache Kafka - Kafka Summit SF 17
Gwen (Chen) Shapira
 
Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...
Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...
Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...
StreamNative
 
Kafka streams decoupling with stores
Kafka streams decoupling with storesKafka streams decoupling with stores
Kafka streams decoupling with stores
Yoni Farin
 
Spark & Yarn better together 1.2
Spark & Yarn better together 1.2Spark & Yarn better together 1.2
Spark & Yarn better together 1.2
Jianfeng Zhang
 
CouchDB at its Core: Global Data Storage and Rich Incremental Indexing at Clo...
CouchDB at its Core: Global Data Storage and Rich Incremental Indexing at Clo...CouchDB at its Core: Global Data Storage and Rich Incremental Indexing at Clo...
CouchDB at its Core: Global Data Storage and Rich Incremental Indexing at Clo...
StampedeCon
 
Spark Streaming @ Scale (Clicktale)
Spark Streaming @ Scale (Clicktale)Spark Streaming @ Scale (Clicktale)
Spark Streaming @ Scale (Clicktale)
Yuval Itzchakov
 
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Paul Brebner
 
Disaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache KafkaDisaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache Kafka
confluent
 
Building Large-Scale Stream Infrastructures Across Multiple Data Centers with...
Building Large-Scale Stream Infrastructures Across Multiple Data Centers with...Building Large-Scale Stream Infrastructures Across Multiple Data Centers with...
Building Large-Scale Stream Infrastructures Across Multiple Data Centers with...
DataWorks Summit/Hadoop Summit
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
Mike Slinn
 
Embrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with RippleEmbrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with Ripple
Sean Cribbs
 
Typesafe & William Hill: Cassandra, Spark, and Kafka - The New Streaming Data...
Typesafe & William Hill: Cassandra, Spark, and Kafka - The New Streaming Data...Typesafe & William Hill: Cassandra, Spark, and Kafka - The New Streaming Data...
Typesafe & William Hill: Cassandra, Spark, and Kafka - The New Streaming Data...
DataStax Academy
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
C4Media
 
Using the SDACK Architecture to Build a Big Data Product
Using the SDACK Architecture to Build a Big Data ProductUsing the SDACK Architecture to Build a Big Data Product
Using the SDACK Architecture to Build a Big Data Product
Evans Ye
 

Similar to CQRS + ES with Scala and Akka (20)

BBL KAPPA Lesfurets.com
BBL KAPPA Lesfurets.comBBL KAPPA Lesfurets.com
BBL KAPPA Lesfurets.com
 
Kafka & Hadoop in Rakuten
Kafka & Hadoop in RakutenKafka & Hadoop in Rakuten
Kafka & Hadoop in Rakuten
 
SMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion Dubai
SMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion DubaiSMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion Dubai
SMACK Stack - Fast Data Done Right by Stefan Siprell at Codemotion Dubai
 
Multi-Datacenter Kafka - Strata San Jose 2017
Multi-Datacenter Kafka - Strata San Jose 2017Multi-Datacenter Kafka - Strata San Jose 2017
Multi-Datacenter Kafka - Strata San Jose 2017
 
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
 
Spark and Couchbase: Augmenting the Operational Database with Spark
Spark and Couchbase: Augmenting the Operational Database with SparkSpark and Couchbase: Augmenting the Operational Database with Spark
Spark and Couchbase: Augmenting the Operational Database with Spark
 
Multi-Cluster and Failover for Apache Kafka - Kafka Summit SF 17
Multi-Cluster and Failover for Apache Kafka - Kafka Summit SF 17Multi-Cluster and Failover for Apache Kafka - Kafka Summit SF 17
Multi-Cluster and Failover for Apache Kafka - Kafka Summit SF 17
 
Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...
Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...
Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...
 
Kafka streams decoupling with stores
Kafka streams decoupling with storesKafka streams decoupling with stores
Kafka streams decoupling with stores
 
Spark & Yarn better together 1.2
Spark & Yarn better together 1.2Spark & Yarn better together 1.2
Spark & Yarn better together 1.2
 
CouchDB at its Core: Global Data Storage and Rich Incremental Indexing at Clo...
CouchDB at its Core: Global Data Storage and Rich Incremental Indexing at Clo...CouchDB at its Core: Global Data Storage and Rich Incremental Indexing at Clo...
CouchDB at its Core: Global Data Storage and Rich Incremental Indexing at Clo...
 
Spark Streaming @ Scale (Clicktale)
Spark Streaming @ Scale (Clicktale)Spark Streaming @ Scale (Clicktale)
Spark Streaming @ Scale (Clicktale)
 
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
 
Disaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache KafkaDisaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache Kafka
 
Building Large-Scale Stream Infrastructures Across Multiple Data Centers with...
Building Large-Scale Stream Infrastructures Across Multiple Data Centers with...Building Large-Scale Stream Infrastructures Across Multiple Data Centers with...
Building Large-Scale Stream Infrastructures Across Multiple Data Centers with...
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
 
Embrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with RippleEmbrace NoSQL and Eventual Consistency with Ripple
Embrace NoSQL and Eventual Consistency with Ripple
 
Typesafe & William Hill: Cassandra, Spark, and Kafka - The New Streaming Data...
Typesafe & William Hill: Cassandra, Spark, and Kafka - The New Streaming Data...Typesafe & William Hill: Cassandra, Spark, and Kafka - The New Streaming Data...
Typesafe & William Hill: Cassandra, Spark, and Kafka - The New Streaming Data...
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
 
Using the SDACK Architecture to Build a Big Data Product
Using the SDACK Architecture to Build a Big Data ProductUsing the SDACK Architecture to Build a Big Data Product
Using the SDACK Architecture to Build a Big Data Product
 

Recently uploaded

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 

Recently uploaded (20)

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 

CQRS + ES with Scala and Akka

  • 1. 11 CQRS + ES with Scala and Akka Bharadwaj 19th June 2016
  • 2. Agenda 1. Event Sourcing  CQRS  Akka and Distribution  DDD 2. Demo
  • 3. Bank Database Question 1: Is the balance in your bank account a value from a column on a row in a relational database?
  • 4. Bank Database Question 1: Is the balance in your bank account a value from a column on a row in a relational database? Question 2: How many of you would be comfortable if it were a value from a column/row?
  • 5. Bank Database Question 1: Is the balance in your bank account a value from a column on a row in a relational database? Question 2: How many of you would be comfortable if it were a value from a column/row? “Bank balance is an equation”
  • 6. Shopping Cart for a Event • T1: Tickets go on sale at: ₹100 • T2: 10 Tickets sold • T3: Ticket price increased to: ₹200 • T4: 2 tickets purchased between T1 and T2 get cancelled
  • 7. • Every update or delete from a database results in loss of data • Databases with constant updates and deletes are actually ‘shared mutable state’ of an application. And ‘shared mutable state’ is evil
  • 8. Event Sourcing Journal of Immutable Facts aka Events in an append only fashion
  • 9. Event Sourcing Journal of Immutable Facts aka Events in an append only fashion Event sourcing is actually just functional code
  • 10. … thats NOT a practical database • it will have too much data…
  • 11. … thats NOT a practical database • it will have too much data… – storage will only getting cheaper – tradeoff: data loss vs. volumes – not for every problem: when data is important
  • 12. … thats NOT a practical database • it will have too much data… – storage will only getting cheaper – tradeoff: data loss vs. volumes – not for every problem: when data is important • every read will be a full table scan…
  • 13. … thats NOT a practical database • it will have too much data… – storage will only getting cheaper – tradeoff: data loss vs. volumes – not for every problem: when data is important • every read will be a full table scan… – periodic rollup or snapshot – snapshot: in functional programming, that is, current state = foldLeft (previous states)
  • 14. … thats NOT a practical database • it will have too much data… – storage will only getting cheaper – tradeoff: data loss vs. volumes – not for every problem: when data is important • every read will be a full table scan… – periodic rollup or snapshot – snapshot: in functional programming, that is, current state = foldLeft (previous states) • how do you even model an application with this thing...
  • 15. … thats NOT a practical database • it will have too much data… – storage will only getting cheaper – tradeoff: data loss vs. volumes – not for every problem: when data is important • every read will be a full table scan… – periodic rollup or snapshot – snapshot: in functional programming, that is, current state = foldLeft (previous states) • how do you even model an application with this thing... – CQRS 
  • 16. CQRS • Command Query Responsibility Segregation • CQRS says read and write paths need to be handled separately by applications • Segregation because reads and writes almost always have very different properties in every system – Difference in order of magnitude of each in a system – Difference in SLA • Build them separately so that both can be scale. Using a singular layer like ORM for both cannot be scaled
  • 17.
  • 18. How to keep the write-side journal and read-side data- store best effort consistent? Akka allows the events created via commands to be sent across to the read side to keep read models consistent and update them quickly
  • 19. Akka Persistent Actor Plugins • Journal – Cassandra, Kafka, Hbase, JDBC • Snapshots – Cassandra, Kafka, Hbase, JDBC
  • 20. Command and Event Distinction • Commands generate Events • Events are immutable facts that can be replayed to restore application state
  • 23. Persistence Query • Persistent Query actors send responses to incoming query messages • Polls the Journal • Each persistence query tracks either of: – a single persistence-id – a ‘tag’ shared by events of different persistent-ids • Different options to build ‘materialization’ (snapshot) in persistent queries depending on how one may want to materialize and the capabilities exposed by underlying Journal store • Different types of persistence query actors would be needed in an application based on the domain and queries
  • 24. Demo
  • 25. Akka persistence magic 1. No direct function calls or message passing between read and write side !
  • 26. Akka persistence magic 1. No direct function calls or message passing between read and write side ! 2. Restart the application to see the automatic state recovery !!
  • 27. Akka persistence magic 1. No direct function calls or message passing between read and write side ! 2. Restart the application to see the automatic state recovery !! 3. Underneath, Akka plumbs the read and write side when they are on the same JVM to reduce round-trip and faster read side updates !!!
  • 28. Akka persistence magic 1. No direct function calls or message passing between read and write side ! 2. Restart the application to see the automatic state recovery !! 3. Underneath, Akka plumbs the read and write side when they are on the same JVM to reduce round-trip and faster read side updates !!! 4. Mix this with Akka clustering and a distributed journal to scale horizontally !!!!
  • 29. Akka Addendum • Akka Persistence View is deprecated and Persistence Query takes its place • Akka Persistence Actors (Write side) have to be cluster singletons • Just using Akka Clustering with Akka Persistence severely limits the possibilities since cluster singletons in clustering are always placed on the oldest node. To control actor placement within the cluster, use Akka Sharding • Different CQRS implementations with Akka: – ‘Eventsourced’ was the first CQRS project on Akka. It supported up to Akka 2.2.0. Akka persistence is influenced by it and was released in Akka 2.4.0. ‘Eventsourced’ is now legacy – ‘Eventuate’ is an alternative to Akka persistence. It seems to have more features than Akka persistence – Experimental
  • 30. How to design a system or app with ES and CQRS… ? • How to model Persistent Actors? How to model Persistent Query’s? • Designing commands and events and aggregates
  • 31. How to design a system or app with ES and CQRS… ? • How to model Persistent Actors? How to model Persistent Query’s? • Designing commands and events and aggregates • DDD  domain driven design – Eventual consistency – No distributed transactions – Many more…
  • 32. References • Akka Persistence Documentation • Greg Young: CQRS and Event Sourcing - https://www.youtube.com/watch?v=JHGkaShoyNs • Sander Mak: Event Sourced Architectures with Akka - https://www.youtube.com/watch?v=vFVry457XLk • Martin Krasser: Event Sourcing and CQRS with Akka Persistence and Eventuate - https://www.youtube.com/watch?v=vFVry457XLk

Editor's Notes

  1. Example of ticket sale. Command would be the sale which includes debit from a card. Event is a sale. On replay we don’t want the debit to happen again. So application needs to separate the part of sale that debits money to that of the selling of the ticket that will help restore application state