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
- 4.1 Protocol Buffers basics
- 4.2 Schema evolution and compatibility
- 4.3 gRPC fundamentals and HTTP/2
- 4.4 Streaming RPCs and flow control
- 4.5 Metadata, deadlines, cancellation and errors
- 4.6 Load balancing, interceptors, health and operations
- 4.7 gRPC on the web and REST interoperability
- 4.8 Real-time web: WebSockets, SSE and long polling
- 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
What are Protocol Buffers (protobuf)?
- A JSON Schema dialect used to document REST APIs
- Messages defined in `.proto` files, serialized to compact binary
- A compression algorithm negotiated by HTTP servers
- 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.
You remove a field from a message in use. What should you do?
- Renumber all of the remaining fields so there are no gaps
- Mark its number and name `reserved` so they're never reused
- Reuse its number for the next field you add to the message
- 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.
What does gRPC run over?
- SMTP, using MIME attachments
- Raw UDP datagrams, unencrypted
- HTTP/2, with protobuf by default
- HTTP/1.1, with JSON by default
Answer: C. HTTP/2, with protobuf by default HTTP/2 gives multiplexing and streaming in both directions.
Which four kinds of RPC does gRPC support?
- Unary, server, client and bidirectional streaming
- Sync, async, batch and scheduled cron calls
- GET, POST, PUT and DELETE, mapped from HTTP
- Request, reply, retry and cancel operations
Answer: A. Unary, server, client and bidirectional streaming Streaming types are declared with `stream` in the service definition.
What is gRPC metadata?
- Header-like key-value pairs sent with a call, like tokens
- The raw contents of the `.proto` file sent to clients
- The binary-encoded body of each protobuf message
- 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.
Why is load balancing gRPC behind a plain layer-4 (TCP) load balancer often uneven?
- Layer-4 balancers can't forward binary protobuf payloads
- Long-lived HTTP/2 connections pin a client's calls to one backend
- gRPC clients are only ever allowed to talk to one server
- 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.
Why can't a browser call a standard gRPC service directly?
- gRPC servers only run on Linux, which browsers can't connect to
- Browsers don't expose HTTP/2 control like trailers, so gRPC-Web is used
- Browsers aren't able to make POST requests from JavaScript
- 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.
What is long polling?
- A WebSocket connection configured with a very long timeout
- The server holds the request until data arrives; the client re-asks
- The client sends a single very large request with all its data
- 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.
Which is the best fit for a public, browser-facing CRUD API used by third parties?
- A WebSocket message for every request
- Raw gRPC with protobuf, called directly
- REST or GraphQL over HTTP with JSON
- SMTP, with requests sent as emails
Answer: C. REST or GraphQL over HTTP with JSON Third parties expect easy tooling and browser support.
What is the purpose of the field number in `string email = 3;`?
- It identifies the field on the wire, so it must never change
- It sets the field's position when output as JSON
- It marks the field as the third required field
- 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.
More Server Side
- HTTP fundamentals
- REST API design
- GraphQL
- OAuth 2.0, OIDC & JWT
- Sessions, cookies & web app security
- C# & .NET
- Java & Spring Boot
- Node.js & Express
- Python, Django & FastAPI
- Go (Golang)
- Concurrency & multithreading
- OOP & SOLID
- Design patterns
- Dependency injection
- Logging & observability
- Data structures
- Algorithms & Big-O
- Linux & shell scripting