gRPC & Kafka — Series 2

Preview — 3 of 10 questions

Why does removing a field require the reserved declaration?

javascript
message Order {
  string id = 1;
  // string coupon = 2;   removed in v2
  int32 amount = 3;
  reserved 2;
  reserved "coupon";
}
ABecause the compiler refuses to generate code for a message with a gap in its numbering
BBecause reserved fields are still transmitted, preserving the message's byte layout
CBecause reserved retains the field for one release so old clients keep receiving it
DBecause field numbers, not names, identify data on the wire — reusing number 2 for a different type later would make old producers' bytes decode as the new field, silently corrupting data; reserving the number and name makes that mistake a compile error

How does a deadline differ from an ordinary client-side timeout?

javascript
const metadata = new Metadata();
this.ordersService.findOne({ id }, metadata, { deadline: Date.now() + 2000 });
AIt is enforced only by the client, exactly like a timeout, but with nicer syntax
BIt is transmitted to the server, which can observe it, abort work when it passes, and propagate the remaining budget to its own downstream calls — so the whole call tree stops instead of continuing work nobody is waiting for
CIt applies per message in a stream rather than to the call as a whole
DIt causes the server to queue the request until it can be served within the deadline

What distinguishes this from throwing NotFoundException?

javascript
throw new RpcException({ code: status.NOT_FOUND, message: 'Order not found' });
ANothing; Nest converts HTTP exceptions to gRPC statuses automatically
BRpcException is only valid in event handlers, not in gRPC methods
CgRPC has its own status code space (NOT_FOUND, INVALID_ARGUMENT, PERMISSION_DENIED, …) that is not HTTP's; RpcException carries a code from that space, whereas an HTTP exception thrown from a gRPC handler reaches the client as a generic UNKNOWN with its details flattened into a message string
DRpcException is caught by exception filters while NotFoundException is not

Sign up free to play

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