Real World Example

Flash Sale at Big Billion Days Scale

During sales like Flipkart Big Billion Days or Amazon Great Indian Festival, product pages get millions of hits per minute. A typical NestJS setup combines all three tools:

  • Cache: product details and prices in Redis with a short TTL (30–60 s); the database sees a tiny fraction of reads.
  • Queue: "place order" reserves stock synchronously, but invoice, email, SMS, analytics and seller notification are BullMQ jobs.
  • Cron: a job at 23:59:00 warms the cache for the sale products; another one releases stock from unpaid orders every few minutes.

src/sale/sale-warmup.service.ts

@Injectable()
export class SaleWarmupService {
  constructor(
    private readonly prisma: PrismaService,
    @Inject(CACHE_MANAGER) private readonly cache: Cache,
    @InjectQueue('analytics') private readonly analytics: Queue,
  ) {}

  @Cron('0 59 23 * * *', { timeZone: 'Asia/Kolkata' })            // 6-field cron: seconds first
  async warmUp() {
    const products = await this.prisma.product.findMany({ where: { inSale: true } });
    await Promise.all(products.map((p) => this.cache.set(`product:${p.id}`, p, 10 * 60_000)));
    await this.analytics.add('sale-warmup', { count: products.length });
  }
}