SlideShare a Scribd company logo
1 of 37
Download to read offline
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

More Related Content

Similar to Diving into event-sourcing and event-driven architectures

Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular SlidesJim Lynch
 
Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - ObservableDragos Ionita
 
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?Mattias Andersson
 
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, everythingKen Mugrage
 
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?Anthony Brown
 
Continuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOContinuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOJosh Cypher
 
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 AzureMartin Gutenbrunner
 
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 ReactIlia Idakiev
 
Making software maintainable
Making software maintainableMaking software maintainable
Making software maintainablePeter Sumskas
 
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, EverythingKen Mugrage
 
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 WorseKevlin Henney
 
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)VMware Tanzu
 
IC3 -- Configuration Management 101
IC3 -- Configuration Management 101IC3 -- Configuration Management 101
IC3 -- Configuration Management 101Gabriel Schuyler
 
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 weekDr. Felix Raab
 
Herding cats in the Cloud
Herding cats in the CloudHerding cats in the Cloud
Herding cats in the CloudDewey Sasser
 
React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016Simon Sturmer
 
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 projectsZeh Fernando
 

Similar to 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
 

Recently uploaded

247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 

Recently uploaded (20)

Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 

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