Skip to content

JordyBaylac/nodejs-grpc-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJS gRPC example

This repo is a basic microservice architecture for a fake payment service application. The solution is composed by 3 services (1 gRPC server and 2 clients).

Use case

An api needs to check a given user has enough funds in its bank account. For that, the api will send an authorization request to a payment service. In that call, the api sends the credit card number and the amount to hold.

The service will reply with a status ("ACCEPTED" or "DECLINED") and an approval code, that works as the client's bank confirmation code. The whole system needs also to get track of successful authorizations, so that at the end of the day, a hotfile (a report) is submitted to an external company that will then move the funds and complete the settlement.

Proposed solution

We will develop 3 microservices:

  • One for the payment service bussiness.
  • One for the api bussines.
  • One for the hotfile process.

Phase 1: Microservice Architecture

Services description

payment

This service expose a gRPC server with two methods:

  • authorize: will simulate a credit card authorization.
  • recordSuccessfulAuth: will stream successfull authorization.

Check the protobuf service definition.

hotfile

This client get subscribed to the recordSuccessfulAuth method and will print a message if a successful authorization is received.

api

This client will send credit card authorization requests to the payment service every 4 seconds. A message will be printed with the authorization response received.

Result

Payment solution

Phase 2: Distributed tracing

After some analysis I decide to go with Opentracing and Jaeger.

Requeriments

1- Download Jaeger tracing from their website jaegertracing.io. 2- Run the Jaeger service and open http://localhost:16686. 3- Follow this NodeJS tutorial.

About

A nodejs gRPC example with three services

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published