Skip to content

REST vs. RPC

One-Liner

Two different approaches to designing APIs: REST focuses on resources and standard methods, while RPC focuses on actions and custom methods.

What It Is

  • REST (Representational State Transfer): An architectural style that uses standard HTTP methods (GET, POST, PUT, DELETE) to act on resources (e.g., /users/123). It’s centered around the “nouns” of a system.
  • RPC (Remote Procedure Call): A style where a client calls a function or procedure on a remote server as if it were a local call. It’s centered around the “verbs” of a system (e.g., getUser, updateUser).

Why It Exists

To provide different paradigms for service-to-service communication. REST is great for public-facing, resource-oriented APIs, while RPC is often preferred for high-performance, internal microservices communication.

How It Works

  • REST: Uses the full HTTP protocol, including status codes and headers, to convey meaning.
  • RPC: Often uses a custom protocol, or a modern framework like gRPC which uses HTTP/2.

Tradeoffs

REST

  • Pros: Standardized, self-describing, cacheable, great for public APIs.
  • Cons: Can be chatty, may not be the most performant, less strict contract between client and server.

RPC

  • Pros: High performance, strict contract (often using a schema like Protocol Buffers), good for streaming.
  • Cons: Less standardized, can be tightly coupled, not as human-readable or explorable as REST.

Failure Modes

  • REST: Ambiguous API design if not following conventions.
  • RPC: Breaking changes to the schema can easily break clients if not managed carefully.

Interview Traps

  • Claiming one is universally better than the other.
  • Not knowing about modern RPC frameworks like gRPC and their advantages.

Real-World Usage

  • REST: Most public web APIs (e.g., GitHub, Twitter).
  • RPC: Internal microservices at companies like Google (gRPC) and Facebook (Thrift).

Anti-Patterns

  • “RPC over HTTP” where a RESTful API is just a tunnel for custom methods in the URL (e.g., /api.php?action=getUser).
  • Using RPC for a public API that needs to be easily explored and integrated by third parties.
  • gRPC
  • Protocol Buffers
  • API Design