Architecture Patterns

REST, GraphQL & gRPC

● Intermediate ⏱ 13 min read architecture

REST, GraphQL, and gRPC are three dominant approaches for designing APIs between clients and services, or between services themselves. Each makes different trade-offs around flexibility, performance, type safety, and tooling. Choosing the right API style for each use case — public API, internal microservice communication, mobile client, real-time feed — is a recurring system design decision.

REST

REST (Representational State Transfer) is an architectural style built on HTTP. It treats everything as a resource identified by a URL, and uses standard HTTP methods to manipulate those resources.

Core constraints:

GET    /api/orders/42          → fetch order 42
POST   /api/orders             → create a new order
PATCH  /api/orders/42          → partially update order 42
DELETE /api/orders/42          → cancel order 42
GET    /api/orders/42/items    → fetch items for order 42

Strengths: Universal support — every language, framework, and tool speaks HTTP. Simple to understand, debug with curl, and document. HTTP caching works out of the box. Statelessness makes horizontal scaling trivial.

Weaknesses:

GraphQL

GraphQL is a query language for APIs and a runtime for executing those queries. Clients specify exactly what data they need — fields, nested relations, filters — in a single query. The server returns precisely that data, nothing more.

query {
  user(id: "42") {
    name
    email
    orders(last: 5) {
      id
      status
      total
      items {
        productName
        quantity
      }
    }
  }
}

This single query fetches the user, their 5 most recent orders, and the items in each order — data that would require 3+ REST calls and significant over-fetching.

Strengths:

Weaknesses:

gRPC

gRPC is a high-performance RPC framework developed by Google. Services are defined in Protocol Buffers (protobuf) — a language-agnostic, binary serialization format. The proto definition serves as both the service contract and the source of generated client/server code.

// orders.proto
service OrderService {
  rpc GetOrder (GetOrderRequest) returns (Order);
  rpc CreateOrder (CreateOrderRequest) returns (Order);
  rpc ListOrders (ListOrdersRequest) returns (stream Order);
  rpc TrackOrder (stream TrackRequest) returns (stream TrackEvent);
}

From this definition, protoc generates type-safe client and server stubs in Go, Java, Python, C++, and other languages. Clients call generated methods as if they were local function calls; the gRPC framework handles serialization, connection management, and transport over HTTP/2.

Strengths:

Weaknesses:

Side-by-Side Comparison

RESTGraphQLgRPC
ProtocolHTTP/1.1 or HTTP/2HTTP/1.1 or HTTP/2HTTP/2
Payload formatJSON (typically)JSONProtobuf (binary)
ContractOpenAPI (optional)GraphQL schema (required)Proto file (required)
Type safetyOptional (via OpenAPI codegen)Strong (schema-enforced)Strong (compile-time)
CachingNative HTTP cachingComplex; client-sideNo standard caching
StreamingSSE / chunked transferSubscriptions (WebSocket)Native bidirectional
Browser supportNativeNativeRequires gRPC-Web
PerformanceGoodGoodExcellent
DiscoverabilityGood (OpenAPI UI)Excellent (introspection)Moderate (grpcurl)

When to Use Each

Use REST when:

Use GraphQL when:

Use gRPC when:

Design Considerations