- DriverService — find nearby cars
- PricingService — compute fare estimate
- LocationService — stream driver GPS coordinates
- NotificationService — notify the driver
RESTful example: simple, human‑readable, but verbose
With a RESTful API, TripService might POST to DriverService:- Endpoint:
POST /drivers/nearby - Payload: JSON with the rider’s location and search radius
- Response: a JSON array of nearby drivers

gRPC + Protobuf: compact, typed, and efficient
gRPC typically uses Protocol Buffers (Protobuf) instead of JSON. The same response with 50 drivers is usually much smaller in binary Protobuf form — often only a couple of kilobytes instead of ten. Because gRPC runs over HTTP/2, it benefits from features like header compression (HPACK) which reduces repeated metadata overhead across a connection after the initial handshake. At large scale (think Uber or Lyft), these bandwidth and CPU savings matter.
API contracts and tooling
- RESTful APIs often rely on documentation (OpenAPI specs, Confluence pages). Docs can drift from code if not kept in sync.
- gRPC centralizes the contract in a
.protofile. Services and messages (for example,DriverServicewithFindNearby(Location) returns (stream Driver)) are defined in one place and compiled into generated client/server stubs.
- For strongly typed languages, contract changes surface at compile time.
- Teams generate consistent client libraries from the same source-of-truth
.protofiles, reducing mismatch risk.
Streaming and real‑time updates
A common use case in the ride app is streaming GPS coordinates from LocationService to the rider every few seconds. Approaches:- REST: poll the endpoint frequently (inefficient) or use WebSockets (a separate protocol and stack from your REST endpoints).
- gRPC: native support for streaming (server-, client-, and bidirectional). LocationService can open a long‑lived stream and push updates efficiently over the same HTTP/2 connection.

Browsers don’t expose the raw bidirectional HTTP/2 streams that “raw” gRPC relies on, so browser JavaScript cannot speak plain gRPC directly. Use bridging options such as
gRPC-Web or deploy a proxy/gateway if you need browser clients to access gRPC backends. Many teams still expose REST for public/client‑facing APIs while using gRPC internally.Best practice: Use the right tool for the job. Choose gRPC for high‑performance, internal service-to-service calls and streaming. Use REST/HTTP+JSON for public APIs or when human readability and broad compatibility matter.
Quick comparison table
When to choose which
-
Use REST when:
- You need wide compatibility with browsers and third‑party clients.
- Human‑readable payloads and simplicity/debuggability matter.
- You expose a public API or want to support many clients without generated stubs.
-
Use gRPC when:
- You need efficient, low‑latency service‑to‑service communication.
- You want strong typing and auto‑generated client/server code.
- You require native streaming (e.g., real‑time location updates).
Links and references
- gRPC
- Protocol Buffers (Protobuf)
- OpenAPI Specification
- HTTP/2 specification
- gRPC‑Web
- WebSockets API (MDN)