gRPC rocks build your first gRPC service(part 1)

Jimmy Zhao
2 min readApr 2, 2022

If you are a beginner, you must have been frustrated by the complexity of using protoc to build a gRPC service. The protoc compiler is powerful, but not newbee friendly. In this series of articles, I will explain how I build gRPC services in a toolkit called Skemaloop, in which you will find that building a gRPC service is quite easy.

How gRPC works

First, let me introduce the concepts of how gRPC works.

The gRPC framework provides a mechnism, in which the IDL(Interface Definition Language) can be used to define the service interface and messge types. The IDL will be used to seralize and deseralize the messages between server and clients. Developers can use protoc compiler to generate gRPC Server and gRPC Stub code boilerplate, and all the communciations are handled by the auto-generated code of the gRPC framework. There are many articles to introduce gRPC framework and the IDL of protobuf, I don`t want to cover the details here.

There are three steps to generate a gRPC server.

  1. create schema, which will be defined in protobuf.
  2. generate server and stub.
  3. add your business logic and start the service.

Create Schema

The offical site of Skemaloop provides the full process that you can follow to start your work. Click the try now button to start your journey.

You need login with your github account. After you login, you can start define your application interface.

The group is your github`s user account. You can create a new repository for the schema defintions, I will use my sandbox repository for this tutorial. If you want to create a hierachy you can define your path. I will leave to the default now.

The module and package is the hierachy of your schema, each module has multiple packages, and each packages have multiple serviecs definitions, in our case, multiple protobuf files.

I will call my service to SayHi.

Let`s create schema and continue. A schema definition is created as below.

syntax = "proto3";
//package code generated by schemakit DO NOT EDIT.
package sample_module.sample_package;


message HelloRequest {
string msg = 1;
}

message HelloReply {
string msg = 1;
string code = 2;
}

service SayHi {
rpc SayHello (HelloRequest) returns (HelloReply);
}

In next articile, I will explain the steps of how to create the server and stub code, and start the service.

--

--

Jimmy Zhao

A problem solver, product manager, and technologist