
6 Redis Caching Patterns That Cut Node.js API Response Time from 1.5s to 150ms
Most Node.js apps hit the database on every request. That works until traffic grows and your API starts returning responses in seconds instead of milliseconds. These Redis caching patterns remove most database reads and turn slow endpoints into memory lookups. 1 Cache database queries instead of running them on every request Most APIs query the database even when the same data was requested seconds ago. Before (PostgreSQL on every request) export async function getJobs ( filters ) { const jobs = await prisma . jobPosting . findMany ({ where : { ...( filters . remote && { remote : true }) }, include : { company : { select : { name : true , website : true } } }, orderBy : { createdAt : " desc " }, take : 20 }) return jobs } After (Redis cache aside pattern) import redis from " ../lib/redis " export async function getJobs ( filters ) { const cacheKey = `jobs: ${ JSON . stringify ( filters )} ` const cached = await redis . get ( cacheKey ) if ( cached ) { return JSON . parse ( cached ) } c
Continue reading on Dev.to
Opens in a new tab



