How to properly migrate a large NestJS monolith to microservices with a single API Gateway?
I'm currently working on a Node.js project using the NestJS framework. At the moment, the architecture is monolithic, but I want to transition to a microservices-based architecture for better scalability and separation of concerns. Here's what I'm aiming for: I want to have a single API Gateway that exposes all REST APIs to the frontend. I plan to split the current codebase into multiple specific microservices. I'm considering using Kafka (or Redis) for inter-service communication. I have some questions about how to approach this migration properly: 1. Where should my API routes live? Should each microservice expose its own APIs, and the gateway just forwards requests to them? Or should only the API Gateway expose all APIs and communicate with microservices internally (e.g., via Kafka/RPC)? 2. What is the best pattern to follow with NestJS in this case? Is it common to keep all HTTP routes in the gateway and use message-based communication under the hood? Are there clean ways to organize large numbers of routes that used to live in the monolith? 3. Is Kafka a good choice for this architecture? I’m debating between Kafka and Redis for message communication between microservices. What are the trade-offs in this use case? Any guidance on migration patterns, NestJS microservices best practices, and gateway-service communication would be greatly appreciated.
I'm currently working on a Node.js project using the NestJS framework. At the moment, the architecture is monolithic, but I want to transition to a microservices-based architecture for better scalability and separation of concerns.
Here's what I'm aiming for:
- I want to have a single API Gateway that exposes all REST APIs to the frontend.
- I plan to split the current codebase into multiple specific microservices.
- I'm considering using Kafka (or Redis) for inter-service communication.
I have some questions about how to approach this migration properly:
1. Where should my API routes live?
- Should each microservice expose its own APIs, and the gateway just forwards requests to them?
- Or should only the API Gateway expose all APIs and communicate with microservices internally (e.g., via Kafka/RPC)?
2. What is the best pattern to follow with NestJS in this case?
Is it common to keep all HTTP routes in the gateway and use message-based communication under the hood?
Are there clean ways to organize large numbers of routes that used to live in the monolith?
3. Is Kafka a good choice for this architecture?
I’m debating between Kafka and Redis for message communication between microservices.
What are the trade-offs in this use case?
Any guidance on migration patterns, NestJS microservices best practices, and gateway-service communication would be greatly appreciated.