Event Sourcing Core Concepts

  Рет қаралды 6,728

CodeOpinion

CodeOpinion

Күн бұрын

What is event sourcing? Often, many terms are thrown around that can be pretty confusing. I will explain the core concepts and the terminology used around Event Sourcing so you can better understand what it is and what some of the benefits might be.
🔗 EventStoreDB
eventsto.re/codeopinion
🔔 Subscribe: / @codeopinion
💥 Join this channel to get access to a private Discord Server and any source code in my videos.
🔥 Join via Patreon
/ codeopinion
✔️ Join via KZbin
/ @codeopinion
📝 Blog: codeopinion.com
👋 Twitter: / codeopinion
✨ LinkedIn: / dcomartin
📧 Weekly Updates: mailchi.mp/63c7a0b3ff38/codeo...
0:00 Intro
0:33 Events
2:01 Event Streams
4:12 Projections Read Models
6:47 Projections Write Models
8:00 Subscriptions

Пікірлер: 36
@VladyslavHorbachov
@VladyslavHorbachov 2 ай бұрын
Hey Derek, thank you so much for covering this topic. This is the best Event Sourcing channel on KZbin. I have some questions related to implementation, and I can't find the answers anywhere: In case of Clean Architecture + DDD project, we have some layers, like Domain, Application, Infrastructure and so on... These projections should be part of Domain project, or some interfaces has to be defined in the domain, and the implementation lives in some other place? I understand, that the implementation is subjective, and you can do it in hundreds of different ways, but I want to heat your experience on this topic.
@bernhardkrickl5197
@bernhardkrickl5197 2 ай бұрын
We do something similar. We do message exchange with customs. We treat the messages as events and project a series of messages to derive the current state of a declaration process each time a new message comes in or goes out and store the result in our relational data base. I hesitate to call it event sourcing, though. Because imo an event should be something "small", ie. it should not have much data attached to it, and it should be fairly flat. The customs messages can have hundreds of fields in a structure several levels deep with repeatable parts. It's not just "Customs event X has happened, changing the important bit of the state from Y to Z", it's "Customs message X was sent/received and here is the full data of it. Go figure it out yourself."
@pierre-antoineduchateau923
@pierre-antoineduchateau923 2 ай бұрын
Great video as always. I think that it goes a bit farther than 101 though 😉. I would have loved to hear the pros/cons of event sourcing vs normal CRUD with tables !
@nighma
@nighma 2 ай бұрын
Great video! Thank you! Another interesting one will be how to manage atomicity for example when a projector need to write to the read store AND the event store. Another example will be when we need to write data into a database and send a message in a Kafka topic.
@sykvel
@sykvel 2 ай бұрын
Projection only read existing events. New event could be created by aggregate object only that orchestrated by command processing engine. So depending of your commands you can apply different strategy - execute next command in bundle only when first finished successfully or rollback all events when one is failed
@vincentcifello4435
@vincentcifello4435 2 ай бұрын
Marten has Inline projections that write to your read model in the same transaction as saving the event to the store. Although, can't you create an in memory projection is you need such strong read consistency?
@MrDomenic123
@MrDomenic123 2 ай бұрын
Is it just me or are others also surprised by the quite negative comments about event sourcing? I didn't expect event sourcing to get such a rejection...
@CodeOpinion
@CodeOpinion 2 ай бұрын
As with many that are unfamiliar or done incorrectly they tend to throw the baby out with the bathwater
@capability-snob
@capability-snob 2 ай бұрын
Another important lesson is: store the whole event. You're not using those fields? Don't care about that relationship? If you store those details, you can add a dependency on them later, replay your stream and have that detail as if you were always tracking those fields. Event sourcing is the ultimate schema update hack.
@pierre-antoineduchateau923
@pierre-antoineduchateau923 2 ай бұрын
Exactly ! I'm starting to use it to kickstart early-stage projects, where the business logic is still uncertain, but the app is already running in production. By storing wide enough contexts in the events, I know I'm not losing information. I can change queries without data migrations. At that stage, i'm not even using projections. Those come later, to optimise performance.
@marcom.
@marcom. 2 ай бұрын
One of the things that really sucks in event sourcing is the fact that we usually don't start to build a system with all its data from scratch. So you need some kind of special initial load treatments. And the second thing that sucks is the fact that event schemas usually evolve over time and you get more and more attributes that weren't included from the beginning. So you tend to make events very broad so you end up in some kind of event driven state transfer.
@serb1146
@serb1146 2 ай бұрын
Event versioning, upconverters, migrations, performance, when u have 5+ years project support... Nightmare.
@sykvel
@sykvel 2 ай бұрын
What the reason for having those broad event? It could be a new event or composition of objects that you include or not in event
@sykvel
@sykvel 2 ай бұрын
For initial migration good practice is having init event for each aggregate to set state
@lkazzzz
@lkazzzz 2 ай бұрын
You don't need all historical events about an aggregate before starting to apply event sourcing. All you need is to create an initial snapshot record of your current aggregate state, and then apply events afterwards.
@afailable
@afailable 2 ай бұрын
​@@serb1146 it's a trade off, because all the other options become nightmares for different reasons by the time you're into supporting a business system for 5+ years
@awright18
@awright18 2 ай бұрын
Good video! I've not yet done event sourcing in practice, but I have a question that I don't believe is typically talked about. It seems that projections "replay" events in order to derive the state, and I believe that replaying of events has to happen in code, so what happens when the shape of the events changes through different versions, it seems to code would need to be kept up to date to handle that problem for the set of data streams to remain "replayable". This isn't likely too much of an issue with a set of recent transactions, but seems like it could be a problem when wanting to surface historical data (several years old).
@michaldivismusic
@michaldivismusic 2 ай бұрын
I'd like to know as well.
@pierre-antoineduchateau923
@pierre-antoineduchateau923 2 ай бұрын
The past events are not supposed to change shape. Think of the event history as un append-only log. New events can have a different shape (ie different properties) but the old events in the history should not be overwritten. Projections have to be updated to handle new event shapes but have to still handle the old events. You can give the event payload a version number to help the code handle different shapes. That's the basic principle but of course, you can use a different strategy.
@michaldivismusic
@michaldivismusic 2 ай бұрын
@@pierre-antoineduchateau923 So in summary, try not to introduce breaking changes to the event structure, but if you have to, use versioning. Sounds good.
@RaVq91
@RaVq91 2 ай бұрын
@@michaldivismusic versioning of events sounds bad, you would have to keep adding new events instead of modifying old ones when you would like to add some extra properties to them OR do some branching in "apply" method. Who will know that in some long living storage we keep some events that not match current event structure.
@sykvel
@sykvel 2 ай бұрын
All your architectural mistakes baked into events consistently. Eventually or not:)
@FlaviusAspra
@FlaviusAspra 2 ай бұрын
ES is what you do together with CQRS, in order to really profit from ES. Systems in which you do ES without CQRS are systems not complex enough to have been following ES in the first place. Zoom out. The two are ombilical.
@CodeOpinion
@CodeOpinion 2 ай бұрын
I would say they are _often_ go hand in hand, but you there are absolutely use-cases of ES without CQRS or projections.
@dasfahrer8187
@dasfahrer8187 2 ай бұрын
Event sourcing just sounds like CRUD with extra steps that also just doesn't scale well as time goes on as you have to now potentially replay millions, billions or more transactions. So, to alleviate that overhead and time, if you're going to store "projections" then why do event sourcing at all? It seems like the better solution in most instances is to just do a typical relational database and then add a thin event layer on top for possibly some context, support, debugging and reporting.
@CodeOpinion
@CodeOpinion 2 ай бұрын
Using a series of events as way to persist how and why you got to a current state is natural in a lot of domains. If you try and apply CRUD thinking with event sourcing, you're going to end up in a horrible outcome. Most call this CRUD-sourcing. There's no point. The value is in when you're task-driven and in a domain or subdomain where recording the series of events that you can derive state has a lot of value. An example of this, while maybe not intuitive that I use in a lot of examples is inventory. You can project your GL from all of the events that happen in a subledger (invoices, receipts, etc), which is event sourced.
@majormartintibor
@majormartintibor 2 ай бұрын
What is Event Sourcing? Event Sourcing is architecting for tomorrows questions.
@sakesun
@sakesun 2 ай бұрын
Architecting for tomorrows troubles.
@obiwanjacobi
@obiwanjacobi 2 ай бұрын
Of course product YYZ987 should have been YYZ2112... 😅
@vincentcifello4435
@vincentcifello4435 2 ай бұрын
Thanks for the continued high quality information! Have you done a video about event sourcing and EDA? Something along the lines of a Process Manager/Saga. NServiceBus has that Saga integration tutorial. How do you see that working in an event sourced application? In several presentations, Adam Dymtruk states no Sagas or buses are needed. kzbin.info/www/bejne/eHnPfIOdjperrsk Thanks!
@CodeOpinion
@CodeOpinion 2 ай бұрын
I think I can see the angle, however I don't agree. Event Sourcing used as a way to record state and using them as notifications for workflows (saga) are very different things to me.
@vincentcifello4435
@vincentcifello4435 2 ай бұрын
​@@CodeOpinion Either my question was terrible or I am thinking about this incorrectly. Wouldn't it still be necessary to have workflows triggered by business events (messages) in an event sourced system?
@CodeOpinion
@CodeOpinion 2 ай бұрын
No, you could be event sourcing and not using workflows. You could not be event sourcing and using workflows driven by events. One is about state the other is about communication
@Tony-dp1rl
@Tony-dp1rl 2 ай бұрын
Almost Nobody needs Event Sourcing. Literally < 0.1% of systems would even benefit at all.
@CodeOpinion
@CodeOpinion 2 ай бұрын
My example of inventory is naturally event sourced. Your sub-ledger can pretty much generate your GL as a projection.
Keep your project structure simple!
15:08
CodeOpinion
Рет қаралды 15 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 90 МЛН
Always be more smart #shorts
00:32
Jin and Hattie
Рет қаралды 37 МЛН
Мы никогда не были так напуганы!
00:15
Аришнев
Рет қаралды 4 МЛН
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 141 МЛН
What Software Architects Do That Programmers DON'T
12:51
Thriving Technologist
Рет қаралды 103 М.
Debunking Kafka Top 5 Use Cases
10:02
CodeOpinion
Рет қаралды 14 М.
Why I Quit the Scrum Alliance
7:58
The Passionate Programmer
Рет қаралды 9 М.
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
"Serverless sucks!"... or does it?
7:27
CodeOpinion
Рет қаралды 7 М.
8 TypeScript Tips To Expand Your Mind (and improve your code)
10:54
This is Why Programming Is Hard For you
10:48
The Coding Sloth
Рет қаралды 656 М.
Beware! Anti-patterns in Event-Driven Architecture
10:34
CodeOpinion
Рет қаралды 13 М.
Event-Driven Architecture (EDA) vs Request/Response (RR)
12:00
Confluent
Рет қаралды 118 М.
This is why testing is hard
22:18
Web Dev Cody
Рет қаралды 7 М.
YOTAPHONE 2 - СПУСТЯ 10 ЛЕТ
15:13
ЗЕ МАККЕРС
Рет қаралды 112 М.
Simple maintenance. #leddisplay #ledscreen #ledwall #ledmodule #ledinstallation
0:19
LED Screen Factory-EagerLED
Рет қаралды 4,6 МЛН
CY Superb Earphone 👌 For Smartphone Handset
0:42
Tech Official
Рет қаралды 826 М.