Chapter 3: gRPC vs REST vs GraphQL vs SOAP

You can't understand when to use gRPC without understanding what it's competing against. Let's do a deep, honest comparison.

Paradigm Differences

These four technologies represent fundamentally different philosophies:

AspectgRPCRESTGraphQLSOAP
ParadigmRPC (actions)Resources (nouns)Query languageRPC (actions)
Contract.proto (required)OpenAPI (optional)Schema (required)WSDL (required)
TransportHTTP/2HTTP/1.1 or 2HTTP (any)HTTP, SMTP, etc.
PayloadProtobuf (binary)JSON (text)JSON (text)XML (text)
StreamingNative (4 types)No (SSE workaround)SubscriptionsNo
BrowserVia gRPC-WebNativeNativeVia tooling
Code GenRequiredOptionalOptionalRequired

REST: The Incumbent

REST models everything as resources accessed via HTTP verbs:

// REST: resource-oriented
GET    /users/123          → Get user 123
POST   /users              → Create a user
PUT    /users/123          → Update user 123
DELETE /users/123          → Delete user 123
GET    /users/123/orders   → Get user's orders
// gRPC: action-oriented
GetUser(GetUserRequest{id: 123})
CreateUser(CreateUserRequest{name: "Alice"})
UpdateUser(UpdateUserRequest{id: 123, name: "Bob"})
DeleteUser(DeleteUserRequest{id: 123})
ListUserOrders(ListUserOrdersRequest{user_id: 123})

When REST Wins

When gRPC Wins Over REST

Performance: The Numbers

Real benchmarks (approximate, varies by payload):

MetricgRPC/ProtobufREST/JSONFactor
Serialization speed~150ns~1500ns10x faster
Message size (typical)~50 bytes~200 bytes4x smaller
Latency (p99)~0.5ms~2ms4x lower
Throughput (msg/sec)~500K~100K5x higher
Connection setup1 (multiplexed)N (or keep-alive)Much less overhead
ℹ️ Why the Performance Gap?

It's not just "binary vs text." The gap comes from multiple layers:

GraphQL: The Query Language

GraphQL (Facebook, 2015) solves a different problem: letting clients request exactly the data they need.

// GraphQL: client specifies what it wants
query {
  user(id: 123) {
    name
    email
    orders(last: 5) {
      id
      total
    }
  }
}

GraphQL vs gRPC

SOAP: The Enterprise Legacy

SOAP is still alive in banking, healthcare, and government. It's XML-based RPC with enterprise features:

gRPC replaces SOAP in new systems because it's faster, simpler, and achieves the same goals (strong contracts, code generation) without the XML bloat.

Decision Matrix

┌─────────────────────────────────────────┐ │ CHOOSING YOUR API STYLE │ └─────────────────────────────────────────┘ Is it browser-facing (public)? YES ──► Is the data shape flexible per client? YES ──► GraphQL NO ──► REST (+ OpenAPI) NO ──► Is it service-to-service? YES ──► Is streaming needed? YES ──► gRPC (no contest) NO ──► Is performance critical? YES ──► gRPC NO ──► REST or gRPC (team preference) NO ──► Is it legacy enterprise integration? YES ──► SOAP (if you must) NO ──► REST

The Hybrid Reality

In production systems, you rarely use just one. A typical architecture:

┌──────────┐ REST/GraphQL ┌──────────────┐ │ Browser │ ◄──────────────────── │ API Gateway │ │ Mobile │ │ (Envoy/Kong) │ └──────────┘ └──────┬───────┘ │ gRPC ┌─────────────┼─────────────┐ │ │ │ ┌─────▼────┐ ┌────▼─────┐ ┌───▼──────┐ │ Service A │ │ Service B │ │ Service C │ │ (Go) │ │ (C++) │ │ (Python) │ └─────┬────┘ └────┬─────┘ └───┬──────┘ │ gRPC │ gRPC │ └─────────────┼─────────────┘ │ ┌─────▼─────┐ │ Database │ └───────────┘

REST/GraphQL at the edge (for browsers), gRPC internally (for performance and type safety).

Common Misconceptions

⚠️ Myths Debunked

Telecom Perspective

In 3GPP 5G Service-Based Architecture:

Key Takeaways