Overview
gRPC is a remote procedure call framework, through this blog we will understand factors regarding gRPC like what is gRPC, why it is popular and we thought this blog we will understand some keywords that gRPC contains like stubs,microservices. So let’s Start through our first initial intro of gRPC.
What is gRPC?
gRPC is a new open-source and high-performance Remote procedure call framework that we can run in any environment. It allows us to run written code on the local computer, even though it may be executed on another computer.
Now the question arises in our mind is what are APIs and how does it work?
Overview of API
API stands for Application Program Interface as its name suggests it is an interface between different services like it will work as a communicator between different services, like if we discuss one example of API through the hotel, we will be one service and kitchen of hotel is the second service so if we want to order some food it will be hard for us to directly communicate with kooks so what we will do we use one communicator as an API and those are waiters we will give order to them they take the food from the kitchen and serve us. This is the actual concept of API’s.
There are some different protocols that we can use to communicate with different services like,
Different Protocols:
- RPC (Remote procedure call)
- SOAP (Simple object access protocols)
- Rest (Representational state transfer)
gRPC is updated protocols by Google with higher performance, interoperability, security, productivity, etc. Some people think gRPC is a totally new concept developed by Google. and there is no protocol that contains this kind of feature. So this is wrong because gRPC is not a new concept. But gRPC was developed in 2015, before that developer is also using one of the older versions of this protocol and that is RPC.
RPC is a form of Client-Server communication that uses a function call rather than an HTTP call.
See this image gRPC does replicate this architectural style of client-server communication, via function calls. So I think now you can see that architecture is the same as RPC so gRPC is not a new concept but we can say it is adopted from this old technique and improve the performance and security, productivity and then they make it more popular in the last few years.
So now the question is: What is the strength that makes gRPC so popular?
What is the strength that makes gRPC so popular?
There are some reasons that make gRPC popular like Compare to other protocols Abstraction is easy like in this it is a just function call. The second thing it supports a lot of languages like Go, C++, Java, Python, C#, etc. Third is code generation, in this, they used a proto compiler to generate the .proto file. So due to this, it will auto-generate server-side skeletons (Like request, response file) and client-side networks stubs which saves significant development time in applications with various services.So this is the strength we can say that makes gRPC popular and one more thing besides this all gRPC is popular because Microservices are very popular.
Microservices is too popular today but still let me give just an intro to what microservices is.
What is microservices
So it is an architecture that divides different services into small parts as its name suggests Micro-Services, so several services in different programming languages we can run on a single server. In which we can do, service to service interaction as well.
So in this gRPC helps the most by providing capability and support to solve the typical issue that arises in this kind of situation when we want to use a different kind of services.
Now let’s see gRPC architecture…
gRPC architecture
The working mechanism of gRPC contains 5 steps:
As we discussed that the client-server communication so it is common that two things will be this only means the first step of this mechanism will be Client and Last will Server.
Afterwords gRPC contains stubs on both sides to pack and unpack the param. so one will be client stub and the second is server stub so now one remaining step is RPC runtime that is the middle communicator between this all steps so steps are:
- Client
- Client Stub
- RPC Runtime
- Server Stub
- Server
In many blogs, you can find more than 5 steps but it’s common because as we talk before, gRPC communicate with the local kernel first then goes for a public server kernel so might be this step increases the count otherwise these are the common steps.
What is a stub?
It is one type of interface between RPC clients. The stub includes Connecting, Sending/Receiving steaming or non-streaming requests, canceling calls, and so on.
Maybe some have one question: In SOAP we are passing in XML format, in Rest we are passing in JSON format so what we are passing in gRPC makes it more secure compared to others?
So as we know in soap and rest we are passing our data in XML and JSON file that is readable data means a human can read the things while in gRPC we are passing the data through Protocol Buffers as we discussed before proto file so what will happen we will pass the same data but in encoding form, like if I am passing int a and int b they will pass this two param in encoding form now at the server end stub will decode this package and response the data as per the requirements.
Development ServicesGet Expert Assistance
Conclusion
Whatever we have discussed today is the surface of what gRPC is and how it works. Maybe some of you have doubt like in which particular situations I have to use this different protocols so it totally depends on project requirements. Like if the project contains small data we can go for Rest but if the project contains a large number of data then security is one of the important concerns so at that time we have to go with gRPC as it contains encoding and decoding features so this is all about gRPC.
Happy Learning .