DEV Community

Cover image for Hello "gRPC" world
Hardik Shakya
Hardik Shakya

Posted on

Hello "gRPC" world

Introduction

This article aims to give an introduction to the gRPC world. We might play with actual code and implementations in future parts of this series, but for now let's just say "Hello" to this gRPC thing.

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, authentication and much more.

When to use gRPC ?

Here are some use cases when you need gRPC:

  • Real-time communication via bi-directional streaming.
  • Efficient inter-service communication in microservices.
  • Low latency and high throughput communication.
  • Polyglot environments.

Concepts of gRPC

Let's discuss some key concepts of gRPC.

Protocol buffers

Protocol buffers provide a language and platform-neutral extensible mechanism for serializing structured data in a forward and backward-compatible way. It's like JSON, except it's smaller and faster, and it generates native language bindings.

Service definition

Like many RPC systems, gRPC is based on the idea of defining a service and specifying the methods that can be called remotely with their parameters and return types. gRPC uses protocol buffers as the Interface Definition Language (IDL) for describing both the service interface and the structure of the payload messages.

Let's discuss some Pros and Cons

Here are some advantages and disadvantages of gRPC I have found in some articles:

Pros:

  • Lightweight and efficient.
  • High performance.
  • Built-in code generation support.
  • Bi-directional streaming.

Cons:

  • Relatively new compared to some famous API technologies REST and GraphQL.
  • Limited browser support.
  • Steeper learning curve.
  • Not human readable.

It's time for some "vs" game

Here, we will going to compare gRPC in two different section. Let's see how it performed in this two comparison game.

1. Data Streaming via gRPC vs MQTT vs Websockets:

Test:
Tried to send 10000 messages each contains 2KB size of message.

Result:

gRPC MQTT Websockets
38 ms 1330 ms 127 ms

Above results clearly shows that gRPC wins because of persistent connection and protobuf data format, which is lightweight.

2. API technologies via REST vs GraphQL vs gRPC:

Test:

  • Will it cause tight coupling?
  • How chatty (distinct API calls to get needed information) are the APIs?
  • What's the performance like?
  • How complex is it to integrate?
  • How well does the caching work?
  • Built-in tooling and code generation?
  • What's API discoverability like?

Result:

Type Coupling Chattiness Performance Complexity Caching Codegen Discoverability Versioning
REST Low High Good Medium Great Bad Good Easy
GraphQL Medium Low Good High Custom Good Good Custom
gRPC High Medium Great Low Custom Great Bad Hard

Conclusion

In this article, an overview of gRPC was given, with its some basic key concepts. Also, we did some comparison and got to know how it's actually performing against it's competitors.

However, it will demand more effort, so it will be the subject of another article.

Hope you found this article useful and little informative!

References

Latest comments (0)