gRPC
gRPC is a framework for remote procedure calls: one service calls a method on another service as if it were a local function, and gRPC handles serialization, transport, timeouts and errors. You describe your API in a .proto file, generate client and server code for any of a dozen languages, and the two sides talk over HTTP/2 using compact binary messages. It grew out of the internal RPC system Google had used for years and was open-sourced in 2015.
The properties that matter:
- Contract-first: The API is defined once, in a schema (Protocol Buffers). Clients and servers are generated from it, so a typo in a field name is a compile error, not a 400 in production.
- Binary and compact: Protocol Buffers encode messages in a tight binary format that is smaller than JSON and much cheaper to parse.
- Built on HTTP/2: Many calls share one long-lived TCP connection, multiplexed as independent streams, with header compression and flow control.
- Streaming: Besides ordinary request/response calls, gRPC supports server streaming, client streaming and full bidirectional streaming over the same connection.
- Deadlines and cancellation built in: Every call can carry a deadline that propagates to downstream calls, and cancelling a call cancels its work on the server.
In interviews, gRPC is the default answer for internal service-to-service communication in a microservice design, and it shows up whenever latency, payload size or streaming matters: a matching engine talking to a risk service, a ride-sharing backend receiving location streams, a model-serving tier. It also comes up in API design questions as the alternative to REST and GraphQL. The interesting follow-ups are about schema evolution, deadlines, and one subtle problem: load balancing long-lived HTTP/2 connections.
Protocol Buffers
Everything starts with the service definition:
syntax = "proto3";
package rides.v1;
service DispatchService {
rpc GetTrip(GetTripRequest) returns (Trip); // unary
rpc WatchTrip(WatchTripRequest) returns (stream TripUpdate); // server streaming
rpc UploadLocations(stream Location) returns (UploadSummary); // client streaming
rpc DriverSession(stream DriverEvent) returns (stream DispatchCommand); // bidirectional
}
message Location {
string driver_id = 1;
double lat = 2;
double lng = 3;
int64 timestamp_ms = 4;
optional float heading = 5;
}
Running protoc (or buf generate) on this file produces a typed client stub and a server interface in Go, Java, Python, C++, TypeScript and others. The client calls stub.GetTrip(request); the server implements GetTrip.
But what is actually happening under the hood? On the wire, a Protobuf message is a sequence of fields, and each field is written as a tag (the field number and a wire type packed together) followed by the value. Integers use varints, where small numbers take fewer bytes: the value 150 takes 2 bytes, not 4 or 8. Field names never appear on the wire; only the numbers do.
Take the Location above. As JSON, {"driver_id":"d_48213","lat":37.7749,"lng":-122.4194,"timestamp_ms":1712345678901} is 82 bytes, and parsing it means scanning text and converting decimal strings to floats. As Protobuf it's 34 bytes: a 9-byte string, two 9-byte doubles and a 7-byte varint, with no field names and no quoting. Across billions of location updates a day, that difference shows up in bandwidth, CPU and latency.
Schema Evolution
Because the wire format uses field numbers, not names, Protobuf has clear rules for changing an API without breaking old clients:
- Adding a field is safe. Old readers skip field numbers they don't know (and preserve them if they re-serialize). New readers see the default value when an old writer didn't set it.
- Renaming a field is safe on the wire, since only the number is sent (though it breaks JSON mapping and source code).
- Never reuse or change a field number or its type. If you delete a field, mark its number
reservedso nobody reuses it and old data is never misread. - Removing a required concept is a breaking change. Proto3 dropped
requiredfields entirely for this reason; every field is optional on the wire.
Mentioning these rules in an interview is a quick way to show you've maintained a real API. "We version the package as
rides.v1, only ever add fields, reserve deleted field numbers, and run a breaking-change check in CI" covers what an interviewer wants to hear about evolving gRPC contracts.