Reliability
10. Why must every call have a deadline?
Because gRPC sets none by default, so a stuck server can hold a client's call, and its resources, forever. The deadlines guide says to always set a realistic deadline explicitly.
A deadline is a point in time, not a duration, so it can be passed down a call chain. If service A has 2 seconds left and calls B, B should get the remaining time, not a fresh 2 seconds.
The guide notes that Go and Java propagate deadlines by default, while C++ needs it enabled. Servers should also check whether the call was canceled and stop work that nobody is waiting for.
ctx, cancel := context.WithTimeout(ctx, 300*time.Millisecond)
defer cancel()
resp, err := client.GetUser(ctx, &pb.GetUserRequest{Id: id})
if status.Code(err) == codes.DeadlineExceeded {
// fall back or fail fast
}
11. Which status codes should a server return?
Return the code that tells the client what to do next. INVALID_ARGUMENT means fix the request. NOT_FOUND and ALREADY_EXISTS are about the resource. FAILED_PRECONDITION means the system is not in the right state.
UNAVAILABLE means try again later.
Two are often misused. INTERNAL is reserved for serious errors where an invariant broke, per the status codes guide. UNKNOWN is what a client sees when a server throws an unmapped exception.
A server that returns UNKNOWN for validation errors leaves clients unable to tell a bug from bad input.
12. How do you send structured error details?
Use the richer error model: attach protobuf messages from google.rpc, such as BadRequest with field violations or RetryInfo, to the status. They travel in the trailers alongside the code and message.
The error handling guide notes this model only works when Protobuf is the data format, and support differs by language. Clients must still handle a bare status, because a proxy or an older server may not send details.
13. How do retries work, and when are they unsafe?
gRPC retries in the client, per method, from a retryPolicy in the service config: a maximum number of attempts, exponential backoff and a list of retryable codes, usually just UNAVAILABLE.
"retryPolicy": {
"maxAttempts": 4,
"initialBackoff": "0.1s",
"maxBackoff": "1s",
"backoffMultiplier": 2,
"retryableStatusCodes": ["UNAVAILABLE"]
}
Per the retry guide, gRPC adds 20% jitter and stops retrying once response headers arrive. Retrying is only safe for idempotent methods.
A CreatePayment call that timed out may have succeeded, so it needs an idempotency key before it can be retried. Hedging, which sends extra copies before the first fails, has the same limit.
14. What does wait-for-ready change?
It changes what a call does while the channel has no ready connection. By default the call fails fast with UNAVAILABLE. With wait-for-ready set, it waits for a connection until its deadline.
Use it for calls made during startup, when a dependency may still be booting, or for batch jobs that would rather wait than fail. It only makes sense with a deadline; otherwise the call can wait forever.
15. What problem do keepalives solve, and how do they cause outages?
Keepalive pings detect dead connections that TCP would not notice for a long time, such as when a load balancer silently drops an idle flow. They matter most for long-lived streams.
The outage pattern is a client that pings too often. The keepalive guide lists a server default of 5 minutes as the minimum ping interval.
A client pinging every 10 seconds gets a GOAWAY with too_many_pings, and its connections keep dropping. Client and server settings must be agreed together.