Let's "Go" and build an Application with gRPC

Tharaka Romesh
Level Up Coding
Published in
8 min readOct 8, 2021

--

REST (REpresentational State Transfer) architecture has become the go-to method to build applications like web applications, microservices. REST provide provides a set of guidelines on how to create an API. The REST architecture generally relies on HTTP protocol. An API will qualify as "RESTful" when it full fill the following.

  • A uniform interface
  • Client-server independence
  • Stateless
  • Cacheable
  • Layered

Although REST was introduced to address drawbacks of SOAP (which uses RPC under the hood), REST returned a lot of metadata, which was the main reason it couldn't replace lightweight RPC, which led to the introduction of new or improved technologies like gRPC and GraphQL.

gRPC (Google Remote Procedure Call) is a high-performance, open-source universal RPC framework that Google developed to achieve high-speed communication between microservices. gRPC has Protobuf (protocol buffers) by default which would format or serialize the messages to a specific format that will be highly-packed, highly efficient data. So it is evident that lightweight RPC like gRPC will be ideal for some use-cased. In this article, let's dive in and see the benefits of using gRPC and building an application using Go, one of the most famous languages to build microservices.

What is RPC?

RPC (Remote Procedure Call) is one of the oldest architectures available. RPC allows you to invoke a function on a remote server in a particular format and receive a response in the same format. In a way, the concept of an RPC API is similar to that of a REST API. RPC APIs define the rules and methods that a client could interact with. The client then submits calls with some arguments to invoke these methods. You can find these arguments in the query string. An RPC call POST /deletePokemon will have a query string that will look like this {"id": 2 } and a Typical REST will have DELETE /pokemon/delete/2.

Exploring gRPC

gRPC can be considered a successor to RPC, which is light in weight. Google developed it to communicate between microservices and other systems that need to interact. There are several benefits of using gRPC.

--

--

I’m a Full Stack Developer at Anyfin AB who is passionate about new technologies and writing tech blogs. Reach me at tharakaromesh@gmail.com