Questions
15 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?
15 / 25

How do you handle errors in microservice request-response patterns and propagate them to the caller in NestJS?

Difficulty: 6/10
Exception Filters, HttpException, Microservice Transport

Throw RpcException on the microservice side to send structured errors back to the caller. On the API gateway or caller side, catch errors in the Observable pipeline with catchError() and rethrow as HTTP exceptions. Register a global RpcExceptionFilter to convert RpcException to HTTP responses on the gateway.

RpcException on service, filter and catchError on gateway
Error propagation rules:
  1. 1

    RpcException is the correct exception class for microservice handlers — plain Error objects are not serialized properly.

  2. 2

    Pass an object to RpcException with statusCode and message for structured error payloads.

  3. 3

    The gateway must have a global RpcExceptionFilter to convert RpcException to HTTP responses.

  4. 4

    catchError() in the Observable pipeline intercepts errors from send() before they propagate as unhandled.

  5. 5

    throwError(() => new HttpException(...)) re-throws as an HTTP exception so the gateway's exception filters handle it.

Scenario Questions

0-2 years experience

  1. 1You need to call another NestJS microservice via TCP and return the result to an HTTP client. How would you catch an error from the remote service and send an appropriate HTTP status code back?
  2. 2If a service method throws a custom HttpException, what will the NestJS framework do when the request originates from a microservice client, and how can you ensure the caller receives the same error details?
  3. 3Describe the steps to add a global exception filter that transforms all microservice errors into a standard JSON payload.

2-5 years experience

  1. 1During a recent feature you added a fallback when a downstream payment microservice is unavailable. The fallback isn’t being triggered even though the remote call times out. Walk me through how you’d debug the error propagation in NestJS.
  2. 2You need to propagate validation errors from a user‑service microservice back to the original HTTP gateway, preserving the original error code and message. What trade‑offs exist between using HttpException vs. custom error objects, and how would you implement it?
  3. 3Explain how you would configure a NestJS microservice client to retry on transient errors and still surface the final failure to the caller.

5-8 years experience

  1. 1At scale, you notice that error payloads from several microservices are inflating response sizes and causing latency. How would you redesign error handling and propagation in NestJS to mitigate this while keeping enough diagnostic info?
  2. 2Your system uses both gRPC and RabbitMQ transports. How do you ensure a consistent error contract across these transports, and what changes would you make to the exception filters or interceptors?
  3. 3If a downstream service crashes and the NestJS gateway keeps retrying, how would you prevent cascading failures and still surface a meaningful error to the original client?

8+ years experience

  1. 1The organization is moving from a monolith to a NestJS microservice architecture. What long‑term strategy would you propose for standardizing error handling and propagation across dozens of services, considering versioning, observability, and backward compatibility?
  2. 2Multiple teams have built their own custom exception filters. How would you consolidate them into a unified approach without breaking existing contracts, and what governance process would you put in place?
  3. 3Discuss the implications of propagating stack traces to external callers in a public API. How would you design the error handling layer to balance security, debuggability, and compliance across all NestJS services?

Follow-up Questions

  • What changes would you make if you needed to hide internal error codes from external clients?
  • How does NestJS differentiate between HTTP and microservice contexts when handling exceptions?
  • Can you show a minimal example of the JSON error shape you would return?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.