SlideShare a Scribd company logo
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Jan-Hendrik Kuperus
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
State of the universe
• age: 7.252.754.400.000.000.000 minutes
• width: 554.000.000.000 lightyears
• stars:
10.000.000.000.000.000.000.000.000
• birthRate: 190.000 stars / minute
Photo by Guillermo Ferla on Unsplash
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
State of the universe
• age: 7.252.754.400.000.000.001 minutes
• width: 554.000.000.006 lightyears
• stars:
10.000.000.000.000.000.000.000.000
• birthRate: 190.000 stars / minute
• deathRate: 190.000 stars / minute
Photo by Guillermo Ferla on Unsplash
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
What just happened?
Photo by Guillermo Ferla on Unsplash
state
t[0]
state
t[1]
time passes
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
What just happened?
Photo by Guillermo Ferla on Unsplash
state
t[0]
state
t[1]
time passes
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Image credit: Particle Data Group at Lawrence Berkeley National
[910] StarBirthEvent
...
[867] PlanetLostLifeEvent
...
[1] ParticleFormedEvent
[0] BigBangEvent
...
[593] PlanetSparkedLifeEvent
[911] PlanetSparkedLifeEvent
...
[???] JFall2021Event
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Traditional State Sourcing (CRUD)
• Stores current state of system
• Constant read-time complexity
• Impossible to determine reason for change
• Impossible to analyze origin of data
Event Sourcing
• Stores changes / events
• Increasing read-time complexity
• All intents of changes visible
• Analysis of data origin
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Traditional State Sourcing (CRUD) Event Sourcing
Shopping Cart
1 copy of Domain-Driven Design by Eric Evans
Added Domain-Driven Design by Eric Evans
Added Implementing Domain-Driven Design
by Vaughn Vernon
Added Domain-Driven Design Distilled by
Vaughn Vernon
Removed Domain-Driven Design Distilled by
Vaughn Vernon
Removed Implementing Domain-Driven
Design by Vaughn Vernon
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Typical Architecture
• User interacts with Command Handler (CH)
• CH validates state and emits Event
• Event stored in Event Stream
• Event is read by Event Processor
• Event Processor updates Read Model
• User reads from Read Model
CQRS
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Common Terms in Event Sourcing
Aggregate Set of entities that share consistency rules. Emits events to
indicate changes. Is rebuilt from its stored events.
Event Unit of change in an Aggregate. Consists of a type/name,
timestamp, payload, metadata and associated Aggregate.
Command Expresses and intent to performa a change within an Aggregate.
Cause Aggregate reconstruction, validation and event emission.
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
The Event Stream
• The Event Stream maintains all history
– Aggregates contain subplots
• Practically Immutable
– Time Travel wreaks havoc
• You should never change past events
– But, what if … ?
Image credit: Particle Data Group at Lawrence Berkeley National
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Types of changes
• Read Model Changes
– New Structure
– Derived Data
• Event-based Changes
– New Data
– Renaming Fields
– Filtering Events
– Splitting Events
– Corrective Events
• Drastic Changes
– Editing Events
– Migrating Event Streams
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Changing a Read Model
• Read Model Changes are "easy"
– Delete & Start over
– Build & Switch
– Corrective Processor
• When ?
– A bug in a projection
– Adding derived data (scale conversion)
– Changes in Read API
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Rebuilding a Read Model
• Stop Event Processor
• Delete the Read Model
• Delete the state of Event Processor
• Restart Event Processor
• ... wait for it
• ... wait for it
• Profit!
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Build & Switch
• Build a second Event Processor
• Add second Read Model database
• Start the Event Processor
• Both projections are kept up to date
• Seamless jump from old to new
• Old is a backup-plan
• When?
– Structural Changes in Read Model
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Corrective Processor
• Fix the original Event Processor
• Build a second Event Processor
• Target the existing Read Model
• Start the second Event Processor
• Projection is corrected while online
• When?
– Adding data
– Fixing Projection Bugs
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Designing Events for Evolution
• Events live forever!
• Careful design pays off
• Start small, capture change in new events
• Event Hierarchies are a big help
A useful system must evolve continually, or it
becomes less useful over time
- Meir Lehman
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Event Hierarchies
• Allow grouping of events
• Allows for easy “fixing events”
• Allows for adding similar events easily
interface UserDetailsEvent {}
class AppliedUnicodePatchJIRA123Event
implements UserDetailsEvent {}
@EventHandler
public void onUserEvent(UserEvent event) {
...
}
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Changing Events
• Events in storage never change
• Axon offers Upcasters
– Modify event during Aggregate Loading
– Chained together
– Driven by Event Revisions
@Revision("1.0")
class User {
String userId;
}
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Adding Data to Events
• Natural progression of application
• SingleEventUpcaster
• Provide default values
• Mind the order of upcasters!
@Revision("1.0")
class User {
String userId;
}
@Revision("2.0")
class User {
String userId;
String name;
}
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
How do upcasters work?
• Axon loads events into
IntermediateEventRepresentation
• Upcasters are asked to do their thing
• Final intermediate representation is then
deserialised
document -> {
document.getRootElement()
.addElement("name")
.setText("Not entered");
return document;
}
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Renaming fields
• Typically fixing typo's or refactorings
document -> {
document.getRootElement()
.selectSingleNode("name")
.setName("username");
return document;
}
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Renaming Events
• Event name should reflect Domain action
• Can be conditional
• Use EventTypeUpcaster
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Filtering Events
• Effectively "deletes" events from a stream
• Useful for reducing clutter in Aggregates
– After "moving" behaviour away
• Impractical for corrections
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Splitting Events
• Allows to reduce the scope of an Event
• Free to split into any number of Events
• Can help reduce Event Handler size
• Uses SingleEntryMultiUpcaster
• Returns a Stream of new events
class UserDetailsUpdatedEvent {
String newName;
String newAddress;
String newPhone;
String newEmail;
String newSelfie;
}
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Corrective Events
• Indicate a manually corrected situation
• A bug caused Email Addresses to be null
• Extend an existing Event
• Make the name recognizable as a correction
• May need a temporary Command
• Temporary means Temporary!
class UserEmailCorrectedByJIRA1234Event
extends UserEmailUpdatedEvent {
String newEmail;
}
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Drastic Changes
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Editing Events
• Last resort, consider upcasting / filtering
• Regulations
– GDPR
– Secrets
• Shut down the application
• Backup the database
• Edit the database
• Restart the application
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Migrating Event Streams
• When applications change drastically
• Chance to consolidate Events / Aggregates
• Restructure Events
• Practically building your 2.0
• It will take time
– System 2.0 can run in "shadow mode"
• Useful when upcasters have stacked
• Useful for splitting applications
• Useful for merging applications
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Summary
• Event Streams are immutable
– But reality changes constantly
• Read Models are easy to change
• Upcasters can modify Event-representations
• Corrective Events show mea culpa
• Database editing as last resort
• Event Stream migration for next version
Jan-Hendrik Kuperus Evolution in Event Sourced Systems
Thank you!
?

More Related Content

Similar to Evolution in Event Sourced Systems - JFall 2021

Event Driven Architectures - Net Conf UY 2018
Event Driven Architectures - Net Conf UY 2018Event Driven Architectures - Net Conf UY 2018
Event Driven Architectures - Net Conf UY 2018
Bradley Irby
 
Hydro Period Presentation 20070809
Hydro Period Presentation 20070809Hydro Period Presentation 20070809
Hydro Period Presentation 20070809
lspencerini
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
jeetendra mandal
 
Cassandra Summit 2014: Turkcell Curio, Real-Time Targeted Mobile Marketing Pl...
Cassandra Summit 2014: Turkcell Curio, Real-Time Targeted Mobile Marketing Pl...Cassandra Summit 2014: Turkcell Curio, Real-Time Targeted Mobile Marketing Pl...
Cassandra Summit 2014: Turkcell Curio, Real-Time Targeted Mobile Marketing Pl...
DataStax Academy
 
Event Driven Architecture – Enabling Microservices
Event Driven Architecture – Enabling MicroservicesEvent Driven Architecture – Enabling Microservices
Event Driven Architecture – Enabling Microservices
Bradley Irby
 
Zentral london mac_ad_uk_2017
Zentral london mac_ad_uk_2017Zentral london mac_ad_uk_2017
Zentral london mac_ad_uk_2017
Henry Stamerjohann
 
Event driven architecture
Event driven architectureEvent driven architecture
Event driven architecture
Vinod Wilson
 
Ekon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven DesignEkon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven Design
Arnaud Bouchez
 
Testing systemqualities agile2012
Testing systemqualities   agile2012Testing systemqualities   agile2012
Testing systemqualities agile2012
drewz lin
 
Testing System Qualities Agile2012 by Rebecca Wirfs-Brock and Joseph Yoder
Testing System Qualities Agile2012 by Rebecca Wirfs-Brock and Joseph YoderTesting System Qualities Agile2012 by Rebecca Wirfs-Brock and Joseph Yoder
Testing System Qualities Agile2012 by Rebecca Wirfs-Brock and Joseph Yoder
Joseph Yoder
 
Rethinking Streaming Analytics For Scale
Rethinking Streaming Analytics For ScaleRethinking Streaming Analytics For Scale
Rethinking Streaming Analytics For Scale
Helena Edelson
 
Microservices, Kubernetes, and Application Modernization Done Right
Microservices, Kubernetes, and Application Modernization Done RightMicroservices, Kubernetes, and Application Modernization Done Right
Microservices, Kubernetes, and Application Modernization Done Right
Lightbend
 
Reactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala MeetupReactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala Meetup
Miguel Pastor
 
Rethinking Streaming Analytics for Scale
Rethinking Streaming Analytics for ScaleRethinking Streaming Analytics for Scale
Rethinking Streaming Analytics for Scale
C4Media
 
Software archiecture lecture05
Software archiecture   lecture05Software archiecture   lecture05
Software archiecture lecture05
Luktalja
 
Dancing with publish/subscribe
Dancing with publish/subscribeDancing with publish/subscribe
Dancing with publish/subscribe
Sameera Horawalavithana
 
Intellias CQRS Framework
Intellias CQRS FrameworkIntellias CQRS Framework
Intellias CQRS Framework
Sergey Seletsky
 
Zero-downtime deployment on Kubernetes with Hazelcast
Zero-downtime deployment on Kubernetes with HazelcastZero-downtime deployment on Kubernetes with Hazelcast
Zero-downtime deployment on Kubernetes with Hazelcast
Nicolas Fränkel
 
Making sense of messy problems - Systems thinking for interaction designers
Making sense of messy problems - Systems thinking for interaction designersMaking sense of messy problems - Systems thinking for interaction designers
Making sense of messy problems - Systems thinking for interaction designers
johanna kollmann
 
How Events Are Reshaping Modern Systems
How Events Are Reshaping Modern SystemsHow Events Are Reshaping Modern Systems
How Events Are Reshaping Modern Systems
C4Media
 

Similar to Evolution in Event Sourced Systems - JFall 2021 (20)

Event Driven Architectures - Net Conf UY 2018
Event Driven Architectures - Net Conf UY 2018Event Driven Architectures - Net Conf UY 2018
Event Driven Architectures - Net Conf UY 2018
 
Hydro Period Presentation 20070809
Hydro Period Presentation 20070809Hydro Period Presentation 20070809
Hydro Period Presentation 20070809
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
 
Cassandra Summit 2014: Turkcell Curio, Real-Time Targeted Mobile Marketing Pl...
Cassandra Summit 2014: Turkcell Curio, Real-Time Targeted Mobile Marketing Pl...Cassandra Summit 2014: Turkcell Curio, Real-Time Targeted Mobile Marketing Pl...
Cassandra Summit 2014: Turkcell Curio, Real-Time Targeted Mobile Marketing Pl...
 
Event Driven Architecture – Enabling Microservices
Event Driven Architecture – Enabling MicroservicesEvent Driven Architecture – Enabling Microservices
Event Driven Architecture – Enabling Microservices
 
Zentral london mac_ad_uk_2017
Zentral london mac_ad_uk_2017Zentral london mac_ad_uk_2017
Zentral london mac_ad_uk_2017
 
Event driven architecture
Event driven architectureEvent driven architecture
Event driven architecture
 
Ekon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven DesignEkon21 Microservices - Event Driven Design
Ekon21 Microservices - Event Driven Design
 
Testing systemqualities agile2012
Testing systemqualities   agile2012Testing systemqualities   agile2012
Testing systemqualities agile2012
 
Testing System Qualities Agile2012 by Rebecca Wirfs-Brock and Joseph Yoder
Testing System Qualities Agile2012 by Rebecca Wirfs-Brock and Joseph YoderTesting System Qualities Agile2012 by Rebecca Wirfs-Brock and Joseph Yoder
Testing System Qualities Agile2012 by Rebecca Wirfs-Brock and Joseph Yoder
 
Rethinking Streaming Analytics For Scale
Rethinking Streaming Analytics For ScaleRethinking Streaming Analytics For Scale
Rethinking Streaming Analytics For Scale
 
Microservices, Kubernetes, and Application Modernization Done Right
Microservices, Kubernetes, and Application Modernization Done RightMicroservices, Kubernetes, and Application Modernization Done Right
Microservices, Kubernetes, and Application Modernization Done Right
 
Reactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala MeetupReactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala Meetup
 
Rethinking Streaming Analytics for Scale
Rethinking Streaming Analytics for ScaleRethinking Streaming Analytics for Scale
Rethinking Streaming Analytics for Scale
 
Software archiecture lecture05
Software archiecture   lecture05Software archiecture   lecture05
Software archiecture lecture05
 
Dancing with publish/subscribe
Dancing with publish/subscribeDancing with publish/subscribe
Dancing with publish/subscribe
 
Intellias CQRS Framework
Intellias CQRS FrameworkIntellias CQRS Framework
Intellias CQRS Framework
 
Zero-downtime deployment on Kubernetes with Hazelcast
Zero-downtime deployment on Kubernetes with HazelcastZero-downtime deployment on Kubernetes with Hazelcast
Zero-downtime deployment on Kubernetes with Hazelcast
 
Making sense of messy problems - Systems thinking for interaction designers
Making sense of messy problems - Systems thinking for interaction designersMaking sense of messy problems - Systems thinking for interaction designers
Making sense of messy problems - Systems thinking for interaction designers
 
How Events Are Reshaping Modern Systems
How Events Are Reshaping Modern SystemsHow Events Are Reshaping Modern Systems
How Events Are Reshaping Modern Systems
 

Recently uploaded

How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
Massimo Artizzu
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
NishanthaBulumulla1
 

Recently uploaded (20)

How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
 

Evolution in Event Sourced Systems - JFall 2021

  • 1. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Jan-Hendrik Kuperus
  • 2. Jan-Hendrik Kuperus Evolution in Event Sourced Systems State of the universe • age: 7.252.754.400.000.000.000 minutes • width: 554.000.000.000 lightyears • stars: 10.000.000.000.000.000.000.000.000 • birthRate: 190.000 stars / minute Photo by Guillermo Ferla on Unsplash
  • 3. Jan-Hendrik Kuperus Evolution in Event Sourced Systems State of the universe • age: 7.252.754.400.000.000.001 minutes • width: 554.000.000.006 lightyears • stars: 10.000.000.000.000.000.000.000.000 • birthRate: 190.000 stars / minute • deathRate: 190.000 stars / minute Photo by Guillermo Ferla on Unsplash
  • 4. Jan-Hendrik Kuperus Evolution in Event Sourced Systems What just happened? Photo by Guillermo Ferla on Unsplash state t[0] state t[1] time passes
  • 5. Jan-Hendrik Kuperus Evolution in Event Sourced Systems What just happened? Photo by Guillermo Ferla on Unsplash state t[0] state t[1] time passes
  • 6. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Image credit: Particle Data Group at Lawrence Berkeley National [910] StarBirthEvent ... [867] PlanetLostLifeEvent ... [1] ParticleFormedEvent [0] BigBangEvent ... [593] PlanetSparkedLifeEvent [911] PlanetSparkedLifeEvent ... [???] JFall2021Event
  • 7. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Traditional State Sourcing (CRUD) • Stores current state of system • Constant read-time complexity • Impossible to determine reason for change • Impossible to analyze origin of data Event Sourcing • Stores changes / events • Increasing read-time complexity • All intents of changes visible • Analysis of data origin
  • 8. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Traditional State Sourcing (CRUD) Event Sourcing Shopping Cart 1 copy of Domain-Driven Design by Eric Evans Added Domain-Driven Design by Eric Evans Added Implementing Domain-Driven Design by Vaughn Vernon Added Domain-Driven Design Distilled by Vaughn Vernon Removed Domain-Driven Design Distilled by Vaughn Vernon Removed Implementing Domain-Driven Design by Vaughn Vernon
  • 9. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Typical Architecture • User interacts with Command Handler (CH) • CH validates state and emits Event • Event stored in Event Stream • Event is read by Event Processor • Event Processor updates Read Model • User reads from Read Model CQRS
  • 10. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Common Terms in Event Sourcing Aggregate Set of entities that share consistency rules. Emits events to indicate changes. Is rebuilt from its stored events. Event Unit of change in an Aggregate. Consists of a type/name, timestamp, payload, metadata and associated Aggregate. Command Expresses and intent to performa a change within an Aggregate. Cause Aggregate reconstruction, validation and event emission.
  • 11. Jan-Hendrik Kuperus Evolution in Event Sourced Systems The Event Stream • The Event Stream maintains all history – Aggregates contain subplots • Practically Immutable – Time Travel wreaks havoc • You should never change past events – But, what if … ? Image credit: Particle Data Group at Lawrence Berkeley National
  • 12. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Types of changes • Read Model Changes – New Structure – Derived Data • Event-based Changes – New Data – Renaming Fields – Filtering Events – Splitting Events – Corrective Events • Drastic Changes – Editing Events – Migrating Event Streams
  • 13. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Changing a Read Model • Read Model Changes are "easy" – Delete & Start over – Build & Switch – Corrective Processor • When ? – A bug in a projection – Adding derived data (scale conversion) – Changes in Read API
  • 14. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Rebuilding a Read Model • Stop Event Processor • Delete the Read Model • Delete the state of Event Processor • Restart Event Processor • ... wait for it • ... wait for it • Profit!
  • 15. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Build & Switch • Build a second Event Processor • Add second Read Model database • Start the Event Processor • Both projections are kept up to date • Seamless jump from old to new • Old is a backup-plan • When? – Structural Changes in Read Model
  • 16. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Corrective Processor • Fix the original Event Processor • Build a second Event Processor • Target the existing Read Model • Start the second Event Processor • Projection is corrected while online • When? – Adding data – Fixing Projection Bugs
  • 17. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Designing Events for Evolution • Events live forever! • Careful design pays off • Start small, capture change in new events • Event Hierarchies are a big help A useful system must evolve continually, or it becomes less useful over time - Meir Lehman
  • 18. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Event Hierarchies • Allow grouping of events • Allows for easy “fixing events” • Allows for adding similar events easily interface UserDetailsEvent {} class AppliedUnicodePatchJIRA123Event implements UserDetailsEvent {} @EventHandler public void onUserEvent(UserEvent event) { ... }
  • 19. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Changing Events • Events in storage never change • Axon offers Upcasters – Modify event during Aggregate Loading – Chained together – Driven by Event Revisions @Revision("1.0") class User { String userId; }
  • 20. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Adding Data to Events • Natural progression of application • SingleEventUpcaster • Provide default values • Mind the order of upcasters! @Revision("1.0") class User { String userId; } @Revision("2.0") class User { String userId; String name; }
  • 21. Jan-Hendrik Kuperus Evolution in Event Sourced Systems How do upcasters work? • Axon loads events into IntermediateEventRepresentation • Upcasters are asked to do their thing • Final intermediate representation is then deserialised document -> { document.getRootElement() .addElement("name") .setText("Not entered"); return document; }
  • 22. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Renaming fields • Typically fixing typo's or refactorings document -> { document.getRootElement() .selectSingleNode("name") .setName("username"); return document; }
  • 23. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Renaming Events • Event name should reflect Domain action • Can be conditional • Use EventTypeUpcaster
  • 24. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Filtering Events • Effectively "deletes" events from a stream • Useful for reducing clutter in Aggregates – After "moving" behaviour away • Impractical for corrections
  • 25. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Splitting Events • Allows to reduce the scope of an Event • Free to split into any number of Events • Can help reduce Event Handler size • Uses SingleEntryMultiUpcaster • Returns a Stream of new events class UserDetailsUpdatedEvent { String newName; String newAddress; String newPhone; String newEmail; String newSelfie; }
  • 26. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Corrective Events • Indicate a manually corrected situation • A bug caused Email Addresses to be null • Extend an existing Event • Make the name recognizable as a correction • May need a temporary Command • Temporary means Temporary! class UserEmailCorrectedByJIRA1234Event extends UserEmailUpdatedEvent { String newEmail; }
  • 27. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Drastic Changes
  • 28. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Editing Events • Last resort, consider upcasting / filtering • Regulations – GDPR – Secrets • Shut down the application • Backup the database • Edit the database • Restart the application
  • 29. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Migrating Event Streams • When applications change drastically • Chance to consolidate Events / Aggregates • Restructure Events • Practically building your 2.0 • It will take time – System 2.0 can run in "shadow mode" • Useful when upcasters have stacked • Useful for splitting applications • Useful for merging applications
  • 30. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Summary • Event Streams are immutable – But reality changes constantly • Read Models are easy to change • Upcasters can modify Event-representations • Corrective Events show mea culpa • Database editing as last resort • Event Stream migration for next version
  • 31. Jan-Hendrik Kuperus Evolution in Event Sourced Systems Thank you! ?

Editor's Notes

  1. I’m curious: who here is actually working on an Event Sourced System? Who is thinking about introducing Event Sourcing? Who is using Axon Framework? Target: 50 minutes
  2. Age: 7,2 quintillion minutes Width: 554 billion lightyears Stars: 10 septillion
  3. We just witnessed the limitation of classic CRUD state storage: the state can't tell you how it came to be.
  4. Next slide shows example of analysis on data origin: the doubting shopper
  5. A more concrete example shows the richness of Event Sourced data. First, the only thing you will see when using CRUD: an order for 1 book. How do you make recommendations based on this? You cannot see into the buyer's behaviour, so you can only guess. On the other hand, when using Event Sourcing, you get the same result: an order for just 1 book. There is however data on what other books the buyer was looking at. You could use this to create a more targeted recommendation. Maybe one of the other books is on sale, you can then notify this user.
  6. A typical architecture for Event Sourced systems uses the CQRS (Command/Query Responsibility Segregation) pattern. While technically possible, it is not recommended to use the Event Stream as a read model. This is due to the fact that state has to be rebuild before answering a query on the command handler side. Whereas the read model’s sole purpose is to handle read operations as quickly as possible.
  7. A typical architecture for Event Sourced systems uses the CQRS (Command/Query Responsibility Segregation) pattern. While technically possible, it is not recommended to use the Event Stream as a read model. This is due to the fact that state has to be rebuild before answering a query on the command handler side. Whereas the read model’s sole purpose is to handle read operations as quickly as possible.
  8. Lehman's law states: any useful application either undergoes continuing change, or gradually becomes less useful What if : regulations require new data? we made a typo? a bug corrupted data?
  9. Rebuilding a read model is an easy way to make changes to an application. You can also use it as a prototyping method. By creating a second projection, you can keep the current application running while you are developing your new application.
  10. An example of this is the rising need for timestamps from the last change of an entity. You can update the normal processor, but it will only add the timestamp to any entity touched from the moment of the fix. You will need a way to update the timestamps for the other, untouched entities as well.
  11. Before we get into how to change Events, I would like to emphasize that changing events should never be done lightly. It is important to remember that events will live forever. That means you as the developer will also have to maintain those events forever, in every part of your system. (Aggregates / Projects / etc...) Don't over-engineer events to cover things you may need in the future. It's better to create many smaller events opposed to large events containing all possible meaning in your system. But as much as we want to try and prevent having to go back and make changes, we will have to be prepared for situations where we are left no other choice.
  12. Let's get into the part where we are changing things for real.
  13. Let's get into the part where we are changing things for real.
  14. Remember the data in the event store is not changed. We are only changing the runtime representation in memory.
  15. It's questionable whether these changes would be worth introducing an upcaster. At least it is possible.
  16. Renaming an event might be more useful.
  17. You should not use these perform corrections on Aggregate state. Corrections are better kept explicit and I'll show you how in just a moment.
  18. Take this example of an Event that contains all updated fields of a User. Imagine this class having another 25 fields. Maybe it seemed like a good idea somewhere in the past. But if the system now wants to respond to address changes, it makes sense to have a separate UserAddressUpdatedEvent. Using a SingleEntryMultiUpcaster, you can split this event in this way and allow old events to still be loaded in an Aggregate that now has handlers for two smaller events.
  19. Corrective events may in some situations also be created by a splitting Upcaster. That does however require the data needed for the correction is already in the original event. This does raise the question whether this is useful. But maybe a dependent Event Processor needs it.
  20. Every now and then, life gives us lemons.