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

How do you connect a NestJS microservice to Apache Kafka?

Difficulty: 5/10
Kafka client configuration, NestJS microservice transport, Message serialization

Install kafkajs and use Transport.KAFKA in createMicroservice() and ClientsModule.register(). Configure brokers, clientId, and consumer groupId. clientId identifies the application in Kafka logs; groupId determines which consumer group this instance belongs to — Kafka delivers each message to only one consumer per group.

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

    clientId — identifies this application in Kafka logs and metrics; use a meaningful service name.

  2. 2

    groupId — identifies the consumer group; Kafka delivers each message to one consumer per group.

  3. 3

    brokers — array of broker addresses; provide multiple for high availability.

  4. 4

    NestJS uses kafkajs internally — all kafkajs producer and consumer options are supported.

  5. 5

    Each microservice instance with the same groupId competes for partition assignments — enabling horizontal scaling.

Scenario Questions

0-2 years experience

  1. 1How would you set up a NestJS microservice to consume messages from a specific Kafka topic?
  2. 2What configuration steps are required to connect a NestJS app to a Kafka broker?
  3. 3If the microservice can’t establish a connection, which logs or error messages would you check first?

2-5 years experience

  1. 1You need to add a new Kafka consumer to an existing NestJS service that already produces messages. How would you organize the module and why?
  2. 2During testing you notice duplicate messages after the NestJS service restarts. What could be causing this and how would you resolve it?
  3. 3If the Kafka broker address changes at runtime, how would you make your NestJS microservice adapt without redeploying?

5-8 years experience

  1. 1Your system must handle 10 k messages per second across multiple partitions. How would you configure NestJS and Kafka to achieve high throughput and low latency?
  2. 2Explain how you would implement a graceful shutdown for a NestJS Kafka microservice to avoid message loss.
  3. 3What trade‑offs do you consider when choosing manual offset commits versus auto‑commit in a NestJS Kafka consumer?

8+ years experience

  1. 1Your organization is migrating from a legacy RabbitMQ event bus to Kafka, and many teams have NestJS services. How would you design a migration strategy that minimizes downtime and keeps both systems in sync?
  2. 2Discuss how you would centralize Kafka client configuration across dozens of NestJS microservices to enforce consistency and support versioned schema evolution.
  3. 3If you need to support multi‑region Kafka clusters with NestJS services, what architectural changes and operational concerns would you address?

Follow-up Questions

  • Can you sketch the code you would write for the Kafka client setup?
  • How would you verify that your consumer processes messages exactly once?
  • What monitoring or metrics would you put in place to detect consumer lag?
Share

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