Nest
Nest

How can we implement Redis + BullMQ caching to match Fastify performance in NestJS enterprise workloads?

March 18, 2026

Redis for fast in-memory caching + BullMQ for background job queuing gives NestJS the same blazing speed as Fastify by offloading heavy work and caching hot data.​

Use @nestjs/cache-manager with Redis store for HTTP response caching, and @nestjs/bullmq for async job processing. This combo handles high throughput by caching reads instantly and queuing writes/jobs separately.

Step 1:-Install: npm i @nestjs/cache-manager cache-manager-redis-store @nestjs/bullmq bullmq ioredis

Code

/ app.module.ts
import { Module } from '@nestjs/common';
import { CacheModule } from '@nestjs/cache-manager';
import { BullModule } from '@nestjs/bullmq';
import * as redisStore from 'cache-manager-redis-store';

@Module({
  imports: [
    CacheModule.registerAsync({
      useFactory: () => ({
        store: redisStore,
        host: 'localhost',
        port: 6379,
        ttl: 300, // 5min
        isGlobal: true,
      }),
    }),
    BullModule.forRoot({
      connection: { host: 'localhost', port: 6379 },
    }),
  ],
})
export class AppModule {}
      

Step 2:-
Controller with cache + queue

Code

import { Controller, Get, CacheInterceptor, Ctx, CacheKey } from '@nestjs/common';
import { UseInterceptors, InjectQueue } from '@nestjs/bullmq';
import { Queue } from 'bullmq';

@Controller('users')
export class UserController {
  constructor(@InjectQueue('process') private processQueue: Queue) {}

  @Get()
  @UseInterceptors(CacheInterceptor)
  @CacheKey('users:all')
  async getUsers() {
    return this.userService.findAll(); // Auto-cached!
  }

  @Post()
  async createUser(@Body() user: any) {
    // Queue heavy processing
    await this.processQueue.add('process-user', user);
    return { message: 'User queued for processing' };
  }
}
      
Hire Now!

Need Help with Nest Development ?

Ready to leverage the power of conversational AI? Start your project with Zignuts expert AI developers.
bg-image
download-image
Company Deck
PDF, 3MB
© 2026 Zignuts Technolab. All Rights Reserved.
branch imagesbranch imagesbranch imagesbranch imagesbranch imagesbranch images