SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
DIVING INTO EVENT DRIVEN
ARCHITECTURES
BCN ON RAILS
UNAI ESTEIBAR
SOFTWARE ENGINEER
@ XING
@UESTEIBAR ON THE INTERNETS
TEXT
THIS TALK
▸ Introduction to event-sourcing and event-driven architectures.
▸ Our experience on developing an event-sourced app on rails.
▸ Not rails specific.
▸ Oversimplified explanations.
▸ Gifs.
▸ Bad jokes.
WE NEED TO BUILD A STATISTICS APP
TO GATHER AND ANALYSE USERS
ACTIVITY ON THE PLATFORM.
Big boss
LONG STORY SHORT
SO… WE’RE GONNA SYNC EVERYTHING
THROUGH REST ENDPOINTS EVERY FEW
MINUTES, RIGHT? THAT SHOULD DO THE
JOB…
Famous last words
FIRST DISCUSSIONS
I HEARD ABOUT THIS EVENT
SOURCING THING… SOUNDS
FANCY
Excited developers
IN A NUTSHELL
▸ You can query more complex things. Like visits in a certain
time range.
▸ You can build histograms easily.
▸ Data is easier to analyse (useful for providing dashboards
and stats to Product).
GOODIES
NOT SO GOODIES
▸ You can end up with *a lot of events*.
▸ I mean *a lot*.
▸ Onboarding can be complicated.
BUT IF YOU END UP WITH A LOT
OF EVENTS… WHAT ABOUT
PERFORMANCE?
Anyone, anywhere
FIRST DISCUSSIONS
WELCOME TO
CQRS
COMMAND
QUERY
RESPONSIBILITY
SEGREGATION
WARNING
OVERSIMPLIFIED
EXPLANATION
WHAT’S THIS?
SEPARATE WRITE AND READ MODELS
TRADITIONALLY, DATABASES ARE:
▸ Fast to write, slow to read.
▸ Slow to write, fast to read.
CQRS ALLOWS US TO BE FAST TO WRITE AND FAST TO READ.
▸ Save your write model (an event) to a fast to write
database.
▸ Build your projection (read model) in a way that can make
querying easier. (avoiding to do joins, for example).
▸ Write this projection to a fast to read database.
HOW?
▸ Querying the projection is really fast. No more joins.
▸ You can have multiple projections based on the same write
model to accommodate different queries.
▸ If your projection needs more data, you can recreate it
based on your write model.
▸ If your projection is corrupt, you can recreate it as well.
▸ Since the bigger part of your heavy processing is
happening in a worker, it’s much easier to scale.
GOODIES
▸ Data won’t be immediately consistent, but eventually
consistent.
COSTS
BUT YOU HAVE DUPLICATED DATA…
WHAT HAPPENED TO HAVING A
SINGLE SOURCE OF TRUTH?
You, right now
NOT SO GOODIES
YOU STILL HAVE A SINGLE SOURCE OF TRUTH.
YOUR PROJECTION IS BUILT BASED ON YOUR
ORIGINAL DATA (THE WRITE MODEL) AND CAN (AND
SHOULD) BE RECONSTITUTED AS NECESSARY.
LIFECYCLE OF A
DOMAIN EVENT
PROFILES
APP
GET /profile/1
WORKER
DB
WORKER
Record projection

(read model)
Record event

(write model)
Publish

profile.visited
DB
Publish

profile.visited.registered
THINGS TO KEEP
IN MIND
THINGS TO KEEP IN MIND
▸ Payload structure of the published event.
▸ Possibility of losing messages.
▸ Transactionality.
PAYLOAD STRUCTURE
▸ As extensible as possible.
▸ Avoid versioning as much as you can.
▸ If you need to version, there’s different strategies:
▸ Deal with the different versions everywhere in the code.
▸ Upcast the old events on first read.
▸ Upcast the entire event store right away.
DON’T MISS AN EVENT: PUBLISHING
Publish

profile.visited
APP WORKER
Risk of losing the message
APP
PUBLISHED
EVENTS
STORE
WORKERPublish

profile.visited
As a cron job
DON’T MISS AN EVENT: CONSUMING
Consume

profile.visited
WORKER
DEAD LETTER
▸ Try to keep dead letter as independent from your app as
possible.
DB
ARCHITECTURAL
OVERVIEW
EVENT-BASED APPROACH
APP
A B C D
WORKER
X10000
WORKER WORKER WORKERWORKERWORKERWORKER
DB
▸ Scaling is easy and painless.
▸ Dependencies between apps are (almost) gone.
▸ We avoid the domino effect.
GOODIES
NOT SO GOODIES
▸ Adds more complexity to your architecture.
TIPS TO DO THIS IN THE REAL WORLD
▸ Make sure the entire team is on board and have a common
understanding of these techniques.
▸ Explain it to your product team. They will figure out ways
to exploit this that you would never think of.
▸ Your recovery strategy should be painless. One script
should be enough to rebuild your projections.
▸ Stick to the strategy. If you need a new data source, make
it so it comes into your app as an event (e.g. recreating
events for historical data).
LINKS
SOME NICE READS TO GO DEEPER
▸ Versioning: http://files.movereem.nl/2017saner-
eventsourcing.pdf
▸ Software Architecture Patterns by Mark Richards (Chapter
2: Event-Driven Architecture)
▸ Exploring CQRS and Event Sourcing by Microsoft (https://
www.microsoft.com/en-us/download/details.aspx?
id=34774)
▸ Implementing Domain-Driven Design by Vaughn Vernon
Diving into event-sourcing and event-driven architectures

Contenu connexe

Similaire à Diving into event-sourcing and event-driven architectures

Similaire à Diving into event-sourcing and event-driven architectures (20)

Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
 
Advanced workflows
Advanced workflowsAdvanced workflows
Advanced workflows
 
Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - Observable
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
You only have to change on thing to do the DevOps, everything
You only have to change on thing to do the DevOps, everythingYou only have to change on thing to do the DevOps, everything
You only have to change on thing to do the DevOps, everything
 
Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?
 
Continuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOContinuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIO
 
DevOne - How to not fail with Azure
DevOne - How to not fail with AzureDevOne - How to not fail with Azure
DevOne - How to not fail with Azure
 
Offline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and ReactOffline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and React
 
Making software maintainable
Making software maintainableMaking software maintainable
Making software maintainable
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
You only have to change one thing to make DevOps work, Everything
You only have to change one thing to make DevOps work, EverythingYou only have to change one thing to make DevOps work, Everything
You only have to change one thing to make DevOps work, Everything
 
Worse Is Better, for Better or for Worse
Worse Is Better, for Better or for WorseWorse Is Better, for Better or for Worse
Worse Is Better, for Better or for Worse
 
Evolving to Cloud-Native - Nate Schutta (1/2)
Evolving to Cloud-Native - Nate Schutta (1/2)Evolving to Cloud-Native - Nate Schutta (1/2)
Evolving to Cloud-Native - Nate Schutta (1/2)
 
IC3 -- Configuration Management 101
IC3 -- Configuration Management 101IC3 -- Configuration Management 101
IC3 -- Configuration Management 101
 
Building a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one weekBuilding a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one week
 
Herding cats in the Cloud
Herding cats in the CloudHerding cats in the Cloud
Herding cats in the Cloud
 
React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016
 
Lessons learned maintaining Open Source ActionScript projects
Lessons learned maintaining Open Source ActionScript projectsLessons learned maintaining Open Source ActionScript projects
Lessons learned maintaining Open Source ActionScript projects
 
Intro to react_v2
Intro to react_v2Intro to react_v2
Intro to react_v2
 

Dernier

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Dernier (20)

HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 

Diving into event-sourcing and event-driven architectures

  • 1. DIVING INTO EVENT DRIVEN ARCHITECTURES BCN ON RAILS
  • 2. UNAI ESTEIBAR SOFTWARE ENGINEER @ XING @UESTEIBAR ON THE INTERNETS
  • 3. TEXT THIS TALK ▸ Introduction to event-sourcing and event-driven architectures. ▸ Our experience on developing an event-sourced app on rails. ▸ Not rails specific. ▸ Oversimplified explanations. ▸ Gifs. ▸ Bad jokes.
  • 4. WE NEED TO BUILD A STATISTICS APP TO GATHER AND ANALYSE USERS ACTIVITY ON THE PLATFORM. Big boss LONG STORY SHORT
  • 5. SO… WE’RE GONNA SYNC EVERYTHING THROUGH REST ENDPOINTS EVERY FEW MINUTES, RIGHT? THAT SHOULD DO THE JOB… Famous last words FIRST DISCUSSIONS
  • 6.
  • 7. I HEARD ABOUT THIS EVENT SOURCING THING… SOUNDS FANCY Excited developers
  • 8.
  • 10.
  • 11.
  • 12. ▸ You can query more complex things. Like visits in a certain time range. ▸ You can build histograms easily. ▸ Data is easier to analyse (useful for providing dashboards and stats to Product). GOODIES
  • 13. NOT SO GOODIES ▸ You can end up with *a lot of events*. ▸ I mean *a lot*. ▸ Onboarding can be complicated.
  • 14. BUT IF YOU END UP WITH A LOT OF EVENTS… WHAT ABOUT PERFORMANCE? Anyone, anywhere FIRST DISCUSSIONS
  • 18. WHAT’S THIS? SEPARATE WRITE AND READ MODELS TRADITIONALLY, DATABASES ARE: ▸ Fast to write, slow to read. ▸ Slow to write, fast to read. CQRS ALLOWS US TO BE FAST TO WRITE AND FAST TO READ.
  • 19. ▸ Save your write model (an event) to a fast to write database. ▸ Build your projection (read model) in a way that can make querying easier. (avoiding to do joins, for example). ▸ Write this projection to a fast to read database. HOW?
  • 20. ▸ Querying the projection is really fast. No more joins. ▸ You can have multiple projections based on the same write model to accommodate different queries. ▸ If your projection needs more data, you can recreate it based on your write model. ▸ If your projection is corrupt, you can recreate it as well. ▸ Since the bigger part of your heavy processing is happening in a worker, it’s much easier to scale. GOODIES
  • 21. ▸ Data won’t be immediately consistent, but eventually consistent. COSTS
  • 22. BUT YOU HAVE DUPLICATED DATA… WHAT HAPPENED TO HAVING A SINGLE SOURCE OF TRUTH? You, right now NOT SO GOODIES
  • 23. YOU STILL HAVE A SINGLE SOURCE OF TRUTH. YOUR PROJECTION IS BUILT BASED ON YOUR ORIGINAL DATA (THE WRITE MODEL) AND CAN (AND SHOULD) BE RECONSTITUTED AS NECESSARY.
  • 25. PROFILES APP GET /profile/1 WORKER DB WORKER Record projection
 (read model) Record event
 (write model) Publish
 profile.visited DB Publish
 profile.visited.registered
  • 27. THINGS TO KEEP IN MIND ▸ Payload structure of the published event. ▸ Possibility of losing messages. ▸ Transactionality.
  • 28. PAYLOAD STRUCTURE ▸ As extensible as possible. ▸ Avoid versioning as much as you can. ▸ If you need to version, there’s different strategies: ▸ Deal with the different versions everywhere in the code. ▸ Upcast the old events on first read. ▸ Upcast the entire event store right away.
  • 29. DON’T MISS AN EVENT: PUBLISHING Publish
 profile.visited APP WORKER Risk of losing the message APP PUBLISHED EVENTS STORE WORKERPublish
 profile.visited As a cron job
  • 30. DON’T MISS AN EVENT: CONSUMING Consume
 profile.visited WORKER DEAD LETTER ▸ Try to keep dead letter as independent from your app as possible. DB
  • 32. EVENT-BASED APPROACH APP A B C D WORKER X10000 WORKER WORKER WORKERWORKERWORKERWORKER DB
  • 33.
  • 34. ▸ Scaling is easy and painless. ▸ Dependencies between apps are (almost) gone. ▸ We avoid the domino effect. GOODIES NOT SO GOODIES ▸ Adds more complexity to your architecture.
  • 35. TIPS TO DO THIS IN THE REAL WORLD ▸ Make sure the entire team is on board and have a common understanding of these techniques. ▸ Explain it to your product team. They will figure out ways to exploit this that you would never think of. ▸ Your recovery strategy should be painless. One script should be enough to rebuild your projections. ▸ Stick to the strategy. If you need a new data source, make it so it comes into your app as an event (e.g. recreating events for historical data).
  • 36. LINKS SOME NICE READS TO GO DEEPER ▸ Versioning: http://files.movereem.nl/2017saner- eventsourcing.pdf ▸ Software Architecture Patterns by Mark Richards (Chapter 2: Event-Driven Architecture) ▸ Exploring CQRS and Event Sourcing by Microsoft (https:// www.microsoft.com/en-us/download/details.aspx? id=34774) ▸ Implementing Domain-Driven Design by Vaughn Vernon