SlideShare a Scribd company logo
1 of 73
Download to read offline
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Akka persistence, CQRS/ES y otras
siglas del montón
Javier Santos
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
About us
Javier Santos @jpaniego
«Hay dos formas de programar sin
errores; sólo la tercera funciona»
Alan J Perlis
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
scalera.es
@scalerablog
About us
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem to solve
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem to solve
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem to solve
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
DDD - Domain Driven Design
● Context - The setting in which a word or statement appears that
determines its meaning
● Domain (Ontology) - The subject area to which the user applies a
program is the domain of the software
● Model - A system of abstractions that describes selected aspects of a
domain and can be used to solve problems related to that domain
● Ubiquitous language - A language structured around the domain model
and used by all team members to connect all the activities of the team
with the software
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
DDD - Domain Driven Design
● Context - The setting in which a word or statement appears that
determines its meaning
● Domain (Ontology) - The subject area to which the user applies a
program is the domain of the software
● Model - A system of abstractions that describes selected aspects of a
domain and can be used to solve problems related to that domain
● Ubiquitous language - A language structured around the domain model
and used by all team members to connect all the activities of the team
with the software
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
DDD - Domain Driven Design
● Context - The setting in which a word or statement appears that
determines its meaning
● Domain (Ontology) - The subject area to which the user applies a
program is the domain of the software
● Model - A system of abstractions that describes selected aspects of a
domain and can be used to solve problems related to that domain
● Ubiquitous language - A language structured around the domain model
and used by all team members to connect all the activities of the team
with the software
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Our domain model
case class User(
name: String,
address: Address,
credit: Double,
currentBike: Option[Id[Bike]])
case class Bike(
model: String,
battery: Bike.Battery.Status,
bikeStation: Option[Id[Station]])
case class Address(
street: String,
number: String,
zipCode: String)
case class Station(
address: Address,
maxBikeCapacity: Int,
currentCapacity: Int)
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Anemic Domain Model
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Anemic Domain Model
● Think about a domain class that only contains fields and no
methods.
● Anti-pattern against the main idea of the object-oriented
programming paradigm: combining data and process
together.
● Why not using C structs then? ¬¬
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Anemic Domain Model
case class User(
name: String,
address: Address,
credit: Double,
currentBike: Option[Id[Bike]]) {
def startRental(bike: Id[Bike]): User = {
require(
currentBike.isEmpty,"There's another rental on course.")
require(
credit > 0, "Not enough credit to start a rental.")
this.copy(currentBike = Some(bike))
}
//...
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Anemic Domain Model
//...
def finishRental(creditExpense: Double): User = {
require(
currentBike.isDefined, "There is not a rental on course.")
this.copy(
currentBike = None,
credit = credit - creditExpense)
}
}
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Aggregate
● Cluster of domain objects
● The whole block of domain objects works as a sole entity.
User Bike
Address
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Aggregate
trait Aggregate extends ...{
def id: Id[This]
}
case class Station(
address: Address,
maxBikeCapacity: Int,
currentCapacity: Int)
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Event Sourcing
● “Every change to the state of an application is captured in an event
object, and that these event objects are themselves stored in the
sequence they were applied for the same lifetime as the application state
itself” - Martin Fowler
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Event Sourcing
● The system state is the sum of the events
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Stateful[T]
trait Stateful[S] {
type This <: Stateful[S]
type Action = scalaz.State[S, Event]
val state: S
def apply(s: S): This
def update(f: Action): (This, E) = {
val (newState, e) = f(state)
(apply(newState), e)
}
}
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
scalaz.State
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
scalaz.State
● Represents a state mutation that may generate some effect.
● type State[S, Effect] = StateT[Id, S, Effect]
● Monad = composable!
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
scalaz.State
type Action[E] = scalaz.State[User, E]
def addCredit(amount: Double): Action[Double] =
State(user =>
(user.copy(credit = user.credit + amount), amount))
def rentBike(bike: Id[Bike], timesUsed: Long): Action[Long] =
State(user =>
(user.copy(currentBike = Some(bike), timesUsed + 1))
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
scalaz.State
val topUpAndRent: Action[(Double, Long)] =
for {
newCredit <- addCredit(10)
timesUsed <- rentBike(Id(“bike-1”))
} yield (newCredit, timesUsed)
val (relaxingAnn, (newCredit, bikeAge)) =
topUpAndRent(User(“Ann Bottle”, Addres(...), 0.0, None)
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Immutability perversion
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
StatefulAgg[T]
trait StateAgg[S] extends Stateful[S]{
_: PersistenActor =>
var aggState: S
def updateState(f: Action): Unit = {
val (newAgg, _) = update(f)
aggState = newAgg.state
}
}
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
StatefulAgg[T]
trait StateAgg[S] extends Stateful[S]{
_: PersistenActor =>
var aggState: S
def updateState(f: Action): Unit = {
val (newAgg, _) = update(f)
aggState = newAgg.state
}
}
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
CQRS
● Command Query Responsibility Segregation
● Main idea: “You can use a different model to update the
information than the model you use to read information”
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
CQRS
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
CQRS
trait Command[Agg] {
val to: Id[Agg]
}
trait Event
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Akka persistence
● End of 2013
● Martin Krasser
● Main idea : store the internal state of an actor
● ...BUT not directly, only through the changes the actor has
suffered.
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Akka persistence
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Akka persistence
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Akka persistence - Failure recovery
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Akka persistence - Failure recovery
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Akka persistence - Failure recovery
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Akka persistence - Failure recovery
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Snapshotting
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Snapshotting
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Persistent actors
trait PersistenceStuff extends PersistentActor{
def persistenceId: String
def receiveCommand: Receive
def receiveRecover: Receive
}
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
trait Reactive { _: Stateful[S] =>
val onEvent: Event => Action
val onSnapshot: Any => Action = {
case snapshot => State(s => (s, snapshot))
}
def asEvent(c: Command[This]): Event
}
Persistent actors
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
trait Aggregate[S] extends StateAgg[S] with Reactive with PersistentActor {
def persistenceId: String = id.id
def receiveRecover: Receive = {
case event: Event => update(onEvent(event))
case snapshot => update(onSnapshot(snapshot))
}
def receiveCommand: Receive = {
case cmd: Command[This@unchecked] =>
if (checkState(cmd))
persistAll(List(asEvent(cmd))){ event =>
update(onEvent(event))
sender ! event
}
else sender ! Nope
}
}
Persistent actors
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
case class UserAgg(state: User.Default) extends Aggregate[User] {
type This = UserAgg
def apply(s: User) = UserAgg(s)
override val onEvent = {
case e@AddedCredit(amount) =>
State(s => (s.copy(credit = s.credit+10),e))
}
def asEvent(c: Command[This]): Event = c match {
case AddCredit(_, amount) => AddedCredit(amount)
}
}
Persistent actors
boilerplate
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Persistence Queries
● Like a PersistentActor but with no Command part
● peristenceId subscription or by tag
● refreshInterval in most plugins
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Persistence Queries
val readJournal =
PersistenceQuery(system).readJournalFor[MyScaladslReadJournal](
"akka.persistence.query.my-read-journal")
// issue query to journal
val source: Source[EventEnvelope, NotUsed] =
readJournal.eventsByPersistenceId("user-1337")
// materialize stream, consuming events
implicit val mat = ActorMaterializer()
source.runForeach { event => println("Event: " + event) }
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
getOrCreate
● A new command is launched against user1...how to deliver it?
● Managers
class UserManager extends Actor {
override def receive = {
case cmd: Command[User@unchecked] =>
getOrCreate(cmd.addresse) forward cmd
}
}
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
getOrCreate
● Imagine there are 500k registered users …
● ...you create a persistent actor and deliver the just arrived
command…
● ...the actor keeps alive….
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
getOrCreate
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Passivation
● Kill the actor if it’s iddle…
trait Passivation extends PersistentActor {
import ShardRegion.Passivate
context.setReceiveTimeout(60.seconds)
override def receiveCommand = {
//…
case ReceiveTimeout =>
context.parent ! Passivate(stopMessage = Stop)
}
}
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Journal
● Different supported pluggable storages:
○ AndroidSQLite
○ BDB
○ Cassandra
○ Kafka
○ DynamoDB
○ HBase
○ MongoDB
○ …
● Why choosing a distributed database as Journal for High Availability?
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
HA : Clustering
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
HA : Clustering
● Send semantics
○ Send: The message is sent to an only cluster actor that fits in the
path. If several, the actor is chosen randomly.
clusterClient ! Send(«/user/handler», «hello»,
localAffinity = true)
○ SendToAll: The message is sent to all cluster actors that fit in the
path.
clusterClient ! SendToAll(«/user/handler», «hi»)
○ Publish: The message is sent to all topic subscribers
clusterClient ! Publish(«myTopic», «hello»)
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Partitioning : Sharding
● Study case:
○ A command is sent (in a cluster)
to aggregate1, the actor is
created in node1, the command is
processed.
○ A second command is sent (in the
same cluster) to aggregate1, but
this time the command is
received by node2, so the actor is
created there.
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Partitioning : Sharding
● It provides
○ Load balancing: In case a new is added to the cluster or
another one crashes, the total actor amount is balanced.
○ Unique actor identification, so messages that are sent to the
same actor will be forwarded to the node that handles in that
moment that shard id (previous case won’t take place)
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Partitioning : Sharding
● Semantics
○ Entry: It represents a uniquely identified entity with
persistent state (Aggregate).
○ Shard: Entry group. Experts recommend
ShardAmount = 10 x MaxNodeAmount
○ ShardRegion: Same Entry shard group.
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Partitioning : Sharding
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
#graciasCarmena
#llevameEnTuBiciceta
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem: eventual consistency
● Changes may take
some time
● If the user requires an
immediate update,
user views could be
updated when the
command part has
acknowledge the event
persistence (handle it
carefully...)
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem: Distributed transactions
● Let’s suppose credit transfer is allowed among users
● Saga Pattern: A persistent actor that represents a
transaction among aggregates
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem: Distributed transactions
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem: cluster initialization
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem: cluster initialization
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem: cluster initialization
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem: cluster initialization
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem: Testing a PersistentActor
TestActorRef + PersistentActor =
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem: Testing a PersistentActor
TestActorRef + PersistentActor =
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Problem : Schema evolution
● Imagine the following:
case class User(name: String, address: Address, amount: Double)
case class User(cardId: String, amount: Double, usualBike: Bike)
● Choosing proper serializers are the key (ProtoBuf, Avro, Java ser...no
way)
● Event migration (EventAdapter)
● How to:
○ add attribute
○ remove attribute
○ rename attribute
○ ...
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Lightbend approach
● Runs on JRE 1.8
● Multiple service control
● Event stream abstraction
● Easy scalability
● Java SDK ...
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Lightbend approach
● Runs on JRE 1.8
● Multiple service control
● Event stream abstraction
● Easy scalability
● Java SDK ...
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
scalera.es
@scalerablog
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
MADRID · NOV 18-19 · 2016
Scala Programming @ Madrid
Akka persistence, CQRS/ES y otras
siglas del montón
Javier Santos

More Related Content

What's hot

Collection advance
Collection advanceCollection advance
Collection advanceAakash Jain
 
Spark: Taming Big Data
Spark: Taming Big DataSpark: Taming Big Data
Spark: Taming Big DataLeonardo Gamas
 
Time Series With OrientDB - Fosdem 2015
Time Series With OrientDB - Fosdem 2015Time Series With OrientDB - Fosdem 2015
Time Series With OrientDB - Fosdem 2015wolf4ood
 
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...NETWAYS
 
A Tool For Big Data Analysis using Apache Spark
A Tool For Big Data Analysis using Apache SparkA Tool For Big Data Analysis using Apache Spark
A Tool For Big Data Analysis using Apache Sparkdatamantra
 
Geospatial Graphs made easy with OrientDB - Codemotion Spain
Geospatial Graphs made easy with OrientDB - Codemotion SpainGeospatial Graphs made easy with OrientDB - Codemotion Spain
Geospatial Graphs made easy with OrientDB - Codemotion SpainLuigi Dell'Aquila
 
GeeCON Prague 2016 - Geospatial Graphs made easy with OrientDB
GeeCON Prague 2016 - Geospatial Graphs made easy with OrientDBGeeCON Prague 2016 - Geospatial Graphs made easy with OrientDB
GeeCON Prague 2016 - Geospatial Graphs made easy with OrientDBLuigi Dell'Aquila
 
Introduction to dataset
Introduction to datasetIntroduction to dataset
Introduction to datasetdatamantra
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwiftOleksandr Stepanov
 
Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016
Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016
Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016Luigi Dell'Aquila
 
Laskar: High-Velocity GraphQL & Lambda-based Software Development Model
Laskar: High-Velocity GraphQL & Lambda-based Software Development ModelLaskar: High-Velocity GraphQL & Lambda-based Software Development Model
Laskar: High-Velocity GraphQL & Lambda-based Software Development ModelGarindra Prahandono
 
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)Andrew Rota
 
Extending Spark for Qbeast's SQL Data Source​ with Paola Pardo and Cesare Cug...
Extending Spark for Qbeast's SQL Data Source​ with Paola Pardo and Cesare Cug...Extending Spark for Qbeast's SQL Data Source​ with Paola Pardo and Cesare Cug...
Extending Spark for Qbeast's SQL Data Source​ with Paola Pardo and Cesare Cug...Qbeast
 

What's hot (17)

Collection advance
Collection advanceCollection advance
Collection advance
 
Spark: Taming Big Data
Spark: Taming Big DataSpark: Taming Big Data
Spark: Taming Big Data
 
Time Series With OrientDB - Fosdem 2015
Time Series With OrientDB - Fosdem 2015Time Series With OrientDB - Fosdem 2015
Time Series With OrientDB - Fosdem 2015
 
Chapter03b
Chapter03bChapter03b
Chapter03b
 
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
OSDC 2016 - Chronix - A fast and efficient time series storage based on Apach...
 
A Tool For Big Data Analysis using Apache Spark
A Tool For Big Data Analysis using Apache SparkA Tool For Big Data Analysis using Apache Spark
A Tool For Big Data Analysis using Apache Spark
 
Geospatial Graphs made easy with OrientDB - Codemotion Spain
Geospatial Graphs made easy with OrientDB - Codemotion SpainGeospatial Graphs made easy with OrientDB - Codemotion Spain
Geospatial Graphs made easy with OrientDB - Codemotion Spain
 
GeeCON Prague 2016 - Geospatial Graphs made easy with OrientDB
GeeCON Prague 2016 - Geospatial Graphs made easy with OrientDBGeeCON Prague 2016 - Geospatial Graphs made easy with OrientDB
GeeCON Prague 2016 - Geospatial Graphs made easy with OrientDB
 
Introduction to dataset
Introduction to datasetIntroduction to dataset
Introduction to dataset
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwift
 
Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016
Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016
Geospatial Graphs made easy with OrientDB - Codemotion Milan 2016
 
Laskar: High-Velocity GraphQL & Lambda-based Software Development Model
Laskar: High-Velocity GraphQL & Lambda-based Software Development ModelLaskar: High-Velocity GraphQL & Lambda-based Software Development Model
Laskar: High-Velocity GraphQL & Lambda-based Software Development Model
 
Scheme 核心概念(一)
Scheme 核心概念(一)Scheme 核心概念(一)
Scheme 核心概念(一)
 
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
 
Extending Spark for Qbeast's SQL Data Source​ with Paola Pardo and Cesare Cug...
Extending Spark for Qbeast's SQL Data Source​ with Paola Pardo and Cesare Cug...Extending Spark for Qbeast's SQL Data Source​ with Paola Pardo and Cesare Cug...
Extending Spark for Qbeast's SQL Data Source​ with Paola Pardo and Cesare Cug...
 
RxJava in practice
RxJava in practice RxJava in practice
RxJava in practice
 
Cassandra for impatients
Cassandra for impatientsCassandra for impatients
Cassandra for impatients
 

Viewers also liked

Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015
Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015
Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015Yanik Berube
 
Akka persistence webinar
Akka persistence webinarAkka persistence webinar
Akka persistence webinarpatriknw
 
Akka Persistence | Event Sourcing
Akka Persistence | Event SourcingAkka Persistence | Event Sourcing
Akka Persistence | Event SourcingKnoldus Inc.
 
Reactive programming with scala and akka
Reactive programming with scala and akkaReactive programming with scala and akka
Reactive programming with scala and akkaKnoldus Inc.
 
Event Sourcing using Akka on AWS
Event Sourcing using Akka on AWSEvent Sourcing using Akka on AWS
Event Sourcing using Akka on AWSDaniel Pfeiffer
 
CQRS+ESをAkka Persistenceを使って実装してみる。
CQRS+ESをAkka Persistenceを使って実装してみる。CQRS+ESをAkka Persistenceを使って実装してみる。
CQRS+ESをAkka Persistenceを使って実装してみる。Matsushita Satoshi
 
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]Johan Janssen
 
Akka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with ScalaAkka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with ScalaJerry Kuru
 
DDDing Tools = Akka Persistence
DDDing Tools = Akka PersistenceDDDing Tools = Akka Persistence
DDDing Tools = Akka PersistenceKonrad Malawski
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneKonrad Malawski
 
Akka Persistence and Eventuate
Akka Persistence and EventuateAkka Persistence and Eventuate
Akka Persistence and EventuateMartin Krasser
 
spray: REST on Akka (Scala Days)
spray: REST on Akka (Scala Days)spray: REST on Akka (Scala Days)
spray: REST on Akka (Scala Days)sirthias
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Konrad Malawski
 

Viewers also liked (20)

Event-sourced architectures with Akka
Event-sourced architectures with AkkaEvent-sourced architectures with Akka
Event-sourced architectures with Akka
 
scalaphx-akka-http
scalaphx-akka-httpscalaphx-akka-http
scalaphx-akka-http
 
Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015
Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015
Scala + Akka + ning/async-http-client - Vancouver Scala meetup February 2015
 
Akka persistence webinar
Akka persistence webinarAkka persistence webinar
Akka persistence webinar
 
Akka Persistence | Event Sourcing
Akka Persistence | Event SourcingAkka Persistence | Event Sourcing
Akka Persistence | Event Sourcing
 
Reactive programming with scala and akka
Reactive programming with scala and akkaReactive programming with scala and akka
Reactive programming with scala and akka
 
Akka Streams
Akka StreamsAkka Streams
Akka Streams
 
Event Sourcing using Akka on AWS
Event Sourcing using Akka on AWSEvent Sourcing using Akka on AWS
Event Sourcing using Akka on AWS
 
Akka-http
Akka-httpAkka-http
Akka-http
 
CQRS+ESをAkka Persistenceを使って実装してみる。
CQRS+ESをAkka Persistenceを使って実装してみる。CQRS+ESをAkka Persistenceを使って実装してみる。
CQRS+ESをAkka Persistenceを使って実装してみる。
 
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
 
Akka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with ScalaAkka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with Scala
 
Arquitectura Lambda
Arquitectura LambdaArquitectura Lambda
Arquitectura Lambda
 
DDDing Tools = Akka Persistence
DDDing Tools = Akka PersistenceDDDing Tools = Akka Persistence
DDDing Tools = Akka Persistence
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
 
Akka http 2
Akka http 2Akka http 2
Akka http 2
 
Akka http
Akka httpAkka http
Akka http
 
Akka Persistence and Eventuate
Akka Persistence and EventuateAkka Persistence and Eventuate
Akka Persistence and Eventuate
 
spray: REST on Akka (Scala Days)
spray: REST on Akka (Scala Days)spray: REST on Akka (Scala Days)
spray: REST on Akka (Scala Days)
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
 

Similar to Codemotion akka persistence, cqrs%2 fes y otras siglas del montón

Estructurar y mantener aplicaciones Rails sin morir en el intento
Estructurar y mantener aplicaciones Rails sin morir en el intentoEstructurar y mantener aplicaciones Rails sin morir en el intento
Estructurar y mantener aplicaciones Rails sin morir en el intentoMoisés Maciá
 
Mongo db improve the performance of your application codemotion2016
Mongo db improve the performance of your application codemotion2016Mongo db improve the performance of your application codemotion2016
Mongo db improve the performance of your application codemotion2016Juan Antonio Roy Couto
 
Codemotion 2015 - Akka voló sobre el nido del future
Codemotion 2015 - Akka voló sobre el nido del futureCodemotion 2015 - Akka voló sobre el nido del future
Codemotion 2015 - Akka voló sobre el nido del futurescalerablog
 
SF Big Analytics 20191112: How to performance-tune Spark applications in larg...
SF Big Analytics 20191112: How to performance-tune Spark applications in larg...SF Big Analytics 20191112: How to performance-tune Spark applications in larg...
SF Big Analytics 20191112: How to performance-tune Spark applications in larg...Chester Chen
 
How to separate frontend from a highload python project with no problems - Py...
How to separate frontend from a highload python project with no problems - Py...How to separate frontend from a highload python project with no problems - Py...
How to separate frontend from a highload python project with no problems - Py...Oleksandr Tarasenko
 
Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...
Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...
Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...Anton Kirillov
 
Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021Taro L. Saito
 
VSSML18. Introduction to WhizzML
VSSML18. Introduction to WhizzMLVSSML18. Introduction to WhizzML
VSSML18. Introduction to WhizzMLBigML, Inc
 
Using spark 1.2 with Java 8 and Cassandra
Using spark 1.2 with Java 8 and CassandraUsing spark 1.2 with Java 8 and Cassandra
Using spark 1.2 with Java 8 and CassandraDenis Dus
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data scienceSovello Hildebrand
 
Code-first GraphQL Server Development with Prisma
Code-first  GraphQL Server Development with PrismaCode-first  GraphQL Server Development with Prisma
Code-first GraphQL Server Development with PrismaNikolas Burk
 
Ch 7: Object-Oriented JavaScript
Ch 7: Object-Oriented JavaScriptCh 7: Object-Oriented JavaScript
Ch 7: Object-Oriented JavaScriptdcomfort6819
 
R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?Villu Ruusmann
 
Mobility insights at Swisscom - Understanding collective mobility in Switzerland
Mobility insights at Swisscom - Understanding collective mobility in SwitzerlandMobility insights at Swisscom - Understanding collective mobility in Switzerland
Mobility insights at Swisscom - Understanding collective mobility in SwitzerlandFrançois Garillot
 
Spark Summit EU talk by Francois Garillot and Mohamed Kafsi
Spark Summit EU talk by Francois Garillot and Mohamed KafsiSpark Summit EU talk by Francois Garillot and Mohamed Kafsi
Spark Summit EU talk by Francois Garillot and Mohamed KafsiSpark Summit
 
Reactive app using actor model & apache spark
Reactive app using actor model & apache sparkReactive app using actor model & apache spark
Reactive app using actor model & apache sparkRahul Kumar
 
Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?Erik-Berndt Scheper
 
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or ServerlessYour API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or ServerlessQAware GmbH
 

Similar to Codemotion akka persistence, cqrs%2 fes y otras siglas del montón (20)

Estructurar y mantener aplicaciones Rails sin morir en el intento
Estructurar y mantener aplicaciones Rails sin morir en el intentoEstructurar y mantener aplicaciones Rails sin morir en el intento
Estructurar y mantener aplicaciones Rails sin morir en el intento
 
Mongo db improve the performance of your application codemotion2016
Mongo db improve the performance of your application codemotion2016Mongo db improve the performance of your application codemotion2016
Mongo db improve the performance of your application codemotion2016
 
Codemotion 2015 - Akka voló sobre el nido del future
Codemotion 2015 - Akka voló sobre el nido del futureCodemotion 2015 - Akka voló sobre el nido del future
Codemotion 2015 - Akka voló sobre el nido del future
 
SF Big Analytics 20191112: How to performance-tune Spark applications in larg...
SF Big Analytics 20191112: How to performance-tune Spark applications in larg...SF Big Analytics 20191112: How to performance-tune Spark applications in larg...
SF Big Analytics 20191112: How to performance-tune Spark applications in larg...
 
How to separate frontend from a highload python project with no problems - Py...
How to separate frontend from a highload python project with no problems - Py...How to separate frontend from a highload python project with no problems - Py...
How to separate frontend from a highload python project with no problems - Py...
 
Scala for dummies
Scala for dummiesScala for dummies
Scala for dummies
 
Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...
Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...
Data processing platforms architectures with Spark, Mesos, Akka, Cassandra an...
 
Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021
 
VSSML18. Introduction to WhizzML
VSSML18. Introduction to WhizzMLVSSML18. Introduction to WhizzML
VSSML18. Introduction to WhizzML
 
Using spark 1.2 with Java 8 and Cassandra
Using spark 1.2 with Java 8 and CassandraUsing spark 1.2 with Java 8 and Cassandra
Using spark 1.2 with Java 8 and Cassandra
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data science
 
Code-first GraphQL Server Development with Prisma
Code-first  GraphQL Server Development with PrismaCode-first  GraphQL Server Development with Prisma
Code-first GraphQL Server Development with Prisma
 
Ch 7: Object-Oriented JavaScript
Ch 7: Object-Oriented JavaScriptCh 7: Object-Oriented JavaScript
Ch 7: Object-Oriented JavaScript
 
R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?
 
Mobility insights at Swisscom - Understanding collective mobility in Switzerland
Mobility insights at Swisscom - Understanding collective mobility in SwitzerlandMobility insights at Swisscom - Understanding collective mobility in Switzerland
Mobility insights at Swisscom - Understanding collective mobility in Switzerland
 
Spark Summit EU talk by Francois Garillot and Mohamed Kafsi
Spark Summit EU talk by Francois Garillot and Mohamed KafsiSpark Summit EU talk by Francois Garillot and Mohamed Kafsi
Spark Summit EU talk by Francois Garillot and Mohamed Kafsi
 
Reactive app using actor model & apache spark
Reactive app using actor model & apache sparkReactive app using actor model & apache spark
Reactive app using actor model & apache spark
 
Spark training-in-bangalore
Spark training-in-bangaloreSpark training-in-bangalore
Spark training-in-bangalore
 
Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?
 
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or ServerlessYour API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
 

Recently uploaded

UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 

Recently uploaded (20)

UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 

Codemotion akka persistence, cqrs%2 fes y otras siglas del montón

  • 1. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Akka persistence, CQRS/ES y otras siglas del montón Javier Santos
  • 2. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid About us Javier Santos @jpaniego «Hay dos formas de programar sin errores; sólo la tercera funciona» Alan J Perlis
  • 3. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid scalera.es @scalerablog About us
  • 4. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem to solve
  • 5. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem to solve
  • 6. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem to solve
  • 7. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid DDD - Domain Driven Design ● Context - The setting in which a word or statement appears that determines its meaning ● Domain (Ontology) - The subject area to which the user applies a program is the domain of the software ● Model - A system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain ● Ubiquitous language - A language structured around the domain model and used by all team members to connect all the activities of the team with the software
  • 8. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid DDD - Domain Driven Design ● Context - The setting in which a word or statement appears that determines its meaning ● Domain (Ontology) - The subject area to which the user applies a program is the domain of the software ● Model - A system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain ● Ubiquitous language - A language structured around the domain model and used by all team members to connect all the activities of the team with the software
  • 9. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid DDD - Domain Driven Design ● Context - The setting in which a word or statement appears that determines its meaning ● Domain (Ontology) - The subject area to which the user applies a program is the domain of the software ● Model - A system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain ● Ubiquitous language - A language structured around the domain model and used by all team members to connect all the activities of the team with the software
  • 10. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Our domain model case class User( name: String, address: Address, credit: Double, currentBike: Option[Id[Bike]]) case class Bike( model: String, battery: Bike.Battery.Status, bikeStation: Option[Id[Station]]) case class Address( street: String, number: String, zipCode: String) case class Station( address: Address, maxBikeCapacity: Int, currentCapacity: Int)
  • 11. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Anemic Domain Model
  • 12. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Anemic Domain Model ● Think about a domain class that only contains fields and no methods. ● Anti-pattern against the main idea of the object-oriented programming paradigm: combining data and process together. ● Why not using C structs then? ¬¬
  • 13. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Anemic Domain Model case class User( name: String, address: Address, credit: Double, currentBike: Option[Id[Bike]]) { def startRental(bike: Id[Bike]): User = { require( currentBike.isEmpty,"There's another rental on course.") require( credit > 0, "Not enough credit to start a rental.") this.copy(currentBike = Some(bike)) } //...
  • 14. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Anemic Domain Model //... def finishRental(creditExpense: Double): User = { require( currentBike.isDefined, "There is not a rental on course.") this.copy( currentBike = None, credit = credit - creditExpense) } }
  • 15. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Aggregate ● Cluster of domain objects ● The whole block of domain objects works as a sole entity. User Bike Address
  • 16. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Aggregate trait Aggregate extends ...{ def id: Id[This] } case class Station( address: Address, maxBikeCapacity: Int, currentCapacity: Int)
  • 17. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Event Sourcing ● “Every change to the state of an application is captured in an event object, and that these event objects are themselves stored in the sequence they were applied for the same lifetime as the application state itself” - Martin Fowler
  • 18. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Event Sourcing ● The system state is the sum of the events
  • 19. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Stateful[T] trait Stateful[S] { type This <: Stateful[S] type Action = scalaz.State[S, Event] val state: S def apply(s: S): This def update(f: Action): (This, E) = { val (newState, e) = f(state) (apply(newState), e) } }
  • 20. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid scalaz.State
  • 21. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid scalaz.State ● Represents a state mutation that may generate some effect. ● type State[S, Effect] = StateT[Id, S, Effect] ● Monad = composable!
  • 22. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid scalaz.State type Action[E] = scalaz.State[User, E] def addCredit(amount: Double): Action[Double] = State(user => (user.copy(credit = user.credit + amount), amount)) def rentBike(bike: Id[Bike], timesUsed: Long): Action[Long] = State(user => (user.copy(currentBike = Some(bike), timesUsed + 1))
  • 23. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid scalaz.State val topUpAndRent: Action[(Double, Long)] = for { newCredit <- addCredit(10) timesUsed <- rentBike(Id(“bike-1”)) } yield (newCredit, timesUsed) val (relaxingAnn, (newCredit, bikeAge)) = topUpAndRent(User(“Ann Bottle”, Addres(...), 0.0, None)
  • 24. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Immutability perversion
  • 25. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid StatefulAgg[T] trait StateAgg[S] extends Stateful[S]{ _: PersistenActor => var aggState: S def updateState(f: Action): Unit = { val (newAgg, _) = update(f) aggState = newAgg.state } }
  • 26. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid StatefulAgg[T] trait StateAgg[S] extends Stateful[S]{ _: PersistenActor => var aggState: S def updateState(f: Action): Unit = { val (newAgg, _) = update(f) aggState = newAgg.state } }
  • 27. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid
  • 28. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid CQRS ● Command Query Responsibility Segregation ● Main idea: “You can use a different model to update the information than the model you use to read information”
  • 29. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid CQRS
  • 30. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid CQRS trait Command[Agg] { val to: Id[Agg] } trait Event
  • 31. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Akka persistence ● End of 2013 ● Martin Krasser ● Main idea : store the internal state of an actor ● ...BUT not directly, only through the changes the actor has suffered.
  • 32. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Akka persistence
  • 33. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Akka persistence
  • 34. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Akka persistence - Failure recovery
  • 35. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Akka persistence - Failure recovery
  • 36. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Akka persistence - Failure recovery
  • 37. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Akka persistence - Failure recovery
  • 38. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Snapshotting
  • 39. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Snapshotting
  • 40. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Persistent actors trait PersistenceStuff extends PersistentActor{ def persistenceId: String def receiveCommand: Receive def receiveRecover: Receive }
  • 41. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid trait Reactive { _: Stateful[S] => val onEvent: Event => Action val onSnapshot: Any => Action = { case snapshot => State(s => (s, snapshot)) } def asEvent(c: Command[This]): Event } Persistent actors
  • 42. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid trait Aggregate[S] extends StateAgg[S] with Reactive with PersistentActor { def persistenceId: String = id.id def receiveRecover: Receive = { case event: Event => update(onEvent(event)) case snapshot => update(onSnapshot(snapshot)) } def receiveCommand: Receive = { case cmd: Command[This@unchecked] => if (checkState(cmd)) persistAll(List(asEvent(cmd))){ event => update(onEvent(event)) sender ! event } else sender ! Nope } } Persistent actors
  • 43. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid case class UserAgg(state: User.Default) extends Aggregate[User] { type This = UserAgg def apply(s: User) = UserAgg(s) override val onEvent = { case e@AddedCredit(amount) => State(s => (s.copy(credit = s.credit+10),e)) } def asEvent(c: Command[This]): Event = c match { case AddCredit(_, amount) => AddedCredit(amount) } } Persistent actors boilerplate
  • 44. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Persistence Queries ● Like a PersistentActor but with no Command part ● peristenceId subscription or by tag ● refreshInterval in most plugins
  • 45. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Persistence Queries val readJournal = PersistenceQuery(system).readJournalFor[MyScaladslReadJournal]( "akka.persistence.query.my-read-journal") // issue query to journal val source: Source[EventEnvelope, NotUsed] = readJournal.eventsByPersistenceId("user-1337") // materialize stream, consuming events implicit val mat = ActorMaterializer() source.runForeach { event => println("Event: " + event) }
  • 46. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid getOrCreate ● A new command is launched against user1...how to deliver it? ● Managers class UserManager extends Actor { override def receive = { case cmd: Command[User@unchecked] => getOrCreate(cmd.addresse) forward cmd } }
  • 47. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid getOrCreate ● Imagine there are 500k registered users … ● ...you create a persistent actor and deliver the just arrived command… ● ...the actor keeps alive….
  • 48. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid getOrCreate
  • 49. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Passivation ● Kill the actor if it’s iddle… trait Passivation extends PersistentActor { import ShardRegion.Passivate context.setReceiveTimeout(60.seconds) override def receiveCommand = { //… case ReceiveTimeout => context.parent ! Passivate(stopMessage = Stop) } }
  • 50. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid
  • 51. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Journal ● Different supported pluggable storages: ○ AndroidSQLite ○ BDB ○ Cassandra ○ Kafka ○ DynamoDB ○ HBase ○ MongoDB ○ … ● Why choosing a distributed database as Journal for High Availability?
  • 52. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid HA : Clustering
  • 53. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid HA : Clustering ● Send semantics ○ Send: The message is sent to an only cluster actor that fits in the path. If several, the actor is chosen randomly. clusterClient ! Send(«/user/handler», «hello», localAffinity = true) ○ SendToAll: The message is sent to all cluster actors that fit in the path. clusterClient ! SendToAll(«/user/handler», «hi») ○ Publish: The message is sent to all topic subscribers clusterClient ! Publish(«myTopic», «hello»)
  • 54. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Partitioning : Sharding ● Study case: ○ A command is sent (in a cluster) to aggregate1, the actor is created in node1, the command is processed. ○ A second command is sent (in the same cluster) to aggregate1, but this time the command is received by node2, so the actor is created there.
  • 55. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Partitioning : Sharding ● It provides ○ Load balancing: In case a new is added to the cluster or another one crashes, the total actor amount is balanced. ○ Unique actor identification, so messages that are sent to the same actor will be forwarded to the node that handles in that moment that shard id (previous case won’t take place)
  • 56. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Partitioning : Sharding ● Semantics ○ Entry: It represents a uniquely identified entity with persistent state (Aggregate). ○ Shard: Entry group. Experts recommend ShardAmount = 10 x MaxNodeAmount ○ ShardRegion: Same Entry shard group.
  • 57. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Partitioning : Sharding
  • 58. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid #graciasCarmena #llevameEnTuBiciceta
  • 59. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem: eventual consistency ● Changes may take some time ● If the user requires an immediate update, user views could be updated when the command part has acknowledge the event persistence (handle it carefully...)
  • 60. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem: Distributed transactions ● Let’s suppose credit transfer is allowed among users ● Saga Pattern: A persistent actor that represents a transaction among aggregates
  • 61. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem: Distributed transactions
  • 62. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem: cluster initialization
  • 63. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem: cluster initialization
  • 64. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem: cluster initialization
  • 65. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem: cluster initialization
  • 66. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem: Testing a PersistentActor TestActorRef + PersistentActor =
  • 67. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem: Testing a PersistentActor TestActorRef + PersistentActor =
  • 68. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Problem : Schema evolution ● Imagine the following: case class User(name: String, address: Address, amount: Double) case class User(cardId: String, amount: Double, usualBike: Bike) ● Choosing proper serializers are the key (ProtoBuf, Avro, Java ser...no way) ● Event migration (EventAdapter) ● How to: ○ add attribute ○ remove attribute ○ rename attribute ○ ...
  • 69. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Lightbend approach ● Runs on JRE 1.8 ● Multiple service control ● Event stream abstraction ● Easy scalability ● Java SDK ...
  • 70. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Lightbend approach ● Runs on JRE 1.8 ● Multiple service control ● Event stream abstraction ● Easy scalability ● Java SDK ...
  • 71. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid scalera.es @scalerablog
  • 72. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid
  • 73. MADRID · NOV 18-19 · 2016 Scala Programming @ Madrid Akka persistence, CQRS/ES y otras siglas del montón Javier Santos