LearnThatStack Ace your next interview
API Design · question
Question 15 of 110

What are Protocol Buffers and why does gRPC use them?

beginner
← All API Design questions
Re-explain

Protocol Buffers (protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. gRPC uses protobuf for several reasons:

  • Efficiency: Binary serialization is faster and more compact than JSON/XML
  • Type Safety: Strongly typed schema prevents runtime errors
  • Code Generation: Automatically generates client and server code
  • Language Agnostic: Works across different programming languages
  • Schema Evolution: Supports backward and forward compatibility

Example protobuf definition:

syntax = "proto3";

message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
}

service UserService {
  rpc GetUser(UserRequest) returns (User);
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for API Design One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • What changes to a .proto file break existing clients, and how do you remove a field safely? Field numbers, not names, go on the wire. Never change or reuse a number, mark removed ones reserved, and know old readers skip unknown fields.
  • Why is a protobuf message smaller than the same data sent as JSON? Each field is tagged by its number instead of its name, integers use varint encoding, and the reader needs the schema to decode the bytes.
  • How do you get client and server code from a .proto file, and why does that matter? protoc with a language plugin writes message classes, client stubs and server base classes, so both sides compile against one contract.
  • When would you choose JSON over protobuf for an API? Browser clients, public APIs and reading payloads by eye favor JSON. Say what protobuf costs there, like needing gRPC-Web and a shared schema.
  • In proto3, how do you tell a field that was never set from one set to zero or empty? Scalars default to zero values that are not sent on the wire. Mention the optional keyword or wrapper types for explicit presence.

What you can say

  1. Protocol Buffers are Google's language-neutral format for structured data. You define the data once in a schema, and it serializes to compact binary.
  2. In a .proto file you declare messages with a type and a number for each field, plus services with their RPC methods, and a compiler generates code from that file.
  3. gRPC uses protobuf for a few reasons. The binary encoding is smaller and faster to parse than JSON or XML, and the strong typing catches mismatched data before runtime.
  4. Code generation gives you client and server code in many languages from that one file, so a Go server and a Java client share the same contract.
  5. It also supports backward and forward compatibility, as long as you add fields with new numbers and never reuse the old ones.
  6. The cost is that you can't read the payload by eye and browsers can't call gRPC directly, so for public or browser-facing APIs I'd usually still use JSON.

Weak answers to avoid

  • Recites the benefit list with no mechanism Saying 'efficient' and 'type safe' sounds memorized. Explain one mechanism, like field numbers replacing field names on the wire.
  • Thinks field names identify data on the wire The field number is what gets encoded. Renaming is safe, but changing or reusing a number breaks old clients. Say you reserve removed numbers.
  • Says gRPC only works with protobuf Protobuf is gRPC's default, but gRPC can carry other formats. Say it is the default because of the schema, code generation and compact encoding.
  • Names no downside Binary payloads are not human-readable, browsers need gRPC-Web, and every client needs the .proto. Naming one cost shows you know when not to use it.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the API Design cheatsheet.

← Back to all API Design questions
Pro · $10/mo

90 of 110 API Design answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime