https://github.com/damiancipolat/node-event-saga
An implementation of the SAGA pattern using event driven architecture, created within a single nodejs process.
https://github.com/damiancipolat/node-event-saga
architecture event-driven-architecture nodejs patterns-design saga saga-pattern
Last synced: 10 months ago
JSON representation
An implementation of the SAGA pattern using event driven architecture, created within a single nodejs process.
- Host: GitHub
- URL: https://github.com/damiancipolat/node-event-saga
- Owner: damiancipolat
- License: mit
- Created: 2020-02-24T05:52:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T18:32:57.000Z (over 3 years ago)
- Last Synced: 2025-04-02T07:11:46.856Z (about 1 year ago)
- Topics: architecture, event-driven-architecture, nodejs, patterns-design, saga, saga-pattern
- Language: JavaScript
- Size: 199 KB
- Stars: 11
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node-event-saga
A custom implementation of the **SAGA** pattern using event driven architecture, created within a single nodejs process.
In this scenario the event bus is a **Event Emitter** into a nodejs process, in more complex project the bus will be sqs or sns in AWS.
This project are only node.js **modules** and a **scaffolding** for more realistics scenarios will be necesary to add an api rest interface.
The Fail feature or the saga is only present in some events, in a real situation all the request should have it.
### **Events diagram**
In this diagram I show how a transaction is done through different messages. For each operation two types of SUCCESS and FAIL messages are issued, in the case of FAIL status updates are applied to maintain consistency.

#### Note:
For this example, I will use for mock the Order, Notification and Payment service the web mocky.io to make fake but real request.
### Events dictionary
Events name with description.
- **ORDER_CREATED**: Initial event of the payment flow.
- **ORDER_CREATED_SUCCESS**: Sucess order creation event.
- **ORDER_CREATED_FAIL**: Order creaation error.
- **PAYMENT_FAIL**: Error in process payment.
- **PAYMENT_SUCCESS**: Payment succeffull.
- **FLOW_END**: Send email with the bill and finish the flow.
#### To run:
```sh
npm install
node app.js
```
#### Readings:
- https://microservices.io/patterns/data/saga.html
- https://itnext.io/effectively-communicate-between-microservices-de7252ba2f3c
- https://developers.redhat.com/blog/2018/10/01/patterns-for-distributed-transactions-within-a-microservices-architecture/
- https://blog.couchbase.com/saga-pattern-implement-business-transactions-using-microservices-part/
- https://medium.com/@ijayakantha/microservices-the-saga-pattern-for-distributed-transactions-c489d0ac0247
- https://itnext.io/microservices-architecture-an-implementation-of-saga-pattern-dbbe5d881c78
- https://dzone.com/articles/distributed-sagas-for-microservices