gRPC 101: The Simplest Guide You Will Ever Read
In last years, projects are mainly developed with “microservice architecture”. Since smaller things are much easier to handle, microservices look perfect to develop big and complex projects in a faster and more efficient way.
In the beginning, REST architecture were used to develop microservices but was it perfect enough? The answer is no because there are some points, which are about speed and efficiency, can be improved. Then, gRPC framework has come and it has been a game-changer!
What is gRPC?
gRPC is a modern open source high performance Remote Procedure Call (RPC) framework that can run in any environment.
It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.
- Simple service definition: Define your service using Protocol Buffers, a powerful binary serialization toolset and language.
- Start quickly and scale: Install runtime and dev environments with a single line and also scale to millions of RPCs per second with the framework.
- Works across languages and platforms: Automatically generate idiomatic client and server stubs for your service in a variety of languages and platforms.
- Bi-directional streaming and integrated auth: Bi-directional streaming and fully integrated pluggable authentication with HTTP/2-based transport.
Protocol Buffers or Proto
Protocol buffers are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured data — think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
gRPC vs REST
gRPC is roughly 7 times faster than REST when receiving data & roughly 10 times faster than REST when sending data for this specific payload. This is mainly due to the tight packing of the Protocol Buffers and the use of HTTP/2 by gRPC.
Disadvantages of gRPC
gRPC looks magical so far but there are some disadvantages of it unfortunately.
- Lack of consistent error handling
- Lack of developer tooling
- Lack of infrastructure and monitoring support outside of Google Kubernetes Engine (GKE)
- Limited insight into common practices
- Lack of edge caching
- Lack of support for additional content types
To conclude, REST has been around for 20 years and gRPC is not a replacement for REST. gRPC APIs can offer huge performance improvements and reduced response time as compared to REST APIs, but which approach to choose boils down to what fits your particular use case. You learnt about gRPC basics and you’ll learn how to develop your first gRPC project using python in next post! Stay tuned..