← Back to blog

Beyond REST: Understanding gRPC for Service-to-Service Communication

A practical look at gRPC, how it works, and when it makes sense to use it in a distributed system.

  • Abhishek P P
  • 6 min read
  • #backend-engineering
  • #system-design

on this page / 7

REST is probably the first thing most of us reach for when building APIs. It is simple, widely supported, easy to debug, and works well for communication between clients and servers.

But as an application grows, things start getting a little different.

You might split a monolithic application into multiple services. One service handles users, another handles documents, and another takes care of notifications. These services need to communicate with each other, sometimes quite frequently.

REST can handle this. But is it always the best choice?

That's where gRPC comes into the picture.

What is gRPC?

gRPC is an open-source Remote Procedure Call (RPC) framework developed by Google.

The idea is straightforward: instead of making an HTTP request to an endpoint, a service can call a method exposed by another service.

For example, imagine a DocumentService needs information about a user. It can call a method such as GetUser() on the UserService.

The calling service doesn't need to know how the other service handles the request internally. It only needs to know the method and the data expected by it.

gRPC uses HTTP/2 for transport and Protocol Buffers (Protobuf) as its default interface definition language and serialization format.

Let's look at what that means in practice.

Protocol Buffers: Defining the Contract

When services communicate, both sides need to agree on the structure of the data being exchanged.

With REST, we commonly use JSON. With gRPC, we generally define the contract using a .proto file.

For example:

syntax = "proto3";

service UserService {
  rpc GetUser (GetUserRequest) returns (UserResponse);
}

message GetUserRequest {
  string id = 1;
}

message UserResponse {
  string id = 1;
  string name = 2;
  string email = 3;
}

This file defines a service called UserService and a method called GetUser.

The method accepts a GetUserRequest and returns a UserResponse.

The interesting part is that this contract can be used to generate client and server code in different programming languages. That means a Node.js service can communicate with a Go service without both teams having to manually implement the same request and response structures.

It also makes the contract explicit. You know what a method expects and what it returns before you even look at its implementation.

Why does gRPC use HTTP/2?

One of the reasons gRPC works well for service-to-service communication is its use of HTTP/2.

Unlike HTTP/1.1, HTTP/2 supports multiplexing, which allows multiple streams of data to share a single connection. It also uses binary framing and header compression through HPACK.

In practical terms, this helps reduce connection overhead and makes it possible to handle multiple concurrent requests more efficiently.

A small clarification: REST APIs can also run over HTTP/2. So HTTP/2 itself isn't exclusive to gRPC. The difference comes from how gRPC uses HTTP/2 along with Protobuf, generated code, and its RPC model.

Streaming in gRPC

This is one of the features I find particularly interesting.

Most REST APIs follow a request-response pattern: the client sends a request and waits for a response.

gRPC supports four communication patterns:

1. Unary RPC

The most familiar pattern. The client sends one request and receives one response.

Client  ───── Request ─────> Server
Client  <──── Response ───── Server

2. Server Streaming

The client sends one request, and the server sends multiple responses over the same call.

Client  ───── Request ─────> Server
Client  <──── Response 1 ─── Server
Client  <──── Response 2 ─── Server
Client  <──── Response 3 ─── Server

This can be useful when a client needs to receive a continuous stream of updates.

3. Client Streaming

The client sends multiple messages, and the server responds once after receiving them.

Client  ───── Request 1 ────> Server
Client  ───── Request 2 ────> Server
Client  ───── Request 3 ────> Server
Client  <──── Response ───── Server

4. Bidirectional Streaming

Both the client and server can send multiple messages independently over the same connection.

Client  ───── Message 1 ────> Server
Client  <──── Message 1 ──── Server
Client  ───── Message 2 ────> Server
Client  <──── Message 2 ──── Server

This is useful for scenarios where both sides need to exchange data continuously.

REST vs gRPC

They solve similar communication problems, but they approach them differently.

AreaRESTgRPC
Communication styleResource-basedProcedure-based
TransportCommonly HTTP/1.1 or HTTP/2HTTP/2
Data formatUsually JSONProtobuf by default
ContractOpenAPI is commonly used.proto files
Code generationOptionalCommonly used
StreamingPossible, but depends on the approachBuilt-in support
Browser supportDirect and straightforwardUsually requires gRPC-Web or a proxy

This doesn't mean gRPC is automatically better than REST. REST is still a very good choice for public APIs, frontend communication, and applications where simplicity and broad compatibility matter.

gRPC becomes particularly useful when services need efficient, strongly typed communication with well-defined contracts.

Where would you use gRPC?

Consider an application with an API Gateway and several internal services.

A frontend sends an HTTP request to the API Gateway. The gateway handles authentication, validation, and other cross-cutting concerns. It then communicates with the required internal services.

One possible setup looks like this:

                 Frontend
                     |
                     | HTTP / REST
                     |
                API Gateway
                     |
          +----------+----------+
          |          |          |
         gRPC       gRPC       gRPC
          |          |          |
      User       Document   Notification
     Service      Service     Service

The frontend doesn't need to know anything about the internal communication. It continues using regular HTTP APIs, while the backend services communicate through gRPC.

This is a common architectural approach, not a rule. You should choose the communication method based on the requirements of each service.

Final thoughts

I don't think the question should be "Should I use REST or gRPC?"

Both have their place.

REST is simple, familiar, and works very well for client-facing APIs. gRPC offers a different set of advantages when services need to communicate with each other through strongly defined contracts, efficient serialization, and streaming.

The important thing is understanding the problem before choosing the technology.

After all, adding another technology to an architecture doesn't automatically make it better. Sometimes it just gives you another thing to maintain.