Home/Learn/System Design/REST vs gRPC

REST vs gRPC

Intermediate
Communication Patterns

REST uses HTTP/1.1 with JSON for simple, human-readable APIs. gRPC uses HTTP/2 with Protocol Buffers for high-performance, strongly-typed, streaming-capable inter-service communication.

Overview

REST (Representational State Transfer) is the dominant API style for web services. It uses standard HTTP methods (GET, POST, PUT, DELETE), JSON payloads, and URL-based resource identification. REST is simple, well-understood, browser-friendly, and works with any HTTP client. gRPC is a high-performance RPC framework from Google. It uses HTTP/2 for multiplexing and streaming, Protocol Buffers (protobuf) for compact binary serialisation, and code-generated client/server stubs for type safety. gRPC is 2-10x faster than REST for inter-service communication due to binary encoding, header compression, and connection multiplexing. However, it is not browser-native (needs grpc-web), harder to debug (binary), and requires schema management (.proto files). Use REST for public APIs and browser clients; use gRPC for internal microservice communication where performance matters.

REST — Resource-Oriented

REST models the world as resources (nouns) accessed via standard HTTP verbs. JSON is the standard format. It is simple, cacheable, and universally supported.

HTTP + JSON — REST API example
// REST API design
// Resource: /api/v1/orders
// Verbs: GET (read), POST (create), PUT (update), DELETE (remove)

// GET /api/v1/orders/123
// Response: 200 OK
{
  "id": "123",
  "userId": "u-42",
  "items": [{ "productId": "p-1", "qty": 2 }],
  "total": 99.99,
  "status": "SHIPPED"
}

// POST /api/v1/orders
// Request body: { "userId": "u-42", "items": [...] }
// Response: 201 Created

// Pros: simple, human-readable, browser-native, cacheable
// Cons: over-fetching (get all fields), N+1 API calls,
//       no streaming, text-based JSON is verbose

gRPC — High-Performance RPC

gRPC uses .proto files to define services and messages. Code generators produce type-safe client and server stubs. HTTP/2 enables multiplexing and bidirectional streaming.

Protobuf + Java — gRPC service definition
// order_service.proto — schema definition
syntax = "proto3";
package orders;

service OrderService {
  rpc GetOrder(GetOrderRequest) returns (Order);
  rpc CreateOrder(CreateOrderRequest) returns (Order);
  rpc StreamOrders(StreamRequest) returns (stream Order);  // server streaming
}

message Order {
  string id = 1;
  string user_id = 2;
  repeated OrderItem items = 3;
  double total = 4;
  string status = 5;
}

message GetOrderRequest { string id = 1; }

// Generated Java client usage
OrderServiceGrpc.OrderServiceBlockingStub stub =
    OrderServiceGrpc.newBlockingStub(channel);
Order order = stub.getOrder(
    GetOrderRequest.newBuilder().setId("123").build()
);

// Pros: 2-10x faster than REST, type-safe, streaming, code-gen
// Cons: not browser-native, binary (harder to debug), schema mgmt

When to Choose Which

Use REST for public/external APIs, browser clients, and simple CRUD. Use gRPC for internal microservice-to-microservice calls, real-time streaming, and polyglot environments where code generation helps.

Conceptual — REST vs gRPC decision matrix
// Decision matrix
//
// Factor              | REST          | gRPC
// ────────────────────────────────────────────
// Payload format      | JSON (text)   | Protobuf (binary)
// Protocol            | HTTP/1.1      | HTTP/2
// Performance         | Moderate      | 2-10x faster
// Streaming           | Limited (SSE) | Native (4 modes)
// Browser support     | ✅ Native     | ⚠️ grpc-web needed
// Human readability   | ✅ Easy       | ❌ Binary
// Type safety         | ❌ Manual     | ✅ Code-generated
// Caching             | ✅ HTTP cache | ❌ Not cacheable
// Tooling (Postman)   | ✅ Rich       | ⚠️ Limited
//
// Common pattern in production:
// External: REST (public API) or GraphQL (mobile/web)
// Internal: gRPC between microservices
// Gateway: REST→gRPC translation at API gateway

Key Points to Remember

  • 1REST: HTTP/1.1 + JSON, simple, browser-friendly, cacheable — best for public APIs.
  • 2gRPC: HTTP/2 + Protobuf, fast, type-safe, streaming — best for internal service-to-service calls.
  • 3gRPC is 2-10x faster than REST due to binary encoding, HTTP/2 multiplexing, and header compression.
  • 4gRPC supports 4 streaming modes: unary, server streaming, client streaming, bidirectional.
  • 5Common pattern: REST for external APIs, gRPC for internal microservice communication.

Interview Questions

Sign in to ask Aria
1

What are the key differences between REST and gRPC?

EasyTCS
2

Why is gRPC faster than REST?

MediumAmazon
3

When would you choose REST over gRPC for internal services?

MediumGoogle
4

How does gRPC handle streaming and why is it useful?

MediumFlipkart
5

Design the communication layer for a system with 50 microservices — which protocols and why?

HardNetflix

Ask Aria about REST vs gRPC

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…