SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Just make them faster!
Slow (re)projections in Event Sourcing?
Dennis Doomen
@ddoomen | The Continuous Improver
About Me
Hands-on architect in the .NET space with 25 years of experience on
an everlasting quest for knowledge to build the right software the right
way at the right time
@ddoomen | The Continuous Improver
Establishing a Ubiquitous Language
Dennis Doomen | @ddoomen | The Continuous Improver
Projection
A (persisted) representation of a set
of events optimized for querying.
Dennis Doomen | @ddoomen | The Continuous Improver
Projector
Actively or passively transposes
events into an optimized
representation
Dennis Doomen | @ddoomen | The Continuous Improver
Checkpoint
An unambiguous reference to a
particular commit in an ordered
event store.
Stream
An ordered collection of events,
originating from the same aggregate
Commit
A collection of ordered events for a
single aggregate, persisted at the
same time
Why do we care?
Dennis Doomen | @ddoomen | The Continuous Improver
Reasons for
reprojections
• Fix a code bug in the
projection
• Restructure the projection
for performance reasons
• New features require
changes to projections.
Dennis Doomen | @ddoomen | The Continuous Improver
In-place upgrades
Event Store
Projector
Application
Version 2
Version 1
X Involves down-
time until the
projection has
been rebuild.
Reads data from old
database
Dennis Doomen | @ddoomen | The Continuous Improver
Out-of-place / Blue-Green upgrades
Event Store
Projector
Application Application
Network Load Balancer
Event Store
Version 1 Version 2
events
Projection
Projector
Projection
bring off-line
Returns HTTP 503
(Service Unavailable)
Returns HTTP 503
(Service Unavailable)
Dennis Doomen | @ddoomen | The Continuous Improver
Requires full
rebuild of the
projections
Practically no
downtime.
Patterns for improving (re)projection speed
Dennis Doomen | @ddoomen | The Continuous Improver
Make projectors fully asynchronous
Domain
Event Store
Events
App
Persistent
Store
Projector
HTTP API
Projection
Freedom to go
as fast or slow
as possible
Autonomy to
handle (transient)
projection issues
independently
Can use
whatever you
need or deem fit
Requires persistent
tracking of the
subscription
Requires a way to
uniquely track a
commit within the
event store
Dennis Doomen | @ddoomen | The Continuous Improver
Domain updates
will not be
immediately
visible.
Project stream-by-stream
Domain
Event Store
Events
App
Persistent
Store
Projector
HTTP API
Projection
Single write
operation per
stream
Reads commits
stream-by-stream
instead of in order of
appearance
Only works if
projection map 1-
to-1 to streams
Requires different
technique during
reprojection vs
normal operation.
Dennis Doomen | @ddoomen | The Continuous Improver
ORM
Use an ORM’s Unit of Work
Domain
Event Store
Events
App
Persistent
Store
Projector
HTTP API
Projection
Can process as
many events in a
batch as needed
and still trigger
one DB operation
Reads commits in order
of appearance
Some ORMs
provide first and
second level
caching
Need to stay away
from typical ORM
pitfalls.
Can mix and
match with RAW
SQL
Requires custom
handling when
batch processing
fails
Dennis Doomen | @ddoomen | The Continuous Improver
Commit
Event Event
Commit
Event Event
Commit
Event Event
RDBMS
Commit
Event Event
Commit
Event Event
Commit
Event Event
RDBMS
Unit of Work
Use an ORM’s Unit of Work
INSERT/UPDATE … WHERE …
INSERT/UPDATE … WHERE …
INSERT/UPDATE … WHERE …
INSERT/UPDATE … WHERE …
Dennis Doomen | @ddoomen | The Continuous Improver
Startup-time in-memory rebuilds
Domain
Event Store
Events
App
Distributed
Cache
Projector
HTTP API
Projection
Kept
in-memory
Can be both
synchronous and
asynchronous
Postpones
availability of data
at start-up.
Can help avoid
reprojections in a
server farm
Can be very fast
Dennis Doomen | @ddoomen | The Continuous Improver
MRU cache
Use aggressive caching during rebuilds
Domain
Event Store
Events
App
Persistent
Store
Projector
HTTP API
Projection
Works well with an
ORM’s unit-of-
work
May be only safe
during rebuilds.
Dennis Doomen | @ddoomen | The Continuous Improver
Mark streams as closed and skip reprojection
Domain
Event Store
Events
App
Persistent
Store
Projector
HTTP API
Projection
Could also be
triggered through
an explicit archive
process
Skips “closed”
commits
Closed Graph
Projector
Persistent
Store
Tracks whether all
related streams can be
closed
Marks all commits in
the stream as “closed”
Requires custom
metadata per
commit.
Only useful if your
domain has the
notion of “closed”
Dennis Doomen | @ddoomen | The Continuous Improver
Persistent
Store
Persistent
Store
Separate projections for “closed” streams
Domain
Event Store
Events
App
Projector
HTTP API
“Open” Projections
Moves
projections to the
“closed” store at
the right time
Never needs to be
rebuild
“Closed” Projections
Limited choices for
searching, unless
you accept
schema changes
or use JSON
Need to “join” data
from two stores,
potentially using
different schemas.
Contains projections in
schema-aware format with
additional searchable
fields.
Only useful if your
domain has the
notion of “closed”
Only needs to
rebuild “open”
streams
Dennis Doomen | @ddoomen | The Continuous Improver
Persistent
Store
Lucene
Index / ES
Tombstoning “closed” streams
Domain
Event Store
Events
App
Normal Projector
HTTP API
“Open” Projections
Removes the
projections when
the stream is
tombstoned
Never needs to be
rebuild
Snapshots
Need to “join” data
from two stores,
potentially using
different schemas
Optimized for
searching
Only useful if your
domain has the
notion of “closed”
Deletes the
tombstoned
streams
Tombstone Projector
Dennis Doomen | @ddoomen | The Continuous Improver
Event Store
Tombstone
Projector
Document #1
Marked As
Archivable Event
Lucene / ES Index
Take snapshot
Purge events
Tombstone
$tombstone
stream
Application.
Normal Projector
Search
Tracks deleted streams
for future reference
Stream Tombstoned
Event
Search
Tombstoning “closed” streams
Dennis Doomen | @ddoomen | The Continuous Improver
Allows projectors
to clean up
Original
Cloning and project the remainder
Domain
Event Store
Events
App
Clone
Projector
HTTP API
Projection
Clone individual tables
or the entire database
Cannot rely on
rebuild to fix bugs
Needs to
understand all
supported
database schemas
Triggers the clone and
then projects the
remainder
Cloning tables is
very fast on SQL
Server
Event store can
still be used in
parallal
Requires
autonomy
Dennis Doomen | @ddoomen | The Continuous Improver
Old
projections
Copy on write
Domain
Event Store
Events
App
New
projections
Projector
HTTP API
Projection
Cannot rely on
rebuilds to fix bugs
Whenever a projection
news to change, it is
copied and updated in
the new table/database
No rebuild
needed
Need to join &
deduplicate data
from two stores,
potentially using
different schemas
Limited choices for
searching, unless
you accept schema
changes
Dennis Doomen | @ddoomen | The Continuous Improver
What about the event store itself?
@ddoomen | The Continuous Improver
Out-of-place / Blue-Green upgrades
Event Store
Projector
Application Application
Network Load Balancer
Event Store
Version 1 Version 2
events
Projection
Projector
Projection
Needs to copy
all events
Dennis Doomen | @ddoomen | The Continuous Improver
In-place / Blue-Green upgrades
Event Store
Projector
Application Application
Network Load Balancer
Version 1 Version 2
Projection
Projector
Projection
Event body,
stream ID, etc
Code
Version
Ignores events which
code base version is
newer than supported
Writes events with the
code base version
Rolling back means
loosing data
Old version can
run
simultaneously
with the new
version
Requires
asynchronous
projectors /
dispatching
Dennis Doomen | @ddoomen | The Continuous Improver
Every event has a code
base version
Q&A
…ask at Kandddinsky
…ping me at @ddoomen
…email me at dennis.doomen@avivasolutions.nl

Weitere ähnliche Inhalte

Was ist angesagt?

Efficient Data Formats for Analytics with Parquet and Arrow
Efficient Data Formats for Analytics with Parquet and ArrowEfficient Data Formats for Analytics with Parquet and Arrow
Efficient Data Formats for Analytics with Parquet and Arrow
DataWorks Summit/Hadoop Summit
 
Agile retrospectives - why, what and how
Agile retrospectives - why, what and howAgile retrospectives - why, what and how
Agile retrospectives - why, what and how
DmitriyViktorov
 

Was ist angesagt? (15)

Project Management: Integration Management Knowledge Area
Project Management: Integration Management Knowledge AreaProject Management: Integration Management Knowledge Area
Project Management: Integration Management Knowledge Area
 
Itto pmbok guide 6th edition
Itto   pmbok guide 6th editionItto   pmbok guide 6th edition
Itto pmbok guide 6th edition
 
Sketching Data with T-Digest In Apache Spark: Spark Summit East talk by Erik ...
Sketching Data with T-Digest In Apache Spark: Spark Summit East talk by Erik ...Sketching Data with T-Digest In Apache Spark: Spark Summit East talk by Erik ...
Sketching Data with T-Digest In Apache Spark: Spark Summit East talk by Erik ...
 
The evolution of Netflix's S3 data warehouse (Strata NY 2018)
The evolution of Netflix's S3 data warehouse (Strata NY 2018)The evolution of Netflix's S3 data warehouse (Strata NY 2018)
The evolution of Netflix's S3 data warehouse (Strata NY 2018)
 
Introduction to Software Project Management
Introduction to Software Project ManagementIntroduction to Software Project Management
Introduction to Software Project Management
 
Efficient Data Formats for Analytics with Parquet and Arrow
Efficient Data Formats for Analytics with Parquet and ArrowEfficient Data Formats for Analytics with Parquet and Arrow
Efficient Data Formats for Analytics with Parquet and Arrow
 
Project management and Success Criteria
Project management and Success Criteria Project management and Success Criteria
Project management and Success Criteria
 
Cost Estimation
Cost EstimationCost Estimation
Cost Estimation
 
Agile retrospectives - why, what and how
Agile retrospectives - why, what and howAgile retrospectives - why, what and how
Agile retrospectives - why, what and how
 
Data Science Tutorial | Introduction To Data Science | Data Science Training ...
Data Science Tutorial | Introduction To Data Science | Data Science Training ...Data Science Tutorial | Introduction To Data Science | Data Science Training ...
Data Science Tutorial | Introduction To Data Science | Data Science Training ...
 
Rocks db state store in structured streaming
Rocks db state store in structured streamingRocks db state store in structured streaming
Rocks db state store in structured streaming
 
Software project management 3
Software project management 3Software project management 3
Software project management 3
 
Project Management - Basic Concepts
Project Management - Basic ConceptsProject Management - Basic Concepts
Project Management - Basic Concepts
 
Data Visualization in Data Science
Data Visualization in Data ScienceData Visualization in Data Science
Data Visualization in Data Science
 
introduction to project management
introduction to project management introduction to project management
introduction to project management
 

Ähnlich wie Slow Event Sourcing (re)projections - Just make them faster!

A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
Outware Mobile
 
Tools and practices to help you deal with legacy code
Tools and practices to help you deal with legacy codeTools and practices to help you deal with legacy code
Tools and practices to help you deal with legacy code
Dennis Doomen
 

Ähnlich wie Slow Event Sourcing (re)projections - Just make them faster! (20)

Design patterns for Event Sourcing in .NET
Design patterns for Event Sourcing in .NETDesign patterns for Event Sourcing in .NET
Design patterns for Event Sourcing in .NET
 
Decomposing the Monolith (Riga Dev Days 2019)
Decomposing the Monolith (Riga Dev Days 2019)Decomposing the Monolith (Riga Dev Days 2019)
Decomposing the Monolith (Riga Dev Days 2019)
 
The Good, The Bad and The Ugly of Event Sourcing
The Good, The Bad and The Ugly of Event Sourcing The Good, The Bad and The Ugly of Event Sourcing
The Good, The Bad and The Ugly of Event Sourcing
 
Practical introduction to DDD, CQRS and Event Sourcing
Practical introduction to DDD, CQRS and Event SourcingPractical introduction to DDD, CQRS and Event Sourcing
Practical introduction to DDD, CQRS and Event Sourcing
 
Event Sourcing from the Trenches (DDD Europe 2020)
Event Sourcing from the Trenches (DDD Europe 2020)Event Sourcing from the Trenches (DDD Europe 2020)
Event Sourcing from the Trenches (DDD Europe 2020)
 
Event Sourcing from the Trenches (with examples from .NET)
Event Sourcing from the Trenches (with examples from .NET)Event Sourcing from the Trenches (with examples from .NET)
Event Sourcing from the Trenches (with examples from .NET)
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservices
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
 
What you can learn from an open-source project with 250 million downloads
What you can learn from an open-source project with 250 million downloadsWhat you can learn from an open-source project with 250 million downloads
What you can learn from an open-source project with 250 million downloads
 
Introduction Into Docker Ecosystem
Introduction Into Docker EcosystemIntroduction Into Docker Ecosystem
Introduction Into Docker Ecosystem
 
Decomposing the Monolith using Microservices that don't give you pain
Decomposing the Monolith using Microservices that don't give you painDecomposing the Monolith using Microservices that don't give you pain
Decomposing the Monolith using Microservices that don't give you pain
 
Tools and practices to help you deal with legacy code
Tools and practices to help you deal with legacy codeTools and practices to help you deal with legacy code
Tools and practices to help you deal with legacy code
 
AWS 2013 LA Media Event: Scalable Media Processing
AWS 2013 LA Media Event: Scalable Media ProcessingAWS 2013 LA Media Event: Scalable Media Processing
AWS 2013 LA Media Event: Scalable Media Processing
 
Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...
Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...
Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...
 
Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...
Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...
Decomposing the monolith into embeddable microservices using OWIN, WebHooks, ...
 
Handling Data in Mega Scale Systems
Handling Data in Mega Scale SystemsHandling Data in Mega Scale Systems
Handling Data in Mega Scale Systems
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
Immutable Infrastructure: Rise of the Machine Images
Immutable Infrastructure: Rise of the Machine ImagesImmutable Infrastructure: Rise of the Machine Images
Immutable Infrastructure: Rise of the Machine Images
 
O365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - MaterialO365 Developer Bootcamp NJ 2018 - Material
O365 Developer Bootcamp NJ 2018 - Material
 
ShowNTell: An easy-to-use tool for answering students’ questions with voice-o...
ShowNTell: An easy-to-use tool for answering students’ questions with voice-o...ShowNTell: An easy-to-use tool for answering students’ questions with voice-o...
ShowNTell: An easy-to-use tool for answering students’ questions with voice-o...
 

Mehr von Dennis Doomen

Getting a grip on your code dependencies (2023-10)
Getting a grip on your code dependencies (2023-10)Getting a grip on your code dependencies (2023-10)
Getting a grip on your code dependencies (2023-10)
Dennis Doomen
 

Mehr von Dennis Doomen (19)

Getting a grip on your code dependencies (2023-10)
Getting a grip on your code dependencies (2023-10)Getting a grip on your code dependencies (2023-10)
Getting a grip on your code dependencies (2023-10)
 
Getting a grip on your code dependencies
Getting a grip on your code dependenciesGetting a grip on your code dependencies
Getting a grip on your code dependencies
 
My Laws of Test Driven Development (2023)
My Laws of Test Driven Development (2023)My Laws of Test Driven Development (2023)
My Laws of Test Driven Development (2023)
 
Automate Infrastructure with Pulumi and C#
Automate Infrastructure with Pulumi and C#Automate Infrastructure with Pulumi and C#
Automate Infrastructure with Pulumi and C#
 
What is the right unit in unit testing (UpdateConf 2022)
What is the right unit in unit testing (UpdateConf 2022)What is the right unit in unit testing (UpdateConf 2022)
What is the right unit in unit testing (UpdateConf 2022)
 
50 things software teams should not do.pptx
50 things software teams should not do.pptx50 things software teams should not do.pptx
50 things software teams should not do.pptx
 
What is the right "unit" in unit testing and why it is not a class?
What is the right "unit" in unit testing and why it is not a class?What is the right "unit" in unit testing and why it is not a class?
What is the right "unit" in unit testing and why it is not a class?
 
A lab around the principles and practices for writing maintainable code
A lab around the principles and practices for writing maintainable codeA lab around the principles and practices for writing maintainable code
A lab around the principles and practices for writing maintainable code
 
How to Practice TDD Without Shooting Yourself in the Foot
How to Practice TDD Without Shooting Yourself in the FootHow to Practice TDD Without Shooting Yourself in the Foot
How to Practice TDD Without Shooting Yourself in the Foot
 
How to practice TDD without shooting yourself in the foot
How to practice TDD without shooting yourself in the footHow to practice TDD without shooting yourself in the foot
How to practice TDD without shooting yourself in the foot
 
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
 
Lessons learned from two decades of professional software development
Lessons learned from two decades of professional software developmentLessons learned from two decades of professional software development
Lessons learned from two decades of professional software development
 
How To Practice TDD Without Shooting Yourself In The Foot
How To Practice TDD Without Shooting Yourself In The FootHow To Practice TDD Without Shooting Yourself In The Foot
How To Practice TDD Without Shooting Yourself In The Foot
 
Strengths and weaknesses of dependency injection
Strengths and weaknesses of dependency injectionStrengths and weaknesses of dependency injection
Strengths and weaknesses of dependency injection
 
Build Libraries That People Love To use
Build Libraries That People Love To useBuild Libraries That People Love To use
Build Libraries That People Love To use
 
Build Libraries, Not Frameworks
Build Libraries, Not FrameworksBuild Libraries, Not Frameworks
Build Libraries, Not Frameworks
 
The Good, The Bad and The Ugly of Event Sourcing
The Good, The Bad and The Ugly of Event SourcingThe Good, The Bad and The Ugly of Event Sourcing
The Good, The Bad and The Ugly of Event Sourcing
 
How to practice TDD without shooting yourself in the foot
How to practice TDD without shooting yourself in the footHow to practice TDD without shooting yourself in the foot
How to practice TDD without shooting yourself in the foot
 
Git like a Pro (How to use it as it was meant to)
Git like a Pro (How to use it as it was meant to)Git like a Pro (How to use it as it was meant to)
Git like a Pro (How to use it as it was meant to)
 

Kürzlich hochgeladen

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Kürzlich hochgeladen (20)

Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
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
 
%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
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%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
 
%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
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
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
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 

Slow Event Sourcing (re)projections - Just make them faster!

  • 1. Just make them faster! Slow (re)projections in Event Sourcing? Dennis Doomen @ddoomen | The Continuous Improver
  • 2. About Me Hands-on architect in the .NET space with 25 years of experience on an everlasting quest for knowledge to build the right software the right way at the right time @ddoomen | The Continuous Improver
  • 3.
  • 4. Establishing a Ubiquitous Language Dennis Doomen | @ddoomen | The Continuous Improver
  • 5. Projection A (persisted) representation of a set of events optimized for querying. Dennis Doomen | @ddoomen | The Continuous Improver Projector Actively or passively transposes events into an optimized representation
  • 6. Dennis Doomen | @ddoomen | The Continuous Improver Checkpoint An unambiguous reference to a particular commit in an ordered event store. Stream An ordered collection of events, originating from the same aggregate Commit A collection of ordered events for a single aggregate, persisted at the same time
  • 7. Why do we care? Dennis Doomen | @ddoomen | The Continuous Improver
  • 8. Reasons for reprojections • Fix a code bug in the projection • Restructure the projection for performance reasons • New features require changes to projections. Dennis Doomen | @ddoomen | The Continuous Improver
  • 9. In-place upgrades Event Store Projector Application Version 2 Version 1 X Involves down- time until the projection has been rebuild. Reads data from old database Dennis Doomen | @ddoomen | The Continuous Improver
  • 10. Out-of-place / Blue-Green upgrades Event Store Projector Application Application Network Load Balancer Event Store Version 1 Version 2 events Projection Projector Projection bring off-line Returns HTTP 503 (Service Unavailable) Returns HTTP 503 (Service Unavailable) Dennis Doomen | @ddoomen | The Continuous Improver Requires full rebuild of the projections Practically no downtime.
  • 11. Patterns for improving (re)projection speed Dennis Doomen | @ddoomen | The Continuous Improver
  • 12. Make projectors fully asynchronous Domain Event Store Events App Persistent Store Projector HTTP API Projection Freedom to go as fast or slow as possible Autonomy to handle (transient) projection issues independently Can use whatever you need or deem fit Requires persistent tracking of the subscription Requires a way to uniquely track a commit within the event store Dennis Doomen | @ddoomen | The Continuous Improver Domain updates will not be immediately visible.
  • 13. Project stream-by-stream Domain Event Store Events App Persistent Store Projector HTTP API Projection Single write operation per stream Reads commits stream-by-stream instead of in order of appearance Only works if projection map 1- to-1 to streams Requires different technique during reprojection vs normal operation. Dennis Doomen | @ddoomen | The Continuous Improver
  • 14. ORM Use an ORM’s Unit of Work Domain Event Store Events App Persistent Store Projector HTTP API Projection Can process as many events in a batch as needed and still trigger one DB operation Reads commits in order of appearance Some ORMs provide first and second level caching Need to stay away from typical ORM pitfalls. Can mix and match with RAW SQL Requires custom handling when batch processing fails Dennis Doomen | @ddoomen | The Continuous Improver
  • 15. Commit Event Event Commit Event Event Commit Event Event RDBMS Commit Event Event Commit Event Event Commit Event Event RDBMS Unit of Work Use an ORM’s Unit of Work INSERT/UPDATE … WHERE … INSERT/UPDATE … WHERE … INSERT/UPDATE … WHERE … INSERT/UPDATE … WHERE … Dennis Doomen | @ddoomen | The Continuous Improver
  • 16. Startup-time in-memory rebuilds Domain Event Store Events App Distributed Cache Projector HTTP API Projection Kept in-memory Can be both synchronous and asynchronous Postpones availability of data at start-up. Can help avoid reprojections in a server farm Can be very fast Dennis Doomen | @ddoomen | The Continuous Improver
  • 17. MRU cache Use aggressive caching during rebuilds Domain Event Store Events App Persistent Store Projector HTTP API Projection Works well with an ORM’s unit-of- work May be only safe during rebuilds. Dennis Doomen | @ddoomen | The Continuous Improver
  • 18. Mark streams as closed and skip reprojection Domain Event Store Events App Persistent Store Projector HTTP API Projection Could also be triggered through an explicit archive process Skips “closed” commits Closed Graph Projector Persistent Store Tracks whether all related streams can be closed Marks all commits in the stream as “closed” Requires custom metadata per commit. Only useful if your domain has the notion of “closed” Dennis Doomen | @ddoomen | The Continuous Improver
  • 19. Persistent Store Persistent Store Separate projections for “closed” streams Domain Event Store Events App Projector HTTP API “Open” Projections Moves projections to the “closed” store at the right time Never needs to be rebuild “Closed” Projections Limited choices for searching, unless you accept schema changes or use JSON Need to “join” data from two stores, potentially using different schemas. Contains projections in schema-aware format with additional searchable fields. Only useful if your domain has the notion of “closed” Only needs to rebuild “open” streams Dennis Doomen | @ddoomen | The Continuous Improver
  • 20. Persistent Store Lucene Index / ES Tombstoning “closed” streams Domain Event Store Events App Normal Projector HTTP API “Open” Projections Removes the projections when the stream is tombstoned Never needs to be rebuild Snapshots Need to “join” data from two stores, potentially using different schemas Optimized for searching Only useful if your domain has the notion of “closed” Deletes the tombstoned streams Tombstone Projector Dennis Doomen | @ddoomen | The Continuous Improver
  • 21. Event Store Tombstone Projector Document #1 Marked As Archivable Event Lucene / ES Index Take snapshot Purge events Tombstone $tombstone stream Application. Normal Projector Search Tracks deleted streams for future reference Stream Tombstoned Event Search Tombstoning “closed” streams Dennis Doomen | @ddoomen | The Continuous Improver Allows projectors to clean up
  • 22. Original Cloning and project the remainder Domain Event Store Events App Clone Projector HTTP API Projection Clone individual tables or the entire database Cannot rely on rebuild to fix bugs Needs to understand all supported database schemas Triggers the clone and then projects the remainder Cloning tables is very fast on SQL Server Event store can still be used in parallal Requires autonomy Dennis Doomen | @ddoomen | The Continuous Improver
  • 23. Old projections Copy on write Domain Event Store Events App New projections Projector HTTP API Projection Cannot rely on rebuilds to fix bugs Whenever a projection news to change, it is copied and updated in the new table/database No rebuild needed Need to join & deduplicate data from two stores, potentially using different schemas Limited choices for searching, unless you accept schema changes Dennis Doomen | @ddoomen | The Continuous Improver
  • 24. What about the event store itself? @ddoomen | The Continuous Improver
  • 25. Out-of-place / Blue-Green upgrades Event Store Projector Application Application Network Load Balancer Event Store Version 1 Version 2 events Projection Projector Projection Needs to copy all events Dennis Doomen | @ddoomen | The Continuous Improver
  • 26. In-place / Blue-Green upgrades Event Store Projector Application Application Network Load Balancer Version 1 Version 2 Projection Projector Projection Event body, stream ID, etc Code Version Ignores events which code base version is newer than supported Writes events with the code base version Rolling back means loosing data Old version can run simultaneously with the new version Requires asynchronous projectors / dispatching Dennis Doomen | @ddoomen | The Continuous Improver Every event has a code base version
  • 27. Q&A …ask at Kandddinsky …ping me at @ddoomen …email me at dennis.doomen@avivasolutions.nl