Understanding Node Js based Microservices in Blockchain -Part II

Shyam Pratap Singh
Nov 16, 2019 · 3 min read

In the previous article, we have seen the basics of Seneca js microservice and its important features. I have provided the below link for the same.

Now, I will focus much more on the real development of basic microservices and its integration with API as well as intercommunication of different Microservices using Mesh Network.

Use Case:

I have tried simulating Hyperledger Fabric Tx flow through three modules i.e Transaction microservice, Orderer Microservice and Commit Microservice and tried showing their network communication and data sharing.

Transaction Microservice receives data from API which is sent by the user and sign to the transaction and send to the Orderer microservice for creating a simple block.

Orderer microservice creates a block and publish the data to commit microservice and now commit microservice store the transaction data into a ledger file and upon completion of operation, it will inform to Orderer Microservice and thus Orderer will inform to Transaction microservices and at the last API get the response, which completes the full cycle.

Code Set up :

Git clone from this which basically does the setup of express server, create default routes and has other files related to the above use case.Follow the instruction as mentioned on README.md file

Important things to understand :

Bootstrapping Mesh Network:

Base Microservice

It basically initiates a mesh network that’s the reason it has isbase:true. There is monitor functionality which shows the real-time status of all microservices which has joined the mesh network.

Monitoring Microservices

Pattern Identification and Plugins:

Each Microservice is identified by pattern name e.g role:transaction,cmd:createTransaction, role:ordere,cmd:createBlock instead of calling through service discovery registry and when a new microservice join the network all other microservices will get to know its pattern through gossip protocol.

Plugins are used to bundle many functionalities of the same family e.g Under Transaction Microservice, findTransaction, createTransaction, updateTransaction could be plugins functionality expose by Transaction Microservice. Each plugin function will have a unique pattern. e.g


Integrating API to Microservice :

We need to create an instance of Seneca-mesh inside controller api and call the pattern of the desired microservice. e.g

controller api

this.add and this.act:

this is an instance of Seneca which is used to host a service or call a service. add is used for hosting service and act is used for calling a service (client service) followed by pattern.

Intercommunication of Microservices :

Data is always shared in the form of the object, each data set has transport object embedded by client service which keeps track of who has sent request, timestamp and origin of the message.

Aim of the use case and code is to provide the basic template to start to writing small microservices and understand intercommunication.

In the next part, I will try to migrate Fabric Node js SDK code to small modular microservice which looks like enrollment microservice, Transaction microservice, utility microservice which shows data relevant to block, channel or chaincode.



Microservice Template :

Seneca JS :

Shyam Pratap Singh

Written by

I am a Blockchain Developer working in Elm Information Security Company,Riyadh in Research and Innovation center. I love to explore new technologies.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade