SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Downloaden Sie, um offline zu lesen
EVENT‐DRIVEN‐
ARCHITECTURE ON
AWS USING AKKA
Software Engineer @firstbird
Contact me: @pfeiffer_d_
DANIEL PFEIFFER
THE JOURNEY OF EVENTS
that are stored with Akka Persistence
to be then distributed via AWS
to be consumed with Akka Stream
what comes after that
THE EXAMPLE
DOMAIN DRIVEN DESIGN
We are talking about Aggregates and Events
EVENT SOURCING
"Capture all changes to an application
state as a sequence of events" -
Martin Fowler, 2005
CQRS
"Asking a question should not change
the answer." - Bertrand Meyer, 2012
THE DIFFERENCE
PERSISTENTACTOR
class TimeEntryAggregate(id: String) extends PersistentActor{
override def persistenceId: String = ???
override def receiveCommand: Receive = ???
override def receiveRecover: Receive = ???
}
A PersistentActorclass represents one DDD
aggregate.
class TimeEntryAggregate(id: String) extends PersistentActor{
...
override def persistenceId: String = s"time-entry-$id"
...
}
A PersistentActorreceives commands and
persists events.
case class CreateTimeEntry(
begin: DateTime,
end: DateTime
)
case class TimeEntryCreated(
begin: DateTime,
end: DateTime,
sequenceNr: Long
)
A PersistentActorreceives commands and
persists events.
class TimeEntryAggregate(id: String) extends PersistentActor{
...
override def receiveCommand: Receive =
case CreateTimeEntry(start, end) =>
val event = TimeEntryCreated(start,end, lastSequenceNr + 1)
persist(event){e =>
// update internal state
// here we go after the event is persisted
}
}
...
}
A PersistentActorrecovers from the journal
class TimeEntryAggregate(id: String) extends PersistentActor{
...
override def receiveRecover: Receive = {
case TimeEntryCreated(start,end) => // update internal state
}
...
}
STORING EVENTS TO A JOURNAL
IS NICE, BUT ...
others may be as well interested, so we have to
distribute them.
WITHIN ONE JVM WE COULD...
use Akka EventStreamto publish events ...
class TimeEntryActor() extends PersistentActor{
...
persist(event){e =>
context.system.eventStream.publish(e)
}
...
}
... and subscribe from interested actors
class EventConsumer extends Actor{
override def preStart: Unit = {
context.system.eventStream.subscribe(classOf[TimeEntryActor.TimeEntry
}
override def receive: Receive = {
case e: TimeEntryCreated => //do something with that event
}
}
HOW DO I INTERACT WITH MY
AGGREGATES?
DON'T CALL ME! CALL MY
OFFICE!
EXAMPLE 1
BUT WE WANT TO BE COOL
DISTRIBUTED SYSTEMS ARE
HARD
WE WANT TO MAKE THEM
EASIER
INTRODUCE A MESSAGE
BROKER, PUB/SUB ...
THE EXAMPLE ON
AWS STEROIDS
TIME ENTRY SERVICE
EMAIL SERVICE
SQS FLOW
SqsSource(...)
.map(msg => Envelope(msg.receiptHandle, msg.body))
.via(unmarshal())
.via(process())
.runWith(ack(...))
SQS MESSAGE
{
"messageId" : "",
"receiptHandle" : "",
"md5OfBody" : "",
"body" : ""
}
SNS NOTIFICATION ENVELOPE
{
"Type" : "Notification",
"MessageId" : "",
"TopicArn" : "",
"Subject" : "time_entry.approved",
"Message" : "",
"Timestamp" : "",
"SignatureVersion" : "",
"Signature" : "",
"SigningCertURL" : "",
"UnsubscribeURL" : ""
}
CHALLENGES
EVENT SCHEMA EVOLUTION
adding a field to an event type,
remove or rename field in event type,
remove event type,
split event into multiple smaller events.
case class TimeEntryCreated(
id: UUID,
begin: DateTime,
end: DateTime,
timeEntryUserId: UUID,
userId: UUID
)
gets marshalled to
{
"id" : "123456",
"begin" : "2016-09-01 12:00:00",
"end" : "2016-09-01 12:15:00",
"timeEntryUserId" : "00000000-0000-0000-0000-000000000000",
"userId" : "00000000-0000-0000-0000-000000000000"
}
Then something within our schema changes
case class TimeEntryCreated(
...
description: String
...
)
and we will have fun with that one
{
"id" : "123456",
"begin" : "2016-09-01 12:00:00",
"end" : "2016-09-01 12:15:00",
"timeEntryUserId" : "00000000-0000-0000-0000-000000000000",
"userId" : "00000000-0000-0000-0000-000000000000"
}
{
"id" : "123456",
"begin" : "2016-09-01 12:00:00",
"end" : "2016-09-01 12:15:00",
"timeEntryUserId" : "00000000-0000-0000-0000-000000000000",
"userId" : "00000000-0000-0000-0000-000000000000"
}
needs to be transformed to that
{
"id" : "123456",
"begin" : "2016-09-01 12:00:00",
"end" : "2016-09-01 12:15:00",
"timeEntryUserId" : "00000000-0000-0000-0000-000000000000",
"userId" : "00000000-0000-0000-0000-000000000000",
"description" : "N/A"
}
class Evolution(system: ExtendedActorSystem) extends EventAdapter{}
override def fromJournal(event: Any, manifest: String): EventSeq = {
val es = ... //doing evolution on event
EventSeq(es)
}
override def manifest(event: Any): String = {
val version = ???
event.getClass.getSimpleName + ":" + version
}
override def toJournal(event: Any): Any = ???
//write to the journal
}
SCALING WITH AKKA CLUSTER
ON AWS
or "Who am I, and where are all the others?"
JOINING A CLUSTER
gives you information about your instance
http://169.254.169.254/latest/meta-data/instance-id
PRESERVING MESSAGE ORDER
The query side could look like that
| id | ... | version |
| --- | --- | ------- |
| 1 | ... | 45 |
| 2 | ... | 3 |
| 3 | ... | 58 |
CHOOSING THE RIGHT
DATASTORE
you will make mistakes so plan for it
ASYNCHRONOUS MEANS NOT
IMMEDIATE
WHY DO WE REALLY WANT TO
DO THAT?
WE WANT TO SLEEP BETTER
WE WANT TO GET RID OF OUR
MONOLITH
OUR DEVELOPMENT PROCESS BENEFITS
WE CAN ALWAYS AGGREGATE OUR
EVENTS
IF SOMEONE STARTS TO ASK
QUESTIONS...
An audit log is included in your application for free!
SUMMARY
THE FIRST PROTOTYPE IS EASY BUT TO
TACKLE THE CHALLENGES NEEDS
EFFORT!
CONFIGURE YOUR SQS QUEUES
PROPERLY
LET EACH SERVICE MANAGE IT'S
RESOURCES ITSELF.
ONE TOPIC PER AGGREGATE
LITERATURE
https://www.infoq.com/articles/AmazonPubSub
http://martinfowler.com/eaaDev/EventCollaboration.html
http://martinfowler.com/bliki/CQRS.html
https://github.com/dpfeiffer/event-sourcing-aws-
akka-showcase
http://www.oreilly.com/programming/free/reactive-
microservices-architecture.html
http://doc.akka.io/docs/akka/snapshot/scala/persistence-
schema-evolution.html#persistence-schema-
evolution-scala http://chrisloy.net/2014/05/11/akka-
cluster-ec2-autoscaling.html

Weitere ähnliche Inhalte

Andere mochten auch

Akka persistence webinar
Akka persistence webinarAkka persistence webinar
Akka persistence webinar
patriknw
 
Akka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with ScalaAkka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with Scala
Jerry Kuru
 

Andere mochten auch (20)

Dependency Injection in Scala - Beyond the Cake Pattern
Dependency Injection in Scala - Beyond the Cake PatternDependency Injection in Scala - Beyond the Cake Pattern
Dependency Injection in Scala - Beyond the Cake Pattern
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
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
 
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion   akka persistence, cqrs%2 fes y otras siglas del montónCodemotion   akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
 
Reactive programming with scala and akka
Reactive programming with scala and akkaReactive programming with scala and akka
Reactive programming with scala and akka
 
Akka Persistence | Event Sourcing
Akka Persistence | Event SourcingAkka Persistence | Event Sourcing
Akka Persistence | Event Sourcing
 
CQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETCQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NET
 
Akka Streams
Akka StreamsAkka Streams
Akka Streams
 
Messaging in the AWS Cloud
Messaging in the AWS CloudMessaging in the AWS Cloud
Messaging in the AWS Cloud
 
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20....Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
 
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
 
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
 

Ähnlich wie Event Sourcing using Akka on AWS

Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-cas
ellentuck
 

Ähnlich wie Event Sourcing using Akka on AWS (20)

TSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech TalkTSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech Talk
 
Tsar tech talk
Tsar tech talkTsar tech talk
Tsar tech talk
 
Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...
 
以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界
 
Event Sourcing on AWS Using Akka in Java
Event Sourcing on AWS Using Akka in JavaEvent Sourcing on AWS Using Akka in Java
Event Sourcing on AWS Using Akka in Java
 
DDD meets CQRS and event sourcing
DDD meets CQRS and event sourcingDDD meets CQRS and event sourcing
DDD meets CQRS and event sourcing
 
Big Data Tools in AWS
Big Data Tools in AWSBig Data Tools in AWS
Big Data Tools in AWS
 
Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
AWS re:Invent 2016: Automating Security Event Response, from Idea to Code to ...
AWS re:Invent 2016: Automating Security Event Response, from Idea to Code to ...AWS re:Invent 2016: Automating Security Event Response, from Idea to Code to ...
AWS re:Invent 2016: Automating Security Event Response, from Idea to Code to ...
 
Raquel Guimaraes- Third party infrastructure as code
Raquel Guimaraes-  Third party infrastructure as codeRaquel Guimaraes-  Third party infrastructure as code
Raquel Guimaraes- Third party infrastructure as code
 
What Is Happening At The Edge
What Is Happening At The EdgeWhat Is Happening At The Edge
What Is Happening At The Edge
 
Demystifying Event-Driven Architectures with Apache Kafka | Bogdan Sucaciu, P...
Demystifying Event-Driven Architectures with Apache Kafka | Bogdan Sucaciu, P...Demystifying Event-Driven Architectures with Apache Kafka | Bogdan Sucaciu, P...
Demystifying Event-Driven Architectures with Apache Kafka | Bogdan Sucaciu, P...
 
Ceilometer + Heat = Alarming
Ceilometer + Heat = Alarming Ceilometer + Heat = Alarming
Ceilometer + Heat = Alarming
 
Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-cas
 
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...
 
Rule Language for IoT
Rule Language for IoTRule Language for IoT
Rule Language for IoT
 
Serverless
ServerlessServerless
Serverless
 
Developing microservices with aggregates (melbourne)
Developing microservices with aggregates (melbourne)Developing microservices with aggregates (melbourne)
Developing microservices with aggregates (melbourne)
 
Developing microservices with aggregates (devnexus2017)
Developing microservices with aggregates (devnexus2017)Developing microservices with aggregates (devnexus2017)
Developing microservices with aggregates (devnexus2017)
 

Kürzlich hochgeladen

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Event Sourcing using Akka on AWS