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

How do you connect a NestJS microservice to RabbitMQ?

Use Transport.RMQ in both NestFactory.createMicroservice() and ClientsModule.register(). Set noAck: false for manual acknowledgement so messages are not lost if the consumer crashes. Set prefetchCount to control concurrency and queueOptions.durable: true so messages survive RabbitMQ restarts.

RabbitMQ microservice and client configuration
RabbitMQ configuration key options:
  1. 1

    noAck: false — enables manual acknowledgement; the handler must ack/nack via RmqContext.

  2. 2

    prefetchCount — controls concurrency; limits how many unacknowledged messages a consumer holds at once.

  3. 3

    durable: true on the queue ensures messages survive RabbitMQ broker restarts.

  4. 4

    urls accepts an array — amqp-connection-manager round-robins and reconnects automatically.

  5. 5

    Use persistent message delivery (deliveryMode: 2) on the publisher side for full durability.

Difficulty: 5/10
Topics: Transport configuration, Message patterns, Error handling

Scenario Questions

0-2 years experience
  1. 1

    Walk me through the code you'd write to set up a NestJS microservice that listens to a RabbitMQ queue named 'orders'.

  2. 2

    If the RabbitMQ server is down when the service starts, what will happen and how would you make the service fail gracefully?

2-5 years experience
  1. 1

    You notice that messages are being lost when the consumer crashes. How would you modify your NestJS RabbitMQ setup to prevent loss?

  2. 2

    Explain why your microservice started throwing a 'Connection reset by peer' error after a recent config change, and how you'd debug it.

5-8 years experience
  1. 1

    Design a strategy for handling high‑throughput order events across multiple NestJS microservices using RabbitMQ, addressing backpressure and scaling.

  2. 2

    How would you implement dead‑letter queues and retry policies in NestJS to ensure problematic messages are isolated?

8+ years experience
  1. 1

    Your organization wants to migrate from a legacy RabbitMQ cluster to a multi‑region, highly available setup. How would you evolve the NestJS microservice architecture to support this without downtime?

  2. 2

    Discuss the trade‑offs of using RabbitMQ versus a streaming platform like Kafka for inter‑service communication in a large NestJS codebase, and how you'd guide the team in making a decision.

Follow-up Questions

  • What metrics would you expose to monitor the RabbitMQ connection?
  • How would you handle schema changes in the messages you receive?
  • Can you compare the performance implications of using RPC versus fire‑and‑forget patterns?