Event‐Driven Choreography - ganmath/learners GitHub Wiki
Let's delve into three critical concepts integral to event-driven systems: Event Notification, Event-Carried State Transfer, and Event Sourcing. These concepts play pivotal roles in the effective functioning and resilience of such architectures.
Detailed Concepts in Event-Driven Architecture
1. Event Notification
Definition: Event Notification is a pattern where a service publishes an event to notify other parts of the system about a change in its state without expecting a direct response.
Key Features:
- Asynchronous Communication: Events are emitted asynchronously, decoupling the event producer from consumers.
- Lightweight: Typically contains minimal data, just enough to signal a change has occurred.
Implementation in Retirement and Insurance Domain:
- When a customer updates their retirement account details (e.g., change in beneficiary or investment strategy), Microservice A (Customer Profile Management) emits an "Account Updated" event.
- Microservice B (Retirement Plan Management) and Microservice C (Insurance Policy Management) listen to these events. Based on the notification, they may initiate processes such as recalculating the expected retirement benefits or adjusting insurance coverage, respectively, but the event itself only informs them that a change has occurred, not the details of the change.
2. Event-Carried State Transfer
Definition: Event-Carried State Transfer involves events that carry all the data needed by a consumer to process them, reducing the need to query the producer for more information.
Key Features:
- Data-rich Events: Events include all necessary data for consumers.
- Reduces Dependency: Minimizes dependencies between services by eliminating the need for additional queries.
Implementation in Retirement and Insurance Domain:
- Suppose Microservice A creates a new customer profile. It publishes a "New Profile Created" event carrying detailed information such as customer ID, name, contact details, and initial retirement plan preferences.
- Microservice B, upon receiving this event, uses the carried data to directly set up a new retirement plan without needing to request more information from Microservice A. Similarly, Microservice C can use this information to issue an appropriate insurance policy immediately.
3. Event Sourcing
Definition: Event Sourcing is an architectural pattern where changes to application state are stored as a sequence of events. Instead of storing just the current state of data, you store the sequence of events that led to that state.
Key Features:
- Audit Trail: Provides a complete history of changes over time.
- Replayability: Allows applications to rebuild state or move to a previous state by replaying events.
Implementation in Retirement and Insurance Domain:
- Each microservice maintains a log of all changes as events. For example, any updates to customer profiles or retirement plans are stored as events in their respective databases.
- If a discrepancy arises, or if there is a need to audit actions (a common requirement in financial services), services can replay the events to reconstruct the state of the customer profile or retirement plan at any point in time.
- In disaster recovery scenarios, this approach can be used to restore the last known state by replaying the events up to that point.
Conclusion
Incorporating these three concepts into the choreographed microservice architecture significantly enhances the system's robustness, traceability, and autonomy. Event Notification ensures that services are promptly aware of changes. Event-Carried State Transfer boosts efficiency by moving necessary data along with notifications, reducing the need for subsequent data requests. Finally, Event Sourcing provides a powerful mechanism for history management and state recovery, which is crucial in highly regulated environments like Retirement and Insurance. This holistic approach to event management not only streamlines processes but also fortifies the architecture against failures and inconsistencies.