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

How do you implement the outbox pattern with Kafka in NestJS to guarantee exactly-once message delivery?

Write the domain event to an outbox table in the same database transaction as the business entity write. A separate relay service polls the outbox and publishes unpublished events to Kafka, then marks them as published. This guarantees the event is eventually published even if the app crashes between the write and the publish.

Outbox entity, transactional write, and relay publisher
Outbox pattern guarantees and design notes:
  1. 1

    The event and business entity are written atomically — no event is lost even if the process crashes after the DB write.

  2. 2

    The relay is idempotent — if it crashes mid-relay, unpublished events are picked up on the next poll.

  3. 3

    Use a distributed lock (Redis SETNX) if multiple relay instances run concurrently to prevent duplicate publishes.

  4. 4

    Mark events as published after Kafka confirms receipt — not before.

  5. 5

    Add a dead-letter column for events that fail repeatedly so operators can inspect and replay them.

Difficulty: 7/10
Topics: outbox pattern, Kafka exactly-once, NestJS transaction management

Scenario Questions

0-2 years experience
  1. 1

    Suppose you need to write a NestJS service that creates a new order and publishes an 'order.created' event to Kafka. How would you use the outbox pattern to ensure the event is only sent if the order is successfully saved?

  2. 2

    If the outbox table contains a row that hasn't been processed yet, what will happen when your background worker picks it up and the Kafka broker is temporarily unavailable?

  3. 3

    Can you walk me through the steps your code would take from receiving the HTTP request to committing the outbox record?

2-5 years experience
  1. 1

    We have a microservice that writes to Postgres and then publishes to Kafka using the outbox pattern. Lately, some messages are being duplicated after a service restart. What could cause that and how would you fix it?

  2. 2

    Imagine you need to add a new field to the outbox payload without breaking existing consumers. How would you evolve the schema while keeping exactly‑once semantics?

  3. 3

    During a load test, the outbox processing thread becomes a bottleneck. What trade‑offs would you consider to improve throughput while preserving ordering guarantees?

5-8 years experience
  1. 1

    Design a scalable outbox processing component for a NestJS application that handles millions of events per day. Discuss partitioning, idempotency, and how you would monitor delivery failures.

  2. 2

    How would you integrate Kafka's transactional producer API with NestJS's TypeORM transaction to achieve exactly‑once delivery across the database and Kafka?

  3. 3

    If a downstream consumer crashes after processing a message but before committing its offset, how does your outbox design prevent duplicate processing, and what additional safeguards would you add?

8+ years experience
  1. 1

    Our organization is moving from a monolith to multiple NestJS services that all use the outbox pattern with a shared Kafka cluster. What architectural guidelines would you set to avoid cross‑service ordering issues and to standardize outbox implementations?

  2. 2

    We have legacy services that directly publish to Kafka without an outbox. How would you plan a migration strategy that minimizes downtime and ensures exactly‑once semantics across the whole system?

  3. 3

    Consider long‑term maintenance: how would you version the outbox schema and handle data migrations without losing in‑flight messages, especially when multiple teams own different services?

Follow-up Questions

  • What would you do if the database transaction commits but the Kafka publish fails?
  • How do you ensure the outbox worker doesn't reprocess already‑sent messages after a crash?
  • Can you explain the trade‑offs between using Kafka transactions versus idempotent producers in this setup?