Microservices
Transports compared
Choose how your services' messages travel.
A transport is the road the messages travel on: a plain TCP connection, or a message broker (a server that receives messages and delivers them). Your handlers do not change when you switch: you change the module you import and the connection options.
| Package | Server | Client | Reply mechanism |
|---|---|---|---|
microservices | TcpServer(port) | TcpClient(host, port) | the same connection |
microservices-redis | RedisServer | RedisClient | a reply channel per request |
microservices-nats | NatsServer | NatsClient | NATS request/reply |
microservices-mqtt | MqttServer | MqttClientTransport | a reply topic |
microservices-rabbitmq | RabbitServer | RabbitClient | replyTo queue and correlation id |
microservices-kafka | KafkaServer | KafkaClient | a reply topic with a correlation header |
microservices-grpc | app.grpc(port, schema) | GrpcClient | the call itself, see gRPC |
app.connectMicroservice(options) and app.startAllMicroservices() start serving; ClientsModule.register { client(name, options) } calls. Each options class takes the broker's address and group or queue names; see each page.
One contract (request and reply, events, errors, guards, roles, interceptors, filters, pipes) runs against every transport with real brokers, so they behave the same.
Which one?
| Choose | When |
|---|---|
| TCP | two services you control, nothing else to run |
| Redis | you already run Redis and want something simple (no message persistence) |
| NATS | low-latency request/reply, many small messages, queue groups for load sharing |
| RabbitMQ | reliable queues, routing, work distribution with acknowledgements |
| Kafka | a durable log you can replay, very high volume, event streams |
| MQTT | devices and low-bandwidth links |
| gRPC | typed calls with a .proto contract, streaming, many languages |
When unsure, start with what your team already operates. Nothing in your handlers is tied to the choice.
Where a new service starts reading (Kafka). A consumer group that has never read a topic starts at the end, like NestJS's fromBeginning: false, so requests and events sent before the service existed are not replayed (replaying old requests would answer callers that are long gone). Pass fromBeginning = true for event processing that needs history.
Restarts are tested
Each broker is restarted under a connected server and client, and both carry on without being restarted. See Overview.
Not verified
Failover inside a broker cluster; running against a NestJS peer; and TLS or authentication options beyond what each client library accepts as connection settings.