Questions
12 of 25
1What is the difference between request-response and event-based (fire-and-forget) message patterns in NestJS microservices?
2What is the @Payload() decorator and how do you use @Ctx() to access transport-specific context in NestJS microservices?
3How do you connect a NestJS microservice to RabbitMQ?
4How do you implement manual message acknowledgement with RabbitMQ in NestJS?
5How do you implement a RabbitMQ topic exchange for routing messages to multiple queues based on routing keys in NestJS?
6How does gRPC differ from REST and when would you choose it for inter-service communication in NestJS?
7How do you implement an API Gateway pattern in NestJS that aggregates multiple microservices?
8How do you implement distributed tracing across NestJS microservices?
9What transport layers does NestJS support for microservices and how do you bootstrap a microservice?
10How do you connect a NestJS microservice to Apache Kafka?
11How do you handle Kafka message patterns and access message headers and partition info via KafkaContext in NestJS?
12How do you set up gRPC in a NestJS microservice?
13How do you implement a circuit breaker pattern when calling a downstream microservice in NestJS?
14How do you inject and use a ClientProxy to communicate with another microservice in NestJS?
15How do you handle errors in microservice request-response patterns and propagate them to the caller in NestJS?
16How do you implement Kafka consumer groups and what guarantees does partition assignment give you in NestJS?
17How do you implement the outbox pattern with Kafka in NestJS to guarantee exactly-once message delivery?
18How do you implement gRPC streaming including server-side, client-side, and bidirectional streaming in NestJS?
19What is the difference between @EventPattern() and @MessagePattern() in NestJS microservices?
20How do you implement the Saga pattern for distributed transactions across NestJS microservices?
21How do you implement idempotent event handlers to safely handle duplicate message delivery in NestJS?
22How do you implement event sourcing with NestJS microservices?
23How do you implement retry logic with exponential backoff for failed microservice calls in NestJS?
24How do you test a NestJS microservice controller in isolation without a real message broker?
25How do you implement service discovery and load balancing across NestJS microservice instances?
12 / 25

How do you set up gRPC in a NestJS microservice?

Install @grpc/grpc-js and @grpc/proto-loader. Define service methods in a .proto file. Bootstrap the microservice with Transport.GRPC pointing to the proto file. Decorate handler methods with @GrpcMethod('ServiceName', 'MethodName') where the names must exactly match the proto service and rpc definitions.

Proto definition, gRPC microservice, and client
gRPC setup rules:
  1. 1

    package in options must match the package statement in the .proto file.

  2. 2

    @GrpcMethod('ServiceName', 'MethodName') — both names must exactly match the proto definitions.

  3. 3

    The proto file path must resolve correctly at runtime — use __dirname and join() for portability.

  4. 4

    Client uses getService<ServiceClient>('ServiceName') to get a typed client proxy for calling remote methods.

  5. 5

    Share the .proto file between services via a shared npm package or a git submodule for consistency.

Difficulty: 6/10
Topics: gRPC server configuration, proto file integration, NestJS microservice transport

Scenario Questions

0-2 years experience
  1. 1

    Walk me through the steps you'd take to add a gRPC server to a new NestJS microservice.

  2. 2

    If you have a .proto file defining a UserService, how would you generate and use the client in a NestJS module?

  3. 3

    What happens if the proto file and the generated TypeScript definitions get out of sync? How would you notice and fix it?

2-5 years experience
  1. 1

    We tried to call a gRPC method from another NestJS service and got a deadline exceeded error. What could be causing this, and how would you troubleshoot?

  2. 2

    Explain how you would configure NestJS to support both gRPC and HTTP transports for the same service, and why you might want to.

  3. 3

    When adding versioning to your gRPC APIs, what changes are needed in the NestJS setup and the proto definitions?

5-8 years experience
  1. 1

    Describe how you would implement server‑side streaming for a large data export in NestJS using gRPC, and what performance considerations you’d keep in mind.

  2. 2

    How would you secure gRPC communication between NestJS microservices in a production environment?

  3. 3

    If you need to add request/response logging and error handling across all gRPC calls, where would you place interceptors in NestJS, and what trade‑offs exist?

8+ years experience
  1. 1

    Our platform currently uses REST for inter‑service communication, but we want to migrate to gRPC for performance. How would you plan the migration across multiple NestJS teams while minimizing disruption?

  2. 2

    Discuss the pros and cons of using a service mesh (e.g., Istio) with NestJS gRPC microservices versus handling load balancing and retries in the application layer.

  3. 3

    How would you design a versioning strategy for gRPC APIs that need to evolve over years, ensuring backward compatibility and smooth rollout across many services?

Follow-up Questions

  • Can you show a minimal NestJS module snippet that registers the gRPC server?
  • What are common pitfalls when the generated protobuf types get out of sync with the service implementation?
  • How do you unit‑test a gRPC handler in NestJS?