Captures the memory of something interesting which affects the domain
Captures interesting events in the domain that cause multiple reactions and those multiple reactions are unknown or may change over the period of time.
Many things happen in the Domain, Many Transactins and Domain Model State Changes occur in the Domain Model/DB.
But we have to analyze, this Change to the DM state is significant, this may cause other actions to provoke.
Silent Domain Model Changes
Reactive Domain Model Changes.
There are two extremes to which Domain Events can be used.
Without Event Sourcing
======================
We just need Events and Event Processing Queues. We log Events just to process them. We do not store the Events themselves.
With Event Sourcing
==========================
We use Domain Events, Event Logs, Event Processing all is there.
But additionally, we save those events as well.
Why We Need Event Sourcing.
================================
Normally we just apply the change to the Database.
We just update the database with new state.
We do not save the Change Set.
Drawback is we cannot revert back to any initial position.
We cannot analyze the Recent Change Set happened inside the system.
We cannot do the AI, Predictions, Data Analysis, Trends.
We must save both Changes and the Final State of the DB.
Sync. Methods are one way to update the State of Domain Model in the DB. Fire and Wait, Complex Error Recovery, Locking, Slow, No Change Log is stored. Response Code is fixed, To change Response Code we need to Change the Application.
If error recover fails, DB can go in inconsistent state.
Async. Methods are another way to do so. Fire and Forget, Simple Error Recovery, Response Code will be done in Handler, No Locking, Fast, No Change Log is stored. Response Code is fixed, To change Response Code we need to Change the Application.
If error recover fails, DB can go in inconsistent state.
Simple Domain Events are extensions to the Async. Methods in a very neat clean way. Fire and Forget, Simple Error Recovery, Response Code will be done in Handler, No Locking, Fast, No Change Log is stored. Response Code is dynamic and can be changed at run time or deployment time. Response code can be configured at deployment time. No need to change the application code.If error recover fails, DB can go in inconsistent state.
Domain Events with Event Sourcing are extensions to the Simple Domain Events in a very neat clean way. Fire and Forget, Simple Error Recovery, Response Code will be done in Handler, No Locking, Fast, Change Log is stored. Response Code is dynamic and can be changed at run time or deployment time. Response code can be configured at deployment time. No need to change the application code.If error recover fails,
Less chances that DB can go in inconsistent state because we have Event Logs, Event Queue, Event processor.
==================================
Subject is Entity or Aggregate Root whose state is going to be changed in response of Event being raised.
It could be the Entity or Aggregate Root whose State Change is to be modeled as Event
One Event is related to one Subject ????
One Subject can have many Events True
One Event has One Event Type ?????
One Event Type is related to many Events????
Event is the Use Case or Transaction or Requirement level thing or Verb that happens in the system. It corresponds to the Method in programming. It is a big concept. One Method Call could result in multiple method calls and multiple DB updates. In the same way One Event can cause multiple Event Types and multiple DB updates or work.
Event Response code could contain any thing.
Direct DB update
Send Email
Send Notification
Log the Event
Call another Web API Service that cause update DB, Email, Notification
In case of Web Application these events are done in the momentous object graphs.
Event Type ??????
I go to Babur's for a meal on Tuesday, and pay by credit card.
Make payment by the Credit Card is a use case that effects the state of Domain Model in DB and we might be interested to propagate that as an event and we want to do multiple things in the response.
An important transaction in the business and many stakeholders are affected by this. There could be events in the system those are less importannt and have very small impact on the system.
High Impact Events/Use Cases are modeled as Domain Event
This might be modeled as an event, UC or Requiremnt
event type is 'make purchase' or Class that Model the Event/Data
whose subject is my credit card, Entity affected by Event in DB
and whose occurred date is Tuesday.
If Babur's uses an old manual system and doesn't transmit the transaction until Friday, the noticed date would be Friday.
Things happen. Not all of them are interesting,
UC happen some are low impact and other are high impact and important
some may be worth recording but don't provoke a reaction.
Some events are need to be stored in event sotre but no reaction code is there.
Some events are needed ot be recorded in DB but does not cause great Reaction Code, Reaction Scope is limited.
The most interesting ones cause a reaction. Many systems need to react to interesting events.
High Impact Use Cases are done as Domain Event. These Events are recorded and as well as there is Reaction Code against the Events.
Often you need to know why a system reacts in the way it did.
Why we need to model such UC as the Events
Rather than simple Methods Calls or Async Method Calls, these UC are modeled as Events. This approach has many advantages.
Events those cause changes can be stored as well. We and go back to any previous state of the DB, and analyze when this bad thing has happened.
It is like the Code First Migrations of EF. All Change Set is saved. All Schema Changes are kept as migrations.
We have our final state of the DB SChema as well. We can revert Db Schema to any previous state.
Same is the case with the Version Control Software. Final State of Code bases. Changes to the Code bases. Revert Code base to previous state.
By funneling inputs to a system into streams of Domain Event you can keep a record of all the inputs to a system.
keep the record of all Events/Method Calls to the System
kepp record of all Method Calls those case update DB and also save the parameters.
Method Call == Event
Method Parameters == Event Type/ Event Data Container
This helps you organize your processing logic, and also allows you to keep an audit log of the inputs to the system.
How it Works