Nest

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

March 18, 2026

download ready
Thank You
Your submission has been received.
We will be in touch and contact you soon!

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 ?

Work with our skilled nest developers to accelerate your project and boost its performance.
**Hire now**Hire Now**Hire Now**Hire now**Hire now

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

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' };
  }
}