Communication Protocols

Systems need a language to talk. Compare REST (The Text Message), gRPC (The High-Speed Binary), and WebSockets (The Phone Call). Learn when to Poll and when to Push.

What you will learn

  • Compare REST vs gRPC (JSON vs Binary)
  • Understand why GraphQL is meant for Frontends, not Backends
  • Master the Real-Time Spectrum: Short Polling, Long Polling, SSE, WebSockets
  • Decide between Unidirectional (SSE) vs Bidirectional (WebSockets)

If Microservices are the cities, Protocols are the roads and languages they use to trade. You wouldn't send a shipping container via a bicycle messenger. You wouldn't write a casual text message in formal legal Latin.

Choosing the right protocol is about Efficiency vs Flexibility.


"The Postcard."

  • Format: JSON (usually).
  • Behavior: Stateless. "Get me user 1." "Here is user 1."
  • Pros: Universal. Every language, browser, and toaster understands JSON.
  • Cons: Verbose. <name>John</name> or {"name": "John"} takes up space.
  • The Trap: Over-fetching.
    • You want: User's Name.
    • API returns: Name, Age, Address, SSN, Favorite Color... (Wasted Bandwidth).

"The High-Speed Private Line."

  • Format: Protobuf (Binary).
  • Behavior: It looks like you are calling a local function getUser(1), but it runs on a server.
  • Pros:
    1. Binary: {"id": 100} in JSON is 9 bytes. In Protobuf, it's 3 bytes. (3x Smaller).
    2. Strict: You need a .proto contract. No more "I thought that field was a string?".
    3. HTTP/2: Multiplexing (Multiple requests over 1 connection).
  • Cons: Browsers hate it (You need gRPC-Web proxy). Humans can't read it.
  • Use Case: Internal Service-to-Service communication.

Create a free account to read the full chapter — advanced chapters, progress tracking, and quizzes are free with sign-up.