Realtime and Messaging for NestJSs
Realtime and messaging in NestJS means two-way and service-to-service communication beyond plain request and response. Gateways give WebSocket support through socket.io or ws, while the microservices package uses transports like TCP, Redis, NATS, RabbitMQ or Kafka with message and event patterns.
Stage: Integrations · Part of the NestJS roadmap · Last reviewed 19 November 2026
What to learn in Realtime and Messaging
- Create a WebSocket gateway with @SubscribeMessage handlers
- Broadcast events to rooms and connected clients
- Build a microservice with MessagePattern and call it from a client
- Tell request-response messages from fire-and-forget events
- Connect a NestJS service to a message broker such as RabbitMQ
Realtime and Messaging interview questions
What is the difference between @MessagePattern and @EventPattern?
@MessagePattern handles request-response messages: the caller waits for a reply. @EventPattern handles events where the sender does not expect a response, so multiple services can react to it and the sender is not blocked.
How does a NestJS gateway handle authentication for WebSockets?
Guards work on gateways too. A common approach is to read a token from the handshake auth or headers in a guard or in handleConnection, verify it, attach the user to the socket, and disconnect the client if verification fails.
Where Realtime and Messaging fits in the NestJS roadmap
Realtime and Messaging belongs to the Integrations stage (intermediate level). Beyond HTTP.
Other units in this stage
Back to the full NestJS roadmap