Up and Running with gRPC
Tags: grpc, webdev, node, go
Published: 2022-01-04 05:00:18

Hello, Today I am going to talk about gRPC.

A high performance, open source universal RPC framework by google.

Now its part of the Cloud Foundation (CNCF)
 
### Let's Understand RPC!

An RPC is a Remote Procedure Call. Google introduce gRPC, But Common Object Request Broker Architecture (CORBA) had RPC before!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dzau45x1dedvgqsiysp.png)

In this above example, you see right side a server code written any other language and left client code calling server function. Okay, Lets consider server written in python we want to call this function from another language, what we will do we simply create a rest api then call that api using other language client. Now think 🤔 is not it cool? if we could call that function nativity like we call functions. I know that will be amazing using RPC we can do that easily.

Here is an another example from grpc.io website. You can see gRPC server code is written in C++, and gRPC Stubs Or Clients are written in different languages. Here as Stubs they are using Ruby and Java Android client. Do not worry I will share complete example end of the season.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/21nzr4lfgo9w9g80zjbd.png)
 
### When we choose gRPC?

- When we wants to build microservices
- Wants to communicate between cross-languages services
- Planning to build distributed services
- Needs client & server streaming 
- Needs Http/2 based transport protocol

[Read more](https://grpc.io/)

### gRPC vs REST

**REST**
REST uses HTTP/1.1 protocol through the JSON or XML messaging format. Common http verbs like {GET, POST, PUT, DELETE etc}

**gRPC**
gRPC uses HTTP/2 protocol through Protocol buffer. Methods {unary, server-streaming, client-streaming and bi-directional call}. It offers language independence support 11 programming languages.

### gRPC methods/operations

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bqfxnjmf153ecdzasb06.png)
 
### What is Protocol Buffer

- Protocol buffer are language language-neutral, platform-neutral extensible mechanism for serializing structured data
- Code generated for any language
- Very convenient for transporting a lot of data
- Data is binary and efficiently serialized (small payloads)
- Support Java, Go, Python, NodeJs, Objective-C, C++ and more with proto3 language version.

[Read more](https://developers.google.com/protocol-buffers)

### gRPC vs Rest

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gt7haylwgnqg5kl0yxcu.png)

### Sample gRPC Based Micro-service Architecture 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3zl24tnet7489lipkztt.png)

[Complete gRPC server & clients check that Demo Codebase](https://github.com/mesadhan/grpc-codelab)

## Congratulations

I hope we learn something exciting about gRPC framework. Thanks for time & passion. Feel free to ask me anything.


Say Hi to me on [Twitter](https://twitter.com/eng_sadhan), [Linkedin](https://www.linkedin.com/in/csesadhan/), and [Medium](https://medium.com/@csesadhan) where I keep on sharing interesting updates.