gRPC & Kafka — Series 3

Preview — 3 of 10 questions

What do optional and oneof contribute?

javascript
message UpdateOrder {
  optional string note = 1;
  oneof target { string order_id = 2; string external_ref = 3; }
}
Aoptional makes the field nullable in the generated TypeScript, with no wire effect
BBoth restore field presence: without them a scalar set to its default ("", 0, false) is indistinguishable from an unset one, so a partial update cannot express "clear this note" versus "leave it alone" — and oneof additionally enforces that exactly one of its members is set
Coneof allows several members to be set simultaneously, unlike optional
DBoth are documentation hints consumed only by code generators

What is metadata, and how should the server treat it?

javascript
const metadata = new Metadata();
metadata.add('authorization', `Bearer ${token}`);
this.ordersService.findOne({ id }, metadata);
AA reserved channel for gRPC's own framing, which applications must not use
BA field of the request message, serialised alongside the payload
CPer-call state shared across every call on the same channel
DKey–value pairs sent with the call, the gRPC analogue of HTTP headers — carrying credentials, trace context and deadlines separately from the message; on the server they reach a guard through the execution context and should be validated exactly like an HTTP header, since a client controls them entirely

What is happening?

javascript
Long-lived gRPC channel through a load balancer.
After a few minutes of inactivity, the next call fails with UNAVAILABLE.
AAn intermediary closed the idle TCP connection without either endpoint noticing, so the client discovers it only when it tries to use it — configuring HTTP/2 keepalive pings keeps the connection observably alive and lets the client detect a broken one before the next request
BThe channel's credentials expired and must be refreshed
CgRPC channels are single-use and must be recreated per call
DThe server's deadline elapsed while the channel was idle

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.