FSD Frontend System Design

Part I β€” The Pipes Β· Lesson 1.7

gRPC

In one lineBinary contracts over HTTP/2 β€” call a remote function like a local one, in a fraction of the bytes.

Where you've seen itNot in your browser tab, but one hop behind it β€” checkout β†’ inventory β†’ pricing, thousands of calls per second.

  • Time14 min
  • DiagramPayload size bar: JSON vs Protobuf
  • Chapter1 Β· Networking

Diagram

diagram
PAYLOAD SIZE β€” same user object

  JSON      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  312 bytes
  JSON+gzip β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                    138 bytes
  Protobuf  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                            74 bytes
            └── field names are replaced by numeric tags
diagram
CONTRACT-FIRST β€” one .proto generates both sides

            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚  user.proto  β”‚
            β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          protoc   β”‚   protoc
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β–Ό                        β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ TS clientβ”‚            β”‚ Go serverβ”‚
  β”‚  stub    β”‚            β”‚  stub    β”‚
  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β–²β”€β”€β”€β”€β”˜
       β”‚   binary over HTTP/2   β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       compile-time type safety on both ends
diagram
FOUR CALL SHAPES

  Unary            client ──► server ──►            one in, one out
  Server stream    client ──► server ══►            one in, many out
  Client stream    client ══► server ──►            many in, one out
  Bidirectional    client ══► server ══►            both stream freely

How it works

  1. Define messages and services in a .proto file β€” this is the contract.
  2. protoc generates typed client and server stubs in every language you use.
  3. Calls travel as binary Protobuf frames over HTTP/2, multiplexed on one connection.
  4. Streaming is native, in either or both directions.

Trade-offs

Use whenAvoid when
Service-to-service, high volumePublic API for unknown clients
Polyglot teams needing one contractYou want browsable URLs and curl
Streaming is a first-class needNo time to run a proxy

The browser catch: browsers can't speak raw gRPC β€” no access to HTTP/2 frames from JS. You need gRPC-Web plus an Envoy proxy, and that path loses client-streaming. For most frontends this is exactly why the browser talks REST or GraphQL to a BFF, and the BFF talks gRPC onward.

Interview angle

"Why don't we just use gRPC from the browser?"

  • The Fetch API gives no control over HTTP/2 framing, so raw gRPC is impossible.
  • gRPC-Web works but needs a translating proxy and drops client-side streaming.
  • The usual shape: browser β†’ BFF (REST/GraphQL) β†’ services (gRPC).

Recap

  • Contract-first, binary, HTTP/2, streaming built in.
  • ~4Γ— smaller payloads and generated types on both ends.
  • Lives behind your BFF, not in the browser.