Posts

Showing posts with the label bullmq

REFRESH-AHEAD

Image
Introduction This article will guide you on how to implement REFRESH-AHEAD on NestJS with Redis and Postgres . We will need to use @nestjs/cache-manager to create a service that handles keys about to expire. We will also use @nestjs/bullmq for background processing to query the database and update the cache. For theoretical details, you can review the previous article where I covered this topic. Detail Create the file constant/index.ts with Queue, Job and Function as follows: export enum QueueName { CACHE_REFRESH = 'cache-refresh' , } export enum JobName { REFRESH_KEY = 'refresh-key' , } export enum FunctionName { PRODUCT_DETAIL = 'product-detail' , TRENDING_PRODUCT = 'trending-product' , } Create file module/bullmq.module.ts import { BullModule } from '@nestjs/bullmq' import { Module } from '@nestjs/common' import { ConfigModule , ConfigService } from '@nestjs/config' import { QueueName } f...

WRITE-BEHIND

Image
Introduction This article will guide you through implementing WRITE-BEHIND (WRITE-BACK) in NestJS with Redis and Postgres . Applying this mechanism will perform asynchronous writes to the Database via a Queue, so I will also use @nestjs/bullmq (BullMQ + Redis) , which is a standardized, powerful library for managing background jobs. As for theoretical content, you can review the previous article I mentioned. Detail Please install the following packages: bun add bullmq @nestjs/bullmq Create Drizzle Schema in drizzle-orm/schema/schema.ts as follows: import { bigserial, decimal, integer, pgTable, serial, text, timestamp, varchar, } from 'drizzle-orm/pg-core' export const products = pgTable ( 'products' , { id : bigserial ( 'id' , { mode : 'number' }). primaryKey (), name : varchar ( 'name' , { length : 255 }). notNull (), description : text ( 'description' ), price : decimal ( 'price' , { precision ...