Event Driven
Pattern 1: Event Notification
E.g. Customer management system emits an event object to a well-known place (e.g. event queue) and insurance quoting system can listen for that event.
E.g. GUI elements
Advantage
- It allows many other systems to hook up to the event stream very easily and those systems do not need to know or care about the system emitting the event.
- Decouple receiver from sender
Disadvantage
- You don’t know what behaviours you will trigger
Pattern 2: Event-carried State Transfer
Pattern 1 的進化版
A less common pattern
E.g. Customer management system emits an event object with all data which downstream systems need, and downstream systems copy a part of data they are going to use
Advantage
- It allows many other systems to hook up to the event stream very easily and those systems do not need to know or care about the system emitting the event.
- Decouple receiver from sender
- Reduced load on supplier
Disadvantage
- Consistency problem
Pattern 3: Event Sourcing
We preserve important state-changed events in the “log” instead of preserving states in an application
E.g. Git, accounting system
Asynchrony
Asynchrony can be used for event sourcing but not necessary
E.g.
- commit at local => synchrony
- local + shared repo (e.g. Github) => asynchrony
Advantage
- Great for audit
- Great for debugging (time traveling)
- To have historic state and alternative state
- Save data in memory (?
Disadvantage
- 對大多數人來說是一個陌生的系統 => 不易共同作業
- To talk to external system gets more complicated
Pattern 4: CQRS
- Command Query Responsibility Segregation
- Basic idea: Separate the components that read (dealing read) and write (dealing update) to the permanent store.
References
v8 engine (emitter), see node implementation