gRPC and Protocol Buffers: contracts, streaming and real-time communication – Server Side interview prep

261 interview-style multiple-choice questions on gRPC and Protocol Buffers: contracts, streaming and real-time communication, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 103 key terms with the flashcards first, then test yourself.

Take the practice test · Flashcards · All study tools

What it covers

  1. 4.1 Protocol Buffers basics
  2. 4.2 Schema evolution and compatibility
  3. 4.3 gRPC fundamentals and HTTP/2
  4. 4.4 Streaming RPCs and flow control
  5. 4.5 Metadata, deadlines, cancellation and errors
  6. 4.6 Load balancing, interceptors, health and operations
  7. 4.7 gRPC on the web and REST interoperability
  8. 4.8 Real-time web: WebSockets, SSE and long polling
  9. 4.9 Choosing protocols and API styles

Key terms

4.1 Protocol Buffers basics

Protocol Buffers
Schema-based binary serialization format
Field number
Wire identifier for a protobuf field
reserved
Keyword preventing reuse of removed field numbers or names
oneof
Group of fields where only one may be set
Varint
Variable-length integer encoding
ZigZag encoding
Mapping signed ints so small negatives stay small
Field tag
Field number plus wire type
Field presence
Knowing if a field was set
Well-known types
Standard messages like Timestamp
FieldMask
List of fields to update or read
Any
Message with a type URL
protoc
Protocol buffer compiler
Buf
Protobuf linting and breaking checks
Editions
Feature-based successor to proto2/proto3
Packed encoding
Repeated scalars in one record
Unknown fields
Unrecognized fields kept by parsers

4.2 Schema evolution and compatibility

Backward compatibility
New code reads old data
Forward compatibility
Old code reads new data
Open enum
Enum that keeps unknown numeric values
Breaking change detection
Comparing schema versions
Versioned package
acme.orders.v2 for breaking changes
protovalidate
Annotation-based message validation
AIP
Google API design guideline
field_behavior
REQUIRED or OUTPUT_ONLY annotations

4.3 gRPC fundamentals and HTTP/2

gRPC
High-performance RPC framework over HTTP/2
Unary RPC
One request, one response
Bidirectional streaming
Both sides stream messages over one call
gRPC-Web
Variant that lets browsers call gRPC services through a proxy
Service definition
rpc methods declared in .proto
Stub
Generated client with typed methods
Method path
/package.Service/Method
Length-prefixed framing
5-byte header before each message
Trailers
Headers sent after the body
GOAWAY
HTTP/2 frame telling clients to move on
Server reflection
Service discovery for tools
ALPN
TLS extension negotiating h2
Channel states
IDLE, CONNECTING, READY, ...

4.4 Streaming RPCs and flow control

Server streaming
One request, many responses
Client streaming
Many requests, one response
Half-close
Client says it's done sending
Flow-control window
Bytes a receiver will accept
BDP probing
Auto-sizes windows for the link
Chunking
Splitting large data into messages
Max connection age
Forces periodic reconnects
Resume token
Cursor to restart a stream
Watch
Stream of changes

4.5 Metadata, deadlines, cancellation and errors

Deadline
Absolute time limit for a call
Status code
gRPC's result code, like OK or UNAVAILABLE
Interceptor
Middleware for gRPC calls
Health checking protocol
Standard gRPC service for health probes
-bin metadata
Binary values, base64 on wire
grpc-timeout
Header carrying remaining deadline
Trailing metadata
Sent with final status
FAILED_PRECONDITION
Valid request, wrong system state
UNAUTHENTICATED
Missing or bad credentials
RESOURCE_EXHAUSTED
Quota or rate limit hit
ABORTED
Concurrency conflict
google.rpc.Status
Rich error details
Retry policy
Service config retries
Hedging policy
Parallel copies, first reply wins

4.6 Load balancing, interceptors, health and operations

Layer 7 balancing
Per-call balancing in a proxy
pick_first
Default policy, one backend
round_robin
Rotates calls across backends
Headless Service
DNS returns pod IPs
xDS
Control-plane config protocol
ORCA
Backend load reports
Health Watch
Streams status changes
Channelz
Runtime channel diagnostics
Subchannel
Connection to one backend
ghz
gRPC load-testing tool

4.7 gRPC on the web and REST interoperability

UseGrpcWeb
ASP.NET Core gRPC-Web middleware
Connect protocol
gRPC, gRPC-Web and HTTP POST in one
google.api.http
Maps RPCs to REST routes
lowerCamelCase JSON
Canonical JSON field names
grpc-gateway
Go REST reverse proxy generator
Buf Schema Registry
Shares proto modules
Twirp
Simple protobuf RPC over HTTP/1.1
protobuf-es
TypeScript protobuf codegen

4.8 Real-time web: WebSockets, SSE and long polling

WebSocket
Full-duplex persistent connection over a single TCP connection
Server-sent events
One-way event stream over HTTP
Long polling
Holding a request open until data is ready
Heartbeat
Periodic message to keep a connection alive and detect failure
WebSocket upgrade
GET with Upgrade, 101 reply
SSE event fields
event, id, data, retry
Ping and pong
WebSocket control frames
wss://
WebSocket over TLS
Close code 1006
Abnormal close, no frame
Subprotocol
App protocol on WebSocket
bufferedAmount
Queued, unsent WebSocket bytes
permessage-deflate
WebSocket compression
Backplane
Shares messages across servers
Stateful reconnect
Buffers through brief drops
Web Push
Notifications via service worker

4.9 Choosing protocols and API styles

Async job
Queue work, return status later
Event fan-out
Many consumers react independently
tRPC
TypeScript-only type-safe RPC
MQTT
Lightweight pub/sub for devices
WebRTC data channel
Unreliable, unordered browser data
Long-running operation
Return ID, poll or watch
Request-reply messaging
Reply-to plus correlation ID
Language Server Protocol
Editor-server JSON-RPC
Chatty API
Many tiny round trips
Sync call chain
Latency adds, availability multiplies

Sample practice questions

  1. What are Protocol Buffers (protobuf)?

    1. A JSON Schema dialect used to document REST APIs
    2. Messages defined in `.proto` files, serialized to compact binary
    3. A compression algorithm negotiated by HTTP servers
    4. A database engine built for storing chat messages

    Answer: B. Messages defined in `.proto` files, serialized to compact binary Code generators create message classes for many languages.

  2. You remove a field from a message in use. What should you do?

    1. Renumber all of the remaining fields so there are no gaps
    2. Mark its number and name `reserved` so they're never reused
    3. Reuse its number for the next field you add to the message
    4. Nothing at all, since field numbers don't really matter

    Answer: B. Mark its number and name `reserved` so they're never reused Reusing a number makes old and new clients misread each other's data.

  3. What does gRPC run over?

    1. SMTP, using MIME attachments
    2. Raw UDP datagrams, unencrypted
    3. HTTP/2, with protobuf by default
    4. HTTP/1.1, with JSON by default

    Answer: C. HTTP/2, with protobuf by default HTTP/2 gives multiplexing and streaming in both directions.

  4. Which four kinds of RPC does gRPC support?

    1. Unary, server, client and bidirectional streaming
    2. Sync, async, batch and scheduled cron calls
    3. GET, POST, PUT and DELETE, mapped from HTTP
    4. Request, reply, retry and cancel operations

    Answer: A. Unary, server, client and bidirectional streaming Streaming types are declared with `stream` in the service definition.

  5. What is gRPC metadata?

    1. Header-like key-value pairs sent with a call, like tokens
    2. The raw contents of the `.proto` file sent to clients
    3. The binary-encoded body of each protobuf message
    4. Server performance statistics returned after each call

    Answer: A. Header-like key-value pairs sent with a call, like tokens Servers can also return metadata in headers and trailers.

  6. Why is load balancing gRPC behind a plain layer-4 (TCP) load balancer often uneven?

    1. Layer-4 balancers can't forward binary protobuf payloads
    2. Long-lived HTTP/2 connections pin a client's calls to one backend
    3. gRPC clients are only ever allowed to talk to one server
    4. gRPC doesn't use TCP at all, so the balancer can't see it

    Answer: B. Long-lived HTTP/2 connections pin a client's calls to one backend Use layer-7 (HTTP/2-aware) proxies or client-side load balancing.

  7. Why can't a browser call a standard gRPC service directly?

    1. gRPC servers only run on Linux, which browsers can't connect to
    2. Browsers don't expose HTTP/2 control like trailers, so gRPC-Web is used
    3. Browsers aren't able to make POST requests from JavaScript
    4. Browsers block all binary data in requests and responses by default

    Answer: B. Browsers don't expose HTTP/2 control like trailers, so gRPC-Web is used gRPC-Web, Connect or JSON transcoding bridge the gap.

  8. What is long polling?

    1. A WebSocket connection configured with a very long timeout
    2. The server holds the request until data arrives; the client re-asks
    3. The client sends a single very large request with all its data
    4. The client polls the server once every few hours for new data

    Answer: B. The server holds the request until data arrives; the client re-asks It's a fallback when WebSockets or SSE aren't available.

  9. Which is the best fit for a public, browser-facing CRUD API used by third parties?

    1. A WebSocket message for every request
    2. Raw gRPC with protobuf, called directly
    3. REST or GraphQL over HTTP with JSON
    4. SMTP, with requests sent as emails

    Answer: C. REST or GraphQL over HTTP with JSON Third parties expect easy tooling and browser support.

  10. What is the purpose of the field number in `string email = 3;`?

    1. It identifies the field on the wire, so it must never change
    2. It sets the field's position when output as JSON
    3. It marks the field as the third required field
    4. It sets the maximum length, in characters, of the string

    Answer: A. It identifies the field on the wire, so it must never change Field names can change; numbers are what's on the wire.

Practice all 261 questions

More Server Side