gRPC & Protocol Buffers test (Intermediate)
30 questions · 35 minutes · Free
Protobuf schemas, gRPC services and streaming, errors, deadlines and interceptors.
Take the gRPC & Protocol Buffers test
What it covers
- Protocol Buffers schemas
- gRPC unary and streaming calls
- gRPC error handling and deadlines
- gRPC interceptors and auth
- gRPC vs REST
Interview format
- Questions: 30 questions — 18 multiple choice, 9 multi-answer, 3 predict-the-output
- Time: 35 minutes, timed from the first question
- Difficulty: Intermediate
- Skill area: Backend
- Price: Free
Earn a certificate
The gRPC & Protocol Buffers test is one of the 6 tests of the Go Backend Developer: Intermediate learning path. Pass it and the other 5 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.
Sample questions
5 sample questions from the gRPC & Protocol Buffers test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
What is required for a browser to communicate with a gRPC service?
- A REST client library
- A WebSocket connection
- gRPC-Web or a JSON transcoding gateway (e.g. grpc-gateway)
- A native gRPC client library
Answer: C. gRPC-Web or a JSON transcoding gateway (e.g. grpc-gateway)
Browsers cannot directly use gRPC because they lack HTTP/2 support. gRPC-Web or JSON transcoding gateways (like grpc-gateway) are required to bridge this gap, allowing browser clients to communicate with gRPC services using HTTP/1.1 or JSON formats.
What is the primary purpose of the package declaration in Protocol Buffers?
- The package declaration in Protocol Buffers is used to define the binary format of messages for efficient serialization and deserialization.
- The package declaration in Protocol Buffers is used to define the HTTP/2 headers and metadata associated with gRPC requests and responses.
- The package declaration in Protocol Buffers is used to handle streaming RPC calls and manage bidirectional communication between the client and server.
- The package declaration in Protocol Buffers is used to avoid naming conflicts and organize related messages, services, and enums into a hierarchical namespace.
Answer: D. The package declaration in Protocol Buffers is used to avoid naming conflicts and organize related messages, services, and enums into a hierarchical namespace.
The package declaration in Protocol Buffers is essential for organizing code and avoiding naming conflicts. It defines a hierarchical namespace for messages, services, and enums. It does not directly impact performance or internal complexity, but it is crucial for structuring code in larger projects.
In a project using the newer editions model of Protocol Buffers, which file option setting should be used?
- Use `syntax = "proto3";` and avoid `edition = "2023";` for newer editions.
- Use `edition = "2023";` and avoid `syntax = "proto3";` for newer editions.
- Use `syntax = "proto2";` and avoid `edition = "2023";` for newer editions.
- Use both `syntax = "proto3";` and `edition = "2023";` in the same file for compatibility.
Answer: B. Use `edition = "2023";` and avoid `syntax = "proto3";` for newer editions.
In newer editions of Protocol Buffers, `edition = "2023";` is used instead of `syntax = "proto3";`. This change is part of the newer editions model and is recommended for projects using the latest features and improvements.
When implementing authentication in a gRPC service, what is the correct way to inject an auth token into a request using interceptors?
- Attach the token to the request metadata within the interceptor.
- Send the token in the response metadata for the client to read.
- Modify the protobuf schema to include an auth field.
- Include the token in the request body as a string.
Answer: A. Attach the token to the request metadata within the interceptor.
In gRPC, interceptors are used to add authentication tokens to requests. The correct approach is to attach the token to the request metadata within the interceptor, ensuring that it is included with every request. Other options, such as using the request body, modifying the protobuf schema, or using the response metadata, are not appropriate for this purpose.
Consider the following code snippet for a Protocol Buffers message extension: `message MyMessage { int32 my_field = 1; } message MyExtension { int32 extended_field = 1; }`. What is the issue with this code?
- The message extension is properly defined. The `extend` keyword should be used with the message name, but the field number does not need to be unique within the extended message.
- The message extension is not properly defined. The `extend` keyword should be used with the message name, and the field number must be unique within the extended message.
- The message extension is properly defined. The field number does not need to be unique within the extended message.
- The message extension is properly defined. The `extend` keyword is not required when extending a message.
Answer: B. The message extension is not properly defined. The `extend` keyword should be used with the message name, and the field number must be unique within the extended message.
In Protocol Buffers, when extending a message, the correct syntax is to use the `extend` keyword followed by the message name and then define the extended fields with unique field numbers. The provided code is incorrect because it does not use the `extend` keyword and does not ensure unique field numbers within the extended message.
Frequently asked questions
- How many questions are in the gRPC & Protocol Buffers test?
- 30 questions (18 multiple choice, 9 multi-answer, 3 predict-the-output), with 35 minutes to answer them.
- What does the gRPC & Protocol Buffers test cover?
- Protocol Buffers schemas, gRPC unary and streaming calls, gRPC error handling and deadlines, gRPC interceptors and auth, gRPC vs REST.
- Is the gRPC & Protocol Buffers test free?
- Yes. It is free to take with a readyforhires account.
- What level is the gRPC & Protocol Buffers test?
- Intermediate, in Backend.