Microservice with Golang, NodeJS and gRPC (Part 1)

Tram Ho


  • Nowadays, the use of microservice architecture is more common than ever, and the benefits are unquestionable. I am participating in such a project and want to share it with you.
  • This article I will divide into 2 parts, and simply display each hello world (the article is used temporarily examples of grpc but will change for me to present from a-> z for you to understand, and you often see how it is more complicated than PHP’s echo "hello world" (yaoming))
  • Part 1: Create a core server (I use golang, usually a place that uses general data) and a go-server (connect to core server)
  • Part 2: Use a child node server to connect to the core server => So the skills in this use will be: golang, nodejs and grpc . A few points to know:
  • The article is based on the actual project I did
  • proto (grpc) will be created a separate github, then imported into other projects (actual project, in the framework of this article, use only a basic way)

Let’s do it

The first is to create a file helloworld.proto (if you do not know what the .proto extension is, please find out here ).

proto / helloworld.proto

So to compile this proto we have protobuf and the command to that compiler is

You can see more installation instructions here. After compiling we will have a directory like this.

  • Now we will set up the servers

Core Server

The first step we will create go module with go mod init core_server command, then of course will create a file go.mod .

Create the file main.go

Then you run the command go run main.go and wait to be the go server .

Go Server

Similar to the core server , in the go server directory there is also a proto directory (but only using service client), which also creates the go module .

  • Create the main.go directory

Then run the command go run main.go and wait for the result

  • Here is the result shown on the core server side
  • Here is the output of the go server after running the run command


  • That’s it, I will show you how to connect between golang-golang servers via grpc. In the next part, I will show you how to connect between golang-nodejs.
  • Print every hello world that is like that, but with large systems, often having new functions like facebook, or many teams implementing in many different languages, this is a very cool thing. The following post uses nodejs as an example (you can use it with php, ruby ​​…)
Share the news now

Source : Viblo