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

How do you implement a RabbitMQ topic exchange for routing messages to multiple queues based on routing keys in NestJS?

The built-in NestJS RabbitMQ transport does not expose exchange configuration directly. Use @golevelup/nestjs-rabbitmq for advanced exchange patterns. Define exchanges in RabbitMQModule.forRoot(), bind handlers to routing key patterns with @RabbitSubscribe(), and publish with AmqpConnection.publish().

Topic exchange with @golevelup/nestjs-rabbitmq
Topic exchange routing key rules:
  1. 1
    • (asterisk) — matches exactly one word in the routing key.
  2. 2

    (hash) — matches zero or more words; orders.# matches everything under orders.

  3. 3

    Topic exchanges are the most flexible pattern — prefer them over direct or fanout for complex routing.

  4. 4

    @golevelup/nestjs-rabbitmq provides a more complete AMQP integration than the built-in NestJS transport.

  5. 5

    Fanout exchanges broadcast to all bound queues regardless of routing key — use for broadcasting events.

Difficulty: 6/10
Topics: Topic exchange, Routing keys, NestJS microservices

Scenario Questions

0-2 years experience
  1. 1

    Suppose you need to send order events to different services based on the event type (e.g., order.created, order.cancelled). How would you set up a RabbitMQ topic exchange in a NestJS microservice to route these messages to the appropriate queues?

  2. 2

    If you accidentally configure the exchange type as 'direct' instead of 'topic', what behavior would you observe when publishing a message with routing key 'order.created'?

  3. 3

    Can you show a minimal NestJS module that declares a queue bound to a topic exchange with a wildcard routing key like 'order.*'?

2-5 years experience
  1. 1

    Your team added a new routing key pattern 'order.payment.*' but messages with that key are not reaching the intended queue. Walk me through how you would debug the issue in NestJS and RabbitMQ.

  2. 2

    When scaling the NestJS service horizontally, you notice duplicate processing of the same message. Which part of the topic exchange or queue configuration might be causing this, and how would you fix it?

  3. 3

    Explain the trade‑offs between using a single topic exchange with many bindings versus multiple exchanges for different domains in a NestJS application.

5-8 years experience
  1. 1

    Design a high‑throughput event pipeline using NestJS and RabbitMQ topic exchanges that must guarantee at‑least‑once delivery across several microservices. What patterns would you employ to handle failures, back‑pressure, and ordering?

  2. 2

    How would you modify your NestJS topic exchange setup to support dynamic addition of new routing keys at runtime without redeploying services?

  3. 3

    Discuss the performance implications of using many wildcard bindings (e.g., '#') in a topic exchange. How would you mitigate potential routing overhead in a large‑scale NestJS deployment?

8+ years experience
  1. 1

    Your organization is migrating from a monolithic RabbitMQ setup with topic exchanges to a multi‑region, multi‑cluster architecture. What architectural changes would you propose for the NestJS services to maintain consistent routing semantics and minimize latency?

  2. 2

    Consider a scenario where different teams own overlapping routing key namespaces (e.g., 'user.' and 'user.profile.'). How would you establish governance and versioning for topic exchanges in NestJS to avoid conflicts over the long term?

  3. 3

    If you needed to replace RabbitMQ with a cloud‑native event bus (e.g., Google Pub/Sub) while preserving existing topic‑based routing logic in NestJS, what migration strategy would you adopt to ensure minimal disruption?

Follow-up Questions

  • What happens if a message is published with a routing key that matches no queue binding?
  • How would you monitor and troubleshoot routing mismatches in production?
  • Can you describe how you would ensure ordering guarantees when multiple consumers share a queue?