gRPC errorsmedium3-5 years
A gRPC service needs to signal 'the requested order doesn't exist' and 'you don't have permission to view this order' to its caller. What mechanism carries that, and how would you decide which status code to use for each?
gRPC errors are a status code from a fixed, small set — not an HTTP status code, though several map closely onto ones you already know — with a message and, optionally, typed error details attached as trailers. "Order doesn't exist" is NOT_FOUND (the gRPC analogue of HTTP 404); "you don't have permission" is PERMISSION_DENIED (the analogue of 403) — both thrown on the server as Status.NOT_FOUND.withDescription(...).asRuntimeException() or similar, and both caught on the client by switching on getStatus().getCode() from the StatusRuntimeException. The one rule that matters regardless of which code: the description is a message that crosses the wire to the caller, so it can carry "order 42" but never a stack trace or internal detail.
PreviousA gRPC call sets a client-side timeout of 2 seconds and calls three downstream services in sequence. Two seconds after the call starts, the first downstream call is still in progress. What happens, and how is this different from each service independently having its own 2-second timeout?Next Why is renaming a protobuf field's Java-facing name always safe, while renumbering it — keeping the name, changing the field number — silently corrupts already-stored or already-in-flight data? What's actually on the wire?