Build Real-World Microservices with gRPC – InApps is an article under the topic Software Development Many of you are most interested in today !! Today, let’s learn Build Real-World Microservices with gRPC – InApps in today’s post !

Read more about Build Real-World Microservices with gRPC – InApps at Wikipedia

You can find content about Build Real-World Microservices with gRPC – InApps from the Wikipedia website

Kasun Indrasiri

Kasun is a key member of WSO2’s architecture team that drives development efforts for the company’s integration platform. Previously, he was involved in developing WSO2 Enterprise Service Bus as a product lead. He has authored the book Beginning WSO2 ESB and co-authored Microservices for the Enterprise. He is an elected member of the Apache Software Foundation and a project management committee member and a committer for the Apache Synapse open source ESB project. Kasun has provided technology consulting on numerous customer engagements by helping to successfully design and implement solutions for integrating web services, REST, SAP and various other technologies.

Early microservices implementations leveraged Representational State Transfer (REST) architecture as the de-facto communication technology. However, RESTful services are often useful for external-facing services, which are directly exposed to consumers. As they are based on conventional text-based messaging (JSON, XML, CVS over HTTP, etc.), which are optimized for humans, these are not ideal choices for internal service-to-service communication.

Rather, using a text-based messaging protocol, we can leverage a binary protocol that is optimized for inter-service communication. The Cloud Native Computing Foundation’s gRPC (gRPC Remote Procedure Call) is an ideal choice for inter-service communication since it uses protocol buffers as the binary data interchange format for inter-service communication.

When we build multiple microservices with different technologies and programming languages, it is important to have a standard way to define service interfaces and underlying message interchange formats. gRPC offers a clean and powerful way to specify service contracts using protocol buffers. Therefore, gRPC is probably the most viable solution for building communication between internal microservices.

In this article, we will take a closer look at why gRPC is a great choice for building inter-microservices communication.

Fundamentals of gRPC

With gRPC, a customer can directly call methods on a server application on a different machine as if it were a local object.  gRPC is based on the foundations of conventional Remote Procedure Call (RPC) technology but implemented on top of the modern technology stacks such as HTTP2, protocol buffers etc. to ensure maximum interoperability.

gRPC natively supports the ability to define a service contract using the gRPC Interface Definition Language (IDL). So, as part of the service definition, you can specify the methods that can be invoked remotely and the data structure of the parameters and return types.

Figure 1. illustrates the use of gRPC with an online retail application as part of an inventory and product-search service. The contract for the Inventory service is defined using gRPC IDL, which is specified in the inventory.proto file. So, a developer for the inventory service should first define all the business capabilities using the service and then generate the service side skeleton code from the proto file. Similarly, the client side code (stub) can be generated using the same proto file.

Figure 1

Since gRPC is programming-language agnostic, you can use heterogeneous languages to build services and clients. In this example, we have generated the Inventory service code using Ballerina ( and the client-side code using Java. You can try out this example using this source code on GitHub.

Read More:   How Go Is Effective For Sysadmins – InApps Technology 2022

The service contract of the inventory(inventory.proto) is shown below.

The service contract is easy to understand and can be shared between the client and the service. If there’s any change to the service contract, both the service and client side code has to be regenerated.

For example, the following code snippet shows the generated code of the gRPC service for Ballerina. For each operation that we have in the gRPC service definition, the corresponding Ballerina code is generated. (Ballerina provides out-of-the-box capabilities to generate the service or client code with “ballerina grpc –input inventory.proto –output service-skeleton –mode service” or “ballerina grpc –input inventory.proto –output bal-client –mode client”).

For the client side, the product-search service, which is a Java (Spring Boot) service, is again generated from the gRPC service definition of the Inventory service. You can use the maven plugin to generate the client stub for the Spring Boot/Java service (the client code is embedded in the Spring Boot service). The client code that invokes the generated client stub is shown below.

Communication Under the Hood

When the client invokes the service, the client-side gRPC library uses the protocol buffer and marshals the remote procedure call, which is then sent over HTTP2. On the server side, the request is un-marshaled and the respective procedure invocation is executed using protocol buffers. The response follows a similar execution flow from the server to the client.

The main advantage of developing services and clients with gRPC is that your service code or client side code doesn’t need to worry about parsing JSON or similar text-based message formats (within the code or implicitly inside the underlying libraries such as Jackson, which is hidden from service code). What comes in the wire is a binary format, which is unmarshalled into an object. Also, having first-class support for defining a service interface via an IDL is a powerful feature when we have to deal with multiple microservices and ensure and maintain interoperability.

A Pragmatic Microservices Use Case with gRPC

Microservices-based applications consist of multiple services and are built with a variety of programming languages. Based on the business use case, you can pick the most appropriate technology to build your service. gRPC plays a very important role in this polyglot architecture. For example, let’s further extend our online retail use case for something more realistic. As shown in Figure 2, product-search service communicates with multiple other services, which are built using gRPC as the communication protocol. So, we can define the service contract for each service:inventory, electronics items, clothing items, etc. Now, if you want to foster a polyglot architecture, you can generate service skeletons using different implementation technologies.

Figure 2 illustrates the inventory service with Ballerina lang, the electronics service with Golang and the clothing service with Vert.x (Java). The client side can also generate a stub for each of these service contracts.

Figure 2

A closer look at the microservices communication styles in Figure 2 shows gRPC is used for all internal communication, while the external-facing communication can be based on REST or GraphQL. When we use REST for external-facing communication, most of the external clients can consume the service as an API (leveraging API definition technologies such as Open API) because most of the external clients will know how to communicate with an HTTP RESTful service. Also, we can use technologies such as GraphQL to allow consumers to query the service based on the specific client needs, which cannot be facilitated with gRPC.

Therefore, as a general practice, we can use gRPC for all synchronous communications between internal microservices. Other synchronous messaging technologies such as RESTful services and GraphQL are more suitable for external-facing services.

Feature image via Pixabay.


List of Keywords users find our article on Google:

wso2 esb
wso2 integration
wso2 api manager
wso2 support pricing
wso2 support services
microservices with wso2
wso2 enterprise integrator
wso2 microservices architecture
microservices in wso2
support wso2
wso2 support
beginning wso2 esb
wso2 kubernetes
what is wso2
wso2 api management
buffering wikipedia
mfe complete data prtxn
wso2 github
ats real companies
graphql with spring boot – foundation i
atlassian jira service management pricing
real recognize real clothing
sap solution manager jira integration
linkedin electronics foundations: fundamentals
grpc github
protobuf net
wso2 team
bal import
hire designers
java jira client
microservices wso2
jira inventory plugin
proto io templates
jira plugin custom field searcher
restful web service listener
grpc java
hire remote xml developers
vertx microservices
jira sap solution manager integration
sap microservices
spring boot grpc
google protobuf github
com atlassian jira maven
de facto clothing wikipedia
vert.x grpc
ballerina lang
spring boot communication between microservices
jira service management inventory
wikipedia buffer
wso2 enterprise integrator reviews
intégration de facebook leads avec jira service desk
wso2 data services
wso2 source code
buffer wikipedia
jira custom listener on status change
wso2 products
this article is a stub you can help by expanding it
vertx github
wso2 api manager pricing
business blueprint wikipedia
“io core procedure”
apache wso2
atlassian jira api java
jira service management
github protobuf
wso2 api manager architecture
jira custom field repeats
binary solutions wikipedia
wso2 api
hood de trustpilot
google protobuf message
hire remote graphql developers
jira custom boolean field
vertx clothing
wso2 is
sap commerce integration api xml
binary search wikipedia
build wikipedia trustpilot
jira java rest client
structure plugin jira
protobuf embedded message
graphql with spring boot – foundation i online course
maven protobuf
atlassian jira structure
intégration de facebook leads avec buffer
apache synapse
jira custom field external data
jira search syntax
sap data quality microservices
google protobuf
grpc google
real caller public
api management wso2
protobuf text format
spring cloud contract
idl string
jira to service now integration text formatting
wso2 app cloud
vertx spring
apache maven wikipedia
grpc communication between microservices
Rate this post

Let’s create the next big thing together!

Coming together is a beginning. Keeping together is progress. Working together is success.

Let’s talk

Get a custom Proposal

Please fill in your information and your need to get a suitable solution.

    You need to enter your email to download

      Success. Downloading...