0
0
NestJSframework~8 mins

Redis transport in NestJS - Performance & Optimization

Choose your learning style9 modes available
Performance: Redis transport
MEDIUM IMPACT
This affects the speed and responsiveness of message passing between microservices or modules in a NestJS application.
Sending messages between microservices using Redis transport
NestJS
@EventPattern('channel')
async processMessage(@Payload() message) {
  await heavyAsyncProcessing(message);
}
Using asynchronous processing frees the event loop, allowing faster handling of incoming messages and better responsiveness.
📈 Performance GainNon-blocking message handling reduces INP and improves throughput.
Sending messages between microservices using Redis transport
NestJS
@EventPattern('channel')
processMessage(@Payload() message) {
  // process message synchronously
  heavySyncProcessing(message);
}
Processing messages synchronously blocks the event loop, causing delays in handling other messages and increasing latency.
📉 Performance CostBlocks event loop during processing, increasing INP and causing slower message throughput.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Synchronous message processingN/AN/AN/A[X] Bad
Asynchronous message processingN/AN/AN/A[OK] Good
Rendering Pipeline
Redis transport in NestJS operates outside the browser rendering pipeline but impacts user experience by affecting server responsiveness and interaction latency.
Message Queueing
Event Loop Processing
Network I/O
⚠️ BottleneckEvent Loop Processing when synchronous/blocking code is used
Core Web Vital Affected
INP
This affects the speed and responsiveness of message passing between microservices or modules in a NestJS application.
Optimization Tips
1Avoid synchronous blocking code in Redis message handlers to keep the event loop free.
2Use asynchronous processing to improve message throughput and reduce latency.
3Monitor event loop delays in DevTools Performance panel to detect blocking operations.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance risk when using Redis transport with synchronous message handlers in NestJS?
AIncreasing DOM reflows in the browser
BBlocking the event loop and increasing message latency
CAdding large bundle size to the frontend
DCausing layout shifts on the page
DevTools: Performance
How to check: Record a session while sending messages and observe the event loop responsiveness and task durations.
What to look for: Look for long tasks blocking the event loop which indicate synchronous processing causing delays.