Implementing a notification system in a microsystem application
So far, the microbank application described at https://medium.com/@epatro/surviving-disruption-in-a-kubernetes-application-fd7a96d6ec09 is pretty much inert: it has an accountSystem service, some account services, a balance service, and a balanceValidator service, as described in the following picture:
Our goal, however, is to test the integrity of the system once I start generating transactions. As the architecture is using multiple components, these transactions will be distributed across many components.
Before I start generating these transactions, I want to focus on validating the bank’s integrity, using the components described in the following diagram:
As you’ll see in this diagram, the validation architecture has 3 components (in green):
- The balanceValidator Deployment checks the integrity of the system (summing up all the balances to match the expected overall balance) and exposes it as a REST API
- the validateBalance Job can be called from the command-line to invoke the balanceValidator Deployment and return success or failure
- Finally, the validateBalance CronJob calls the validateBalance Job periodically (every 5 minutes)
This architecture looks fine, but I am not going to check the result of the job constantly (I have other things to do in my life…). So I need a way to receive a notification when the validation fails.
I love Slack (https://slack.com/), so I am going to use the Slack SDK for Node.js, described at https://slackapi.github.io/node-slack-sdk/ to create a simple notification mechanism when the cron job validation mechanism fails.
The code to send a Slack message is very simple. You can see it at the following git repository: https://github.com/patrocinio/microbank/blob/master/src/validate-balance-job/1.2/notification.js
It’s pretty simple.
Happy notifications!