Skip to content

gRPC

What gRPC is, why choose it over REST, and its four API types.

1 min read

References

What is gRPC?

gRPC is a modern open-source high-performance Remote Procedure Call (RPC) framework developed by Google. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication.

Why gRPC over REST?

Protobuf instead of JSON/XML

REST uses JSON for sending and receiving messages. JSON is flexible, text-based and human-readable but it is not fast enough or light-weight enough for transmitting data between systems. gRPC uses Protobuf(protocol buffers) messaging format which is faster and more efficient for data transmission

First-class support for code generation

REST needs third-party tools to generate the code for API calls. gRPC comes with an in-built protoc compiler which provides the code generation features by default.

Built on HTTP 2

REST is built on HTTP 1.1 which uses a request-response model of communication. gRPC uses HTTP2 so that it supports client-response communication and bidirectional streaming.

Works across languages and platforms

Since the code can be generated for any language, it is easy to create micro-services in any language to interact with each other

Communication across languages

4 Types of API in gRPC

  1. Unary
  2. Server Streaming
  3. Client Streaming
  4. Bidirectional

4 Types of API in gRPC

Following is an example of the four types of APIs. You can understand it further when we are implementing the sample.

service GreetService {
// Unary
rpc Greet(GreetRequest) returns (GreetResponse) {};
// Streaming server
rpc GreetManyTimes(GreetManyTimesRequest) returns (stream GreetManyTimesResponse) {};
// Streaming client
rpc LongGreet(stream LongGreetRequest) returns (LongGreetResponse) {};
// Bidirectional streaming
rpc GreetAll(stream GreetAllRequest) returns (stream GreetAllResponse) {};
}

Related articles

2 min read

Strava

Uploading GPS tracks to Strava from the command line using the Strava API.

  • APIs & Integration
1 min read

Google Sheets JSON Access

Reading a public Google Sheet as JSON over HTTP, without an API key.

  • APIs & Integration
1 min read

Caching

The top caching strategies — cache-aside, read-through, write-through, write-back — compared.

  • Architecture & Process

Type to search the whole site.