What is a microservice transport in the context of NestJS?
A microservice transport is the communication method used by microservices to send and receive messages. In NestJS, transports define how microservices connect and exchange data, such as TCP, Redis, or MQTT.
Click to reveal answer
beginner
Name three common transport layers supported by NestJS microservices.
TCP, Redis, and MQTT are three common transport layers supported by NestJS for microservice communication.
Click to reveal answer
intermediate
Why is TCP transport often used for microservices in NestJS?
TCP transport is used because it provides a reliable, fast, and simple connection-oriented communication channel between microservices, suitable for many internal service calls.
Click to reveal answer
intermediate
How does Redis transport help in microservice communication?
Redis transport uses Redis Pub/Sub to enable asynchronous message passing between microservices, which helps decouple services and supports event-driven architectures.
Click to reveal answer
advanced
What is the main advantage of using MQTT transport in NestJS microservices?
MQTT transport is lightweight and designed for unreliable networks, making it ideal for IoT or mobile microservices that need efficient, low-bandwidth communication.
Click to reveal answer
Which NestJS transport uses a publish-subscribe model for messaging?
ARedis
BTCP
CgRPC
DHTTP
✗ Incorrect
Redis transport uses the publish-subscribe model to send messages asynchronously between microservices.
What type of communication does TCP transport provide in NestJS microservices?
AMulticast only
BConnectionless and unreliable
CBroadcast only
DConnection-oriented and reliable
✗ Incorrect
TCP transport provides a connection-oriented and reliable communication channel.
Which transport is best suited for IoT devices in NestJS microservices?
ARedis
BTCP
CMQTT
DHTTP
✗ Incorrect
MQTT is lightweight and designed for unreliable networks, ideal for IoT devices.
In NestJS, which transport layer supports asynchronous event-driven communication?
ARedis
BTCP
CWebSocket
DHTTP
✗ Incorrect
Redis transport supports asynchronous event-driven communication using Pub/Sub.
Which of the following is NOT a built-in NestJS microservice transport?
ATCP
BHTTP
CRedis
DMQTT
✗ Incorrect
HTTP is not a built-in transport in NestJS; it requires custom implementation or third-party packages.
Explain the differences between TCP, Redis, and MQTT transports in NestJS microservices.
Think about how each transport handles message delivery and network conditions.
You got /3 concepts.
Describe a real-life scenario where you would choose Redis transport over TCP in a NestJS microservice architecture.
Consider when services should not wait for immediate responses.
You got /4 concepts.
Practice
(1/5)
1. Which transport method in NestJS microservices is best suited for simple, direct communication between services on the same network without message brokering?
easy
A. TCP transport
B. Redis transport
C. RabbitMQ transport
D. Kafka transport
Solution
Step 1: Understand transport types in NestJS
TCP transport is a simple protocol for direct communication between services on the same network without needing a message broker.
Step 2: Compare with other transports
Redis, RabbitMQ, and Kafka are message brokers used for more complex messaging patterns and scalability.
Final Answer:
TCP transport -> Option A
Quick Check:
Direct network communication = TCP transport [OK]
Hint: Direct service communication without brokers uses TCP transport [OK]
Common Mistakes:
Confusing Redis or RabbitMQ as direct transports
Thinking Kafka is a simple direct transport
Assuming TCP requires a message broker
2. Which of the following is the correct way to set up a RabbitMQ transport in a NestJS microservice?
easy
A. Transport.KAFKA with topic and brokers
B. Transport.TCP with host and port only
C. Transport.REDIS with channel and password
D. Transport.RMQ with options including urls and queue
Solution
Step 1: Identify RabbitMQ transport setup
RabbitMQ transport in NestJS uses Transport.RMQ and requires options like urls (connection strings) and queue name.
Step 2: Differentiate from other transports
TCP uses host and port, Redis uses channel and password, Kafka uses topic and brokers, so these are incorrect for RabbitMQ.
Final Answer:
Transport.RMQ with options including urls and queue -> Option D
A. The urls array should be a string, not an array
B. The queue name is empty, which is invalid
C. Transport should be TCP, not RMQ
D. Missing Redis password in options
Solution
Step 1: Check RMQ options correctness
RabbitMQ transport requires a non-empty queue name to route messages properly.
Step 2: Validate other options
The urls option is correctly an array of connection strings; transport RMQ is correct; Redis password is irrelevant here.
Final Answer:
The queue name is empty, which is invalid -> Option B
Quick Check:
Empty queue name causes config error [OK]
Hint: RabbitMQ queue name must not be empty [OK]
Common Mistakes:
Thinking urls must be a string
Confusing transport type with Redis
Ignoring empty queue name error
5. You need to design a NestJS microservice system that can handle high message throughput with guaranteed message delivery and supports multiple consumers. Which transport should you choose and why?
hard
A. RabbitMQ transport, because it supports message queues with acknowledgments and multiple consumers
B. Redis transport, because it supports pub/sub and persistence
C. TCP transport, because it is simple and fast for high throughput
D. In-memory transport, because it is the fastest for local communication
Solution
Step 1: Identify requirements for high throughput and guaranteed delivery
Guaranteed delivery and multiple consumers require a message broker with queueing and acknowledgment features.
Step 2: Evaluate transport options
TCP is simple but lacks message queueing; Redis supports pub/sub but has limited message durability; RabbitMQ supports queues, acknowledgments, and multiple consumers; in-memory is local only and not scalable.
Final Answer:
RabbitMQ transport, because it supports message queues with acknowledgments and multiple consumers -> Option A