0
0
NestJSframework~8 mins

Job options (delay, attempts, priority) in NestJS - Performance & Optimization

Choose your learning style9 modes available
Performance: Job options (backoff, attempts, priority)
MEDIUM IMPACT
This concept affects how background jobs are scheduled and retried, impacting server responsiveness and throughput.
Scheduling background jobs with retries and priority
NestJS
await queue.add('email', data, { attempts: 3, backoff: 5000, priority: 1 });
Retries are spaced out with backoff to reduce load; numeric priority ensures proper job ordering.
📈 Performance GainReduces CPU spikes and memory pressure by spreading retries; improves job throughput.
Scheduling background jobs with retries and priority
NestJS
await queue.add('email', data, { attempts: 10, backoff: 0, priority: 1 });
No backoff causes immediate retries on failure, potentially overloading the server; using string priority may not be supported and cause unexpected behavior.
📉 Performance CostTriggers repeated CPU spikes and memory usage during retries, blocking other jobs.
Performance Comparison
PatternCPU UsageMemory UsageJob ThroughputVerdict
Immediate retries with no backoffHigh spikesHighLow due to blocking[X] Bad
Retries with backoff and limited attemptsModerate and stableModerateHigh and smooth[OK] Good
Rendering Pipeline
Job options affect the server's job queue processing, influencing CPU scheduling and memory usage rather than browser rendering.
Job Scheduling
Retry Handling
Queue Prioritization
⚠️ BottleneckRetry Handling when too many immediate retries cause CPU overload
Optimization Tips
1Add backoff between retry attempts to reduce CPU spikes.
2Limit retry attempts to prevent infinite loops and resource exhaustion.
3Use numeric priority to control job processing order efficiently.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of adding a backoff between job retry attempts?
AIt makes jobs run faster immediately after failure
BIt increases memory usage by keeping jobs longer
CIt spreads out retries to reduce CPU spikes and server overload
DIt disables retries completely
DevTools: Node.js Profiler or NestJS Logger
How to check: Run the app with profiling enabled; monitor CPU and memory during job retries; check logs for retry frequency and delays.
What to look for: Look for CPU spikes during retries and memory growth; steady CPU and controlled retry logs indicate good performance.