*REST vs RPC

September 15, 2025

REST in brief

  • Resources, uniform interface (GET/POST/PUT/DELETE), cacheability, idempotence.
  • Great for public web APIs and CRUD over HTTP.

Example (REST)

# language-http
GET /users/123
Accept: application/json

HTTP/1.1 200 OK
{"id":"123","email":"u@example.com"}

RPC in brief

  • Strong contracts (IDLs), bi‑directional streaming, low overhead.
  • Great for service‑to‑service calls where latency and type safety matter.

Example (gRPC, proto)

// language-proto
service Users {
  rpc GetUser(GetUserRequest) returns (User) {}
}
message GetUserRequest { string id = 1; }
message User { string id = 1; string email = 2; }

When to choose which

  • Public external API → REST.
  • Internal high‑QPS, low‑latency, strong typing → gRPC.
  • Mixed is fine: REST at the edge, gRPC internally.

Gateway and translation

  • Use an API gateway to translate REST ↔ gRPC; generate clients from IDL.

Errors and versioning

  • REST: HTTP status codes + error schema; version via path or header.
  • gRPC: status codes (codes.Code) + rich error details; version via package name.

Code: Envoy REST ↔ gRPC bridge (sketch)

# language-yaml
typed_per_filter_config:
  envoy.filters.http.router:
    "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  envoy.filters.http.grpc_json_transcoder:
    "@type": type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder
    proto_descriptor: "users.pb"
    services: ["Users"]
    print_options: { add_whitespace: true }

Analogy

REST is like browsing a library by sections and book IDs. RPC is like calling the librarian and asking for a specific action.

FAQ

  • Can REST stream? Yes with SSE or chunked responses, but gRPC streaming is richer.
  • Is gRPC only HTTP/2? gRPC over HTTP/3 is available in modern stacks.

REST

  • Ressources, verbes HTTP, caching, idempotence.
  • Flexible, bien supporté, observabilité HTTP native.

RPC (gRPC/JSON-RPC)

  • Contrats stricts, schémas, streaming bi-directionnel, performances élevées.

Règle

Public API → REST; inter-services à fort débit/latence faible → gRPC; mix acceptable.