Web / API Series

⚡ Understanding gRPC vs REST From a Top 1% Perspective — gRPC Really Is Fast, but It Carries a Structural Constraint: It Can't Talk Directly to a Browser

Introduction

This article is part of the Top 1% Series Complete Article Guide, and article 5.2 in the Web/API Series.

Prerequisite Knowledge

Getting the Big Picture

gRPC is an RPC framework developed by Google that serializes data in a binary format called Protocol Buffers (protobuf) and communicates using HTTP/2 multiplexing. Compared to REST, which is predominantly JSON over HTTP/1.1, gRPC achieves faster communication thanks to its binary format and its ability to process multiple requests concurrently over a single TCP connection. But browser JavaScript carries a structural constraint — it cannot read the HTTP/2 trailers that gRPC uses to convey a call’s final status — so a browser cannot call a gRPC server directly.

graph TB
    subgraph "Service-to-Service Communication (gRPC)"
    S1["Service A"] -->|"gRPC (protobuf + HTTP/2)"| S2["Service B"]
    end
    subgraph "A Call From a Browser"
    B["Browser JavaScript"] -->|"gRPC-Web"| P["Translating proxy (e.g. Envoy)"]
    P -->|"gRPC"| S3["gRPC server"]
    end

Deep Dive Into the Fundamentals

Why Can’t a Browser Speak gRPC Directly?

gRPC conveys a call’s final success or failure status through HTTP/2 “trailers” — a special header-like region sent after the body. But while the browser’s Fetch API exposes ordinary headers via response.headers, the response.trailers property, despite having existed in the spec for years, isn’t implemented in any major browser. Because of this constraint, browser JavaScript code simply cannot handle gRPC communication directly.

gRPC-Web: a Solution That Inserts a Translating Proxy

gRPC-Web is a separate protocol that makes gRPC usable from a browser by re-embedding the information that would normally be sent as trailers into a special frame at the end of the response body. This requires a configuration with a translating proxy, such as Envoy, sitting in between to convert gRPC-Web requests into native gRPC — adding one more layer of infrastructure complexity compared to pure gRPC. And gRPC-Web doesn’t support client-side streaming or bidirectional streaming at all — only server-side streaming is supported.

Note: schema-first design is another major difference

gRPC enforces a schema-first design, where an API’s types and structure are strictly defined up front in a .proto file. This is a similar idea to GraphQL’s schema, but with gRPC, both client and server code are automatically generated from that schema, giving it the advantage that a type mismatch is more likely to be caught at compile time.

What a Pro Sees Here (Top 1% Understanding)

“Fast” Means Something Different Depending on Where You Use It

gRPC genuinely is fast, but enjoying that speed for a publicly offered API communicating with a browser requires accepting the added complexity of gRPC-Web and a translating proxy. For service-to-service communication that never goes through a browser — internal microservice communication, for instance — this constraint doesn’t arise at all. Never judge solely by the evaluation “gRPC is fast” — always first check “is the client calling this API a browser, or some other service.” This is the perspective a top-1% engineer carries. In real-world practice, a common combination is widely adopted: gRPC for internal service-to-service communication, and REST or GraphQL for externally exposed APIs.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

  1. Trying to call a gRPC server directly from a browser and it fails: Check whether a gRPC-Web client library and a translating proxy like Envoy are configured.
  2. Client-side streaming doesn’t work via gRPC-Web: Confirm that gRPC-Web’s spec doesn’t support client-side streaming or bidirectional streaming.
  3. After a gRPC schema change, client and server types no longer match: Check whether you’ve regenerated the code for both the client and server after updating the .proto file.

Summary

Takeaways to Apply Today

  1. When considering adopting gRPC, always first check whether the caller is a browser or some other service.
  2. When using gRPC for a browser-facing use case, check gRPC-Web’s functional limitations (its streaming restrictions) ahead of time.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).