A learning path ready to make your own.

REST vs GraphQL vs gRPC: Which API Style Should You Choose?

REST vs GraphQL vs gRPC — Concise Summary TL;DR: REST is simple, cache-friendly, and great for public HTTP/CRUD APIs. GraphQL gives clients precise control over the data shape and is ideal for rich/heterogeneous UIs but complicates caching and must guard query complexity. gRPC is the highest-performance option (binary protobuf + HTTP/2 streaming) and fits internal microservices and low-latency/high-throughput needs but needs more tooling and is harder for browsers to consume. Hybrid architectures (e.g., GraphQL gateway over REST/gRPC) are common. Background (very short) REST: Architectural style from Roy Fielding (2000). Resource-oriented, leverages HTTP semantics and caching. GraphQL: Query language/runtime from Facebook (2012→2015). Schema-driven, client-defined shape, supports queries/mutations/subscriptions. gRPC: Google-origin RPC (2015) using protobuf + HTTP/2. Designed for streaming, performance, and strong codegen. Core differences Style: REST = resource/HTTP verbs; GraphQL = single query endpoint with schema; gRPC = RPC methods defined in .proto. Transport & Serialization: REST/GraphQL usually JSON over HTTP; gRPC uses protobuf binary over HTTP/2 (gRPC-Web for browsers). Performance: gRPC typically best throughput/latency; REST/JSON higher bandwidth and parse cost; GraphQL can reduce round-trips but increases server resolver work. Streaming: gRPC = native streaming (client/server/bidi); GraphQL subscriptions via websockets; REST via chunked/SSE/websockets. Caching & CDN REST: native HTTP caching, CDN-friendly, easy to edge-cache. GraphQL: caching harder at HTTP level (query-shaped responses); mitigations: persisted queries, client normalization (Apollo), server/field caching. gRPC: not generally cacheable via standard HTTP caches; requires proxies/custom caches for edge behavior. Versioning & Schema Evolution REST: explicit versioning patterns (URI, headers, content negotiation). GraphQL: encourages non-breaking additive changes and deprecation of fields instead of versioning. gRPC/protobuf: schema evolution rules (numeric tags, optional fields); versioning via package/service names when needed. Security & Auth All: use TLS, OAuth2/JWT/mTLS as appropriate. REST: common bearer tokens, cookies, HTTP auth. GraphQL: same transport auth but needs field-level authorization and protections against expensive queries (depth/cost limits, persisted queries). gRPC: strong support for TLS/mTLS and metadata headers; works well for internal service auth. Error handling & observability REST: HTTP status codes + error bodies. GraphQL: errors array in response (often 200 + errors); requires conventions for codes and behavior. gRPC: rich status codes and metadata mapped to stubs. All benefit from OpenTelemetry/tracing, structured logs, metrics, and appropriate middleware/interceptors. Tooling & Developer Experience REST: massive ecosystem, OpenAPI/Swagger, easy testing with curl/browsers. GraphQL: excellent introspection tooling (GraphiQL/Apollo), typed clients, but learning curve around schema/resolvers and client caching. gRPC: strong codegen across languages via protoc, great for polyglot services; requires build tooling and proxies for browser use. When to choose which (practical guidance) Choose REST for public third‑party APIs, CDN/edge caching, simple CRUD resources, human-readable interoperability. Choose GraphQL for rich UIs, heterogeneous clients with varying data needs, rapid frontend iteration, and when aggregating multiple backends into one graph. Choose gRPC for internal microservices that need low latency/high throughput, streaming, and strong contract-first codegen across languages. Decision checklist Who are your clients? (public third-party → REST/GraphQL; controlled internal → gRPC) Need fine-grained client control over shape and fewer round-trips? → GraphQL Need streaming, high-performance RPCs, or multi-language stubs? → gRPC Need CDN/edge caching? → REST Browser-first consumer? → REST or GraphQL (gRPC-Web with proxy if using gRPC) Migration & hybrid patterns Common approach: keep REST for external APIs, use gRPC for internal services, and expose a GraphQL gateway/BFF for client-specific needs. Use adapters/gateways (Envoy, API Gateway, gRPC-JSON transcoder) and the strangler pattern to incrementally migrate. Persisted queries, BFFs, and federation can help integrate heterogeneous backends safely. Final thoughts There is no single best choice—each style has tradeoffs. Most successful systems combine approaches: REST for public, cacheable endpoints; GraphQL as a client-facing aggregation layer for UI flexibility; gRPC for high-performance internal RPCs and streaming. Choose based on client needs, caching/edge requirements, performance SLAs, and operational constraints, and prefer incremental migration via gateways and adapters. Further reading (high-level) Fielding — REST dissertation GraphQL.org — docs & spec gRPC.io — docs & tutorials OpenAPI, Apollo, Envoy, OpenTelemetry

Let the lesson walk with you.

Podcast

REST vs GraphQL vs gRPC: Which API Style Should You Choose? podcast

0:00-3:48

Follow the trail that experts already trust.

Resources

Turn quick sparks into lasting recall.

Flashcards

REST vs GraphQL vs gRPC: Which API Style Should You Choose? flashcards

16 cards

Question

Click to flip
Answer

Prove the idea before it slips away.

Quizzes

REST vs GraphQL vs gRPC: Which API Style Should You Choose? quiz

14 questions

Who introduced REST and formalized it in a doctoral dissertation in 2000?

Read deeper, connect wider, own the subject.

Deep Article

REST vs GraphQL vs gRPC: Which API Style Should You Choose? ================================================================

TL;DR


  • REST is simple, cache-friendly, human-readable, and works well for public HTTP APIs and CRUD-style resources.
  • GraphQL gives clients precise control over data shape, reduces over-/under-fetching, and is great for rich UIs and heterogeneous clients — but complicates caching and introduces query complexity considerations.
  • gRPC delivers the highest performance (binary protocol, HTTP/2, streaming) and a strong contract-first experience for internal microservices and high-throughput/low-latency services — but requires more tooling and can be harder to consume from browsers.

Choose REST for simplicity, caching, and public-facing APIs. Choose GraphQL when client-driven queries, rapid UI iteration, and schema evolution matter. Choose gRPC for high-performance internal RPC, streaming, and polyglot microservices where tight contracts and code generation are beneficial. Hybrid approaches are common: e.g., GraphQL gateway backed by REST/gRPC microservices.

Table of contents


  • Background and history
  • Core concepts (REST, GraphQL, gRPC)
  • Theoretical foundations and design constraints
  • Protocol, transport, serialization, and performance
  • Data fetching patterns: queries, mutations, streaming
  • Caching, CDN, and caching implications
  • Versioning and schema evolution
  • Authentication, authorization, and security
  • Error handling and observability
  • Tooling, ecosystem, and developer experience
  • Practical use cases and decision matrix
  • Migration strategies and hybrid architectures
  • Code examples (REST, GraphQL, gRPC)
  • Future directions
  • Recommendations and final checklist
  • Further reading

Background and history


  • REST (Representational State Transfer) — introduced by Roy Fielding in his 2000 doctoral dissertation. REST is an architectural style for distributed hypermedia systems built on top of HTTP; emphasis on resources, a uniform interface (verbs, URIs), statelessness, and hypermedia (HATEOAS) as optional guidance.
  • GraphQL — developed internally at Facebook around 2012, open-sourced in 2015. It is a query language and runtime for APIs that uses a strongly typed schema and lets clients request exactly the fields they need. Supports queries, mutations, and subscriptions.
  • gRPC — announced by Google in 2015, inspired by internal RPC systems like Stubby. It’s an RPC framework using Protocol Buffers (protobuf) as the Interface Definition Language (IDL) and data serialization format, and HTTP/2 for transport. Designed for high performance, streaming, and automatic code generation.

Core concepts


REST

  • Resource-oriented: endpoints correspond to resources (e.g., /users/123).
  • Uniform interface: use HTTP methods (GET, POST, PUT/PATCH, DELETE).
  • Stateless: servers do not store client context between requests.
  • Uses HTTP semantics: status codes, headers, caching, content negotiation.
  • Payloads usually JSON (text), XML sometimes.

GraphQL

  • Single endpoint (typically /graphql) that accepts queries and mutations.
  • Strongly typed schema describing types, fields, arguments, and resolvers.
  • Clients ask for exactly what they need; responses mirror the requested shape.
  • Subscriptions for real-time updates (often implemented with websockets).
  • Server resolves fields potentially from multiple backends (federation/mesh).
  • Introspection enables tooling and documentation (GraphiQL, Playground).

gRPC

  • RPC-oriented: define services and methods in .proto files.
  • Uses Protocol Buffers (protobuf) for IDL and binary serialization.
  • Transport over HTTP/2: multiplexed, full-duplex streams, flow control.
  • Supports unary RPCs and streaming: client-streaming, server-streaming, bidirectional streaming.
  • Strong client/server code-generation for many languages.
  • gRPC-Web adds browser compatibility (via proxy like Envoy).

Theoretical foundations and design constraints


  • REST emphasizes a uniform interface and leveraging HTTP semantics. It’s resource-centric and optimized for loose coupling and cacheability.
  • GraphQL is client-driven: it moves control of data retrieval to the client, enabling flexible shape/aggregation across multiple resources without multiple round trips.
  • gRPC is contract-first RPC: it assumes clear service definitions that generate strongly typed stubs, prioritizing performance, low-latency, and streaming semantics.

Transport, serialization, and performance


Transport

  • REST: usually HTTP/1.1 or HTTP/2; widely supported by browsers and CDNs.
  • GraphQL: normally HTTP POST over HTTP/1.1 or HTTP/2; can also run over websockets for subscriptions; uses text-based JSON responses.
  • gRPC: uses HTTP/2 natively (multiplexing, header compression, flow control). Browsers require gRPC-Web or a proxy because full gRPC over HTTP/2 is not natively available in many browsers.

Serialization

  • REST: typically JSON (text), human-readable, slow to parse and larger payloads.
  • GraphQL: JSON over HTTP (requests can be JSON payload or query string).
  • gRPC: Protobuf (binary) — compact, faster to serialize/deserialize.

Performance

  • gRPC tends to have the best throughput and lowest latency for equivalent payloads because of HTTP/2 and protobuf.
  • REST/JSON is generally slower and higher-bandwidth; performance penalty depends on payload size and parsing cost.
  • GraphQL adds server-side work (resolvers, nested fetching) which can increase latency, but it saves client-server round trips (reducing overall latency for complex data needs).
  • HTTP/2 features matter: multiplexing reduces head-of-line blocking vs HTTP/1.1, benefiting gRPC and HTTP/2-based REST.

Data fetching patterns


  • REST: one endpoint per resource; complex UIs may need multiple round-trips to aggregate data. Use patterns like embedding, query parameters, sparse fieldsets to mitigate.
  • GraphQL: single query can fetch multiple related objects in one request with a shape that exactly fits UI needs — reduces overfetching/underfetching.
  • gRPC: RPC calls map to methods — efficient for point-to-point interactions and streaming (real-time telemetry, logs, chat).

Streaming

  • REST: can use chunked transfer, SSE (server-sent events) for server → client streaming; websockets for bidirectional.
  • GraphQL: subscriptions commonly implemented with websockets; not standardized by HTTP layer.
  • gRPC: native streaming (client, server, bidi), excellent for real-time and high-throughput streaming use cases.

Caching, CDN, and caching implications


  • REST: natural fit for HTTP caching (Cache-Control, ETag, Last-Modified), CDNs, edge caching, and intermediaries.
  • GraphQL: harder to cache at HTTP level because responses depend on the query shape — tools exist:
  • Persisted queries (predefined queries referenced by a hash).
  • Response normalization at client-side caches (Apollo Client).
  • Field-level or resolver-level caching on server.
  • CDN caching possible for certain queries (GET with query string), but less straightforward.
  • gRPC: being HTTP/2+binary, not generally cacheable via standard HTTP caches; caching strategies are application-specific. gRPC responses seldom cached by CDNs; use edge proxies or custom caches when needed.

Versioning and schema evolution


  • REST: common patterns include URI versioning (/v1/users), header versioning, or content negotiation. Versioning is often explicit.
  • GraphQL: encourages schema evolution without explicit versions. Fields can be deprecated and removed after clients adapt. Additive changes are safe (adding new fields/types).
  • gRPC: protobuf supports evolving schemas: fields are identified by numeric tags; safe evolution rules (don’t reuse numeric tags, add optional fields). Service versioning via package names or new service names can be used.

Authentication, authorization, and security


  • Common for all:
  • Use TLS (HTTPS) for transport security.
  • OAuth2 / JWT / mTLS can be used depending on context.
  • REST:
  • OAuth2 bearer tokens, API keys in headers, cookie-based sessions (for browsers).
  • Leverages HTTP auth mechanisms.
  • GraphQL:
  • Uses same transport auth (bearer tokens) but authorization often needs field-level checks. Must protect costly queries (query depth/complexity limits, rate-limiting).
  • gRPC:
  • Supports TLS, mTLS, and metadata headers for auth tokens. Works well with mutual TLS for strong trust between services.

Error handling and observability


  • REST:
  • HTTP status codes (2xx success, 4xx client error, 5xx server error), plus error bodies for details.
  • Easy to map and reason about semantics.
  • GraphQL:
  • GraphQL responses often include an "errors" array in the payload; HTTP status is commonly 200 even when errors are present (but servers may return 400/500 for syntax/network errors).
  • Errors can be field-specific; must design a convention for error codes and client behavior.
  • gRPC:
  • Uses rich status codes (OK, NOTFOUND, INVALIDARGUMENT, UNAVAILABLE, etc.) in the protocol; also supports metadata for additional info.
  • Clear mapping to client stubs for ...

Ready to see the full tree?

Clone the preview to open the complete learning structure, practice tools, and generated study materials.