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

How do you implement an API Gateway pattern in NestJS that aggregates multiple microservices?

Create an HTTP-facing NestJS application that injects multiple ClientProxy instances — one per downstream service. Use sequential calls when each step depends on the previous result. Use Promise.all() for independent parallel calls. Map RpcException errors to appropriate HTTP exceptions using catchError() in the pipeline.

API Gateway controller aggregating multiple services
API Gateway design principles:
  1. 1

    Use Promise.all() for independent downstream calls — runs them in parallel and halves latency.

  2. 2

    Use sequential awaits only when each call depends on the result of the previous one.

  3. 3

    Apply a global RpcExceptionFilter to convert microservice errors to HTTP responses on the gateway.

  4. 4

    Add timeout operators (timeout(3000)) to prevent a slow service from hanging the gateway response.

  5. 5

    The gateway should be thin — business logic belongs in the downstream services, not the gateway.

Difficulty: 5/10
Topics: API Gateway, NestJS microservices, request aggregation

Scenario Questions

0-2 years experience
  1. 1

    You need to expose a single endpoint that calls two internal NestJS microservices and returns a combined response. How would you set up the gateway controller and service to achieve this?

  2. 2

    If one of the downstream services times out, what would the gateway return and how would you handle it in NestJS?

  3. 3

    Describe the steps to register a microservice client in the gateway module.

2-5 years experience
  1. 1

    We have a new feature where the gateway must aggregate data from three microservices, each with different response formats. How would you design the transformation layer, and what trade‑offs would you consider?

  2. 2

    During testing the gateway started returning 502 errors when the user service is under load. Walk me through how you would debug the issue in NestJS.

  3. 3

    Explain why you might choose HTTP vs. TCP transport for the microservice clients in the gateway, and how that choice impacts latency and reliability.

5-8 years experience
  1. 1

    Our platform expects the gateway to handle 10k requests per second and aggregate data from five services. What architectural changes would you make in NestJS to ensure scalability and low latency?

  2. 2

    How would you implement circuit breaking and fallback responses in a NestJS API Gateway that aggregates multiple services?

  3. 3

    Discuss how you would handle versioning of downstream microservice APIs in the gateway without redeploying the entire gateway.

8+ years experience
  1. 1

    We are consolidating several legacy microservices into a new NestJS API Gateway. How would you plan the migration to minimize downtime and ensure backward compatibility across teams?

  2. 2

    At a company‑wide level, what governance and observability strategies would you put in place for a NestJS API Gateway that serves as the entry point for dozens of services?

  3. 3

    If the organization decides to move from a monolithic gateway to a distributed edge‑proxy model, how would you redesign the NestJS gateway architecture and what impact would it have on cross‑team responsibilities?

Follow-up Questions

  • What metrics would you expose to monitor the gateway in production?
  • Can you sketch a code snippet that demonstrates your error‑handling approach?
  • How would you structure end‑to‑end tests for the aggregation flow?