gRPC transport in NestJS is a way to communicate between microservices using the gRPC protocol, which is fast and efficient for remote procedure calls.
Click to reveal answer
intermediate
How do you define a gRPC service in NestJS?
You define a gRPC service by creating a .proto file with service and message definitions, then use NestJS decorators and options to connect your service to that proto file.
Click to reveal answer
beginner
What decorator is used to mark a method as a gRPC handler in NestJS?
The @GrpcMethod() decorator marks a method as a gRPC handler that responds to a specific RPC call.
Click to reveal answer
beginner
What is the role of the Transport.GRPC option in NestJS microservice setup?
Transport.GRPC tells NestJS to use the gRPC protocol for communication when creating a microservice client or server.
Click to reveal answer
intermediate
Why is gRPC transport preferred for microservices communication?
gRPC transport is preferred because it uses HTTP/2, supports streaming, is efficient with data serialization using Protocol Buffers, and offers strong typing.
Click to reveal answer
Which file format defines gRPC services in NestJS?
A.proto
B.json
C.yaml
D.xml
✗ Incorrect
gRPC services are defined using Protocol Buffers files with the .proto extension.
Which decorator marks a method as a gRPC handler in NestJS?
A@GrpcHandler()
B@GrpcMethod()
C@GrpcService()
D@GrpcCall()
✗ Incorrect
The @GrpcMethod() decorator is used to mark methods that handle gRPC calls.
What transport option is used to enable gRPC in NestJS microservices?
ATransport.HTTP
BTransport.TCP
CTransport.GRPC
DTransport.REDIS
✗ Incorrect
Transport.GRPC configures NestJS microservices to use the gRPC protocol.
Which protocol does gRPC use for communication?
AHTTP/2
BHTTP/1.1
CFTP
DWebSocket
✗ Incorrect
gRPC uses HTTP/2 for efficient, multiplexed communication.
What serialization format does gRPC use by default?
AYAML
BJSON
CXML
DProtocol Buffers
✗ Incorrect
gRPC uses Protocol Buffers for fast and compact data serialization.
Explain how to set up a basic gRPC microservice in NestJS.
Think about defining the service, configuring transport, and handling calls.
You got /4 concepts.
Describe the benefits of using gRPC transport for microservices communication.
Consider speed, data format, and reliability.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using gRPC transport in a NestJS application?
easy
A. To enable fast and clear communication between microservices using Protocol Buffers
B. To create RESTful APIs with JSON responses
C. To manage database connections efficiently
D. To handle user authentication and authorization
Solution
Step 1: Understand gRPC transport role
gRPC transport in NestJS is designed to enable fast communication between services using Protocol Buffers.
Step 2: Compare with other options
Options B, C, and D describe other unrelated features like REST APIs, database, or auth, which are not the main purpose of gRPC transport.
Final Answer:
To enable fast and clear communication between microservices using Protocol Buffers -> Option A
Quick Check:
gRPC transport = fast microservice communication [OK]
Hint: gRPC = fast microservice communication with Protocol Buffers [OK]
Common Mistakes:
Confusing gRPC with REST APIs
Thinking gRPC manages databases
Assuming gRPC handles authentication
2. Which decorator is used in NestJS to link a method to a gRPC service method?
easy
A. @GrpcMethod
B. @GrpcClient
C. @GrpcHandler
D. @GrpcService
Solution
Step 1: Recall NestJS gRPC decorators
The correct decorator to connect a method to a gRPC service method is @GrpcMethod.
Step 2: Eliminate incorrect options
@GrpcService, @GrpcHandler, and @GrpcClient are not valid decorators for this purpose in NestJS.
Final Answer:
@GrpcMethod -> Option A
Quick Check:
Method to gRPC service = @GrpcMethod [OK]
Hint: Method to gRPC service uses @GrpcMethod decorator [OK]
Common Mistakes:
Using @GrpcService instead of @GrpcMethod
Confusing client decorators with method decorators
Misspelling the decorator name
3. Given this NestJS gRPC service method, what will be the output when called with { id: 5 }?
If no hero matches data.id, find returns undefined.
Step 2: Identify the error
Accessing .name on undefined causes a runtime error.
Final Answer:
Possible runtime error if hero not found -> Option C
Quick Check:
Accessing property on undefined causes error [OK]
Hint: Check if find() result can be undefined before accessing properties [OK]
Common Mistakes:
Ignoring undefined result from find()
Assuming decorator name is wrong
Thinking return type annotation is missing
5. You want to implement a streaming gRPC method in NestJS that sends multiple messages back to the client. Which approach correctly sets up the method signature and decorator?
hard
A. @GrpcMethod('ChatService', 'StreamMessages')
streamMessages(data: { userId: number }): Promise<{ message: string }> {
// implementation
}
B. @GrpcMethod('ChatService', 'StreamMessages')
streamMessages(data: { userId: number }): Observable<{ message: string }> {
// implementation
}
C. @GrpcMethod('ChatService', 'StreamMessages')
streamMessages(data: { userId: number }): { message: string } {
// implementation
}
D. @GrpcMethod('ChatService', 'StreamMessages')
streamMessages(data: { userId: number }): void {
// implementation
}
Solution
Step 1: Understand streaming method return types
Streaming gRPC methods in NestJS return an Observable to send multiple messages over time.
Step 2: Evaluate options
@GrpcMethod('ChatService', 'StreamMessages')
streamMessages(data: { userId: number }): Observable<{ message: string }> {
// implementation
} returns Observable, suitable for streaming. Options A and C return single responses (Promise or object). @GrpcMethod('ChatService', 'StreamMessages')
streamMessages(data: { userId: number }): void {
// implementation
} returns void, which is invalid.
Final Answer:
Method returning Observable for streaming -> Option B
Quick Check:
Streaming gRPC method returns Observable [OK]
Hint: Streaming methods return Observable, not Promise or plain object [OK]
Common Mistakes:
Using Promise instead of Observable for streaming
Returning plain object for streaming method
Using void return type for gRPC method
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.