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

What is the difference between @EventPattern() and @MessagePattern() in NestJS microservices?

Difficulty: 5/10
NestJS decorators, microservice communication patterns, transport layer semantics

@MessagePattern() handles request-response interactions where the return value is sent back to the caller. @EventPattern() handles fire-and-forget events where the return value is discarded. The client uses send() for request-response and emit() for events — both return Observables but with different semantics.

Request-response vs fire-and-forget patterns
Pattern selection guidance:
  1. 1

    @MessagePattern — use for synchronous query-style operations where the result is needed immediately.

  2. 2

    @EventPattern — use for domain events signaling something that happened; no response expected.

  3. 3

    send() blocks the caller until a response is received or a timeout occurs.

  4. 4

    emit() is non-blocking; the caller continues immediately after the message is sent.

  5. 5

    Event-based patterns improve resilience — the emitter is decoupled from all consumers and their availability.

Scenario Questions

0-2 years experience

  1. 1You need to handle a simple RPC call from another service. Which decorator would you use and why?
  2. 2If you accidentally use @EventPattern for a request‑response interaction, what will happen at runtime?
  3. 3Show me how you would set up a NestJS microservice to listen for a 'user.created' event using the appropriate decorator.

2-5 years experience

  1. 1Your team is migrating a set of services from request‑response to an event‑driven model. How do you decide when to replace @MessagePattern with @EventPattern?
  2. 2During debugging you notice that a handler decorated with @EventPattern never receives messages, but a @MessagePattern handler works. What could be wrong in the transport configuration?
  3. 3Explain the trade‑offs of using @EventPattern for a high‑throughput stream versus @MessagePattern for occasional commands.

5-8 years experience

  1. 1Design a gateway that aggregates data from multiple microservices, some using @MessagePattern and others @EventPattern. How would you coordinate responses and ensure reliability?
  2. 2At scale you see latency spikes when many services emit events via @EventPattern on a NATS transport. What architectural changes could mitigate this?
  3. 3How would you implement a fallback mechanism if an @MessagePattern RPC call fails, while still processing related events via @EventPattern?

8+ years experience

  1. 1Your organization plans a long‑term migration from a tightly coupled RPC architecture to an event‑driven architecture across dozens of services. How would you evaluate the impact of replacing @MessagePattern with @EventPattern on contract stability, testing, and observability?
  2. 2When introducing a new version of an event schema, how would you handle backward compatibility for services using @EventPattern without breaking existing @MessagePattern consumers?
  3. 3What governance model would you propose to decide which communication pattern (event vs message) to use for new features, considering cross‑team ownership and future scalability?

Follow-up Questions

  • Can you give an example where mixing the two decorators caused a bug?
  • How would you test that a handler correctly distinguishes between an event and an RPC call?
  • What monitoring would you add to detect misrouted messages between @EventPattern and @MessagePattern?
Share

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