NestJS + Redis + PostgreSQL
NestJS APIs with PostgreSQL for durable data and Redis for caching, BullMQ job queues, rate limiting and cross-instance pub/sub, a common shape for Node services that run as several replicas.
- NestJS
- PostgreSQL
- Redis
- TypeScript
- Node.js
- Learning curve
- Hard
- Status
- Actively developed
- Reviewed
- November 2026
- Best for
- Read-heavy APIs where many requests hit the same data
- Node services running as several replicas that need shared rate limits or sessions
- Products with background jobs: emails, webhooks, media and scheduled tasks
- Real-time features that broadcast events to users connected to different instances
- Not ideal for
- Small internal CRUD app on one instance
Overview
This stack is a NestJS API with PostgreSQL as the system of record (through TypeORM, Prisma or Drizzle) and Redis as the shared, in-memory layer that several API replicas use together: response and query caching via CacheModule, background jobs via BullMQ, distributed rate limiting, Socket.IO broadcasting and short-lived state such as sessions or idempotency keys. What Redis adds is coordination between stateless instances and work moved off the request path; what it costs is a second data store with its own consistency, memory and persistence decisions.
What's inside
On top of NestJS's modules and decorators, teams must learn cache key design and invalidation, BullMQ's job lifecycle and Redis configuration, and how to keep Redis and PostgreSQL consistent when processes fail.
NestJS
Backend
Handles requests, business logic and APIs
Learning: Hard
Status: Active
PostgreSQL
Database
Stores and queries the data
Learning: Moderate
Status: Active
Redis
Cache
Keeps frequently read data in memory
Learning: Moderate
Status: Active
Node.js
Runtime
Runs the code on the server or device
Learning: Moderate
Status: Active
TypeScript
Language
The language the code is written in
Learning: Moderate
Status: Active
How it works
Requests hit any NestJS replica, which checks Redis before PostgreSQL for cached reads, writes durable changes to PostgreSQL, and pushes slow work onto a BullMQ queue in Redis that separate NestJS worker processes consume.
- 1.
Runtime to backend
A load balancer sends the request to one of several Node.js replicas; a guard checks a Redis-backed throttler or session before the controller runs.
- 2.
Backend to cache
For reads, the service or CacheInterceptor looks up a key in Redis and returns the cached value on a hit, skipping the database.
- 3.
Backend to database
On a miss or a write, the service queries PostgreSQL through the ORM, then sets or deletes the related cache keys with a TTL.
- 4.
Backend to cache
Slow side effects such as emails, webhooks or image processing are added to a BullMQ queue, stored in Redis with retry and backoff options.
- 5.
Cache to backend
A NestJS worker process with @Processor() classes pulls jobs from Redis, runs them against PostgreSQL and external APIs, and marks them completed or failed.
Strengths and drawbacks
Strengths
Background jobs inside the same codebase
@nestjs/bullmq turns queue processors into injectable Nest providers, with retries, exponential backoff, delayed and repeatable jobs, priorities and concurrency limits per worker.
Cuts database load for hot reads
Caching expensive queries or whole responses in Redis takes repeated reads off PostgreSQL, which delays the need for read replicas and keeps p95 latency low.
Coordination across replicas
Redis gives all instances a shared view for rate-limit counters, distributed locks, idempotency keys and the Socket.IO Redis adapter, so the API tier stays stateless.
Same language for API and workers
Workers reuse the same modules, DTOs and ORM entities as the API, and can be deployed from the same repository as a separate entry point.
Drawbacks
Cache invalidation and stale data
Every write path must delete or update the right keys; missed invalidations serve stale data, and popular keys expiring at once can stampede PostgreSQL. Key naming, TTLs and request coalescing need deliberate design.
Queue and cache want different Redis settings
BullMQ requires maxmemory-policy noeviction, while a cache usually wants an LRU eviction policy. Sharing one instance risks losing jobs or running out of memory, so production setups often use separate Redis instances.
Two sources of truth to keep consistent
Writing to PostgreSQL and then enqueuing to Redis is not atomic; a crash between the two loses or duplicates work. Reliable designs use an outbox table or make jobs idempotent.
Redis transport is fire-and-forget
Nest's Redis microservice transport uses pub/sub, so messages published while no subscriber is listening are lost; use BullMQ, Redis Streams or a real broker for anything that must be delivered.
Operational and licensing overhead
Redis needs memory sizing, persistence (RDB/AOF) choices and failover via Sentinel, Cluster or a managed service. After Redis's licence changes, many managed services offer Valkey, which BullMQ and ioredis work with.
Scores
Editorial ratings out of 10, comparable across every stack in the guide. They are judgement, not benchmarks. How we score
- Speed of building
- 6.8 out of 10, catalog average 7.7
- Ease of learning
- 6.2 out of 10, catalog average 7.2
- Scalability
- 8.0 out of 10, catalog average 7.6
- Performance
- 7.6 out of 10, catalog average 7.5
- Maintainability
- 7.6 out of 10, catalog average 7.2
- Ecosystem
- 7.8 out of 10, catalog average 8.2
- Flexibility
- 7.4 out of 10, catalog average 7.4
How quickly a team ships features
Higher means easier to pick up
How far it grows before a redesign
Speed of the running application
How well the codebase ages
Libraries, hosting, docs and hiring
How many kinds of product it suits
How it scales
API replicas and worker processes scale independently and stay stateless because shared state sits in Redis; Redis memory and PostgreSQL write throughput become the limits to plan for.
- Starting outMVP and first users
- One NestJS container that also runs BullMQ processors, a small managed Redis and a managed PostgreSQL instance.
- GrowingReal traffic, a few engineers
- Separate API and worker deployments, distinct Redis instances for cache and queues, PgBouncer, and Bull Board or metrics on queue depth and failed jobs.
- LargeHeavy traffic or data
- Autoscaled API replicas, worker pools per queue, Redis with replicas and automatic failover, PostgreSQL read replicas and an outbox for reliable job creation.
- EnterpriseMany teams and regions
- Redis Cluster or managed equivalents per domain, NestJS microservices communicating over Kafka or RabbitMQ for durable events, and Redis kept for caching, locks and short-lived jobs.
Where it fits
Common projects, from best fit to worst.
High-traffic read API
Product catalogues, profiles and feed endpoints serve most reads from Redis with short TTLs, protecting PostgreSQL during traffic spikes.
Great fit
Webhook, email and media processing
BullMQ queues absorb bursts, retry failed deliveries with backoff and keep slow third-party calls out of request latency.
Great fit
Real-time notifications across instances
The Socket.IO Redis adapter fans events out to users connected to any replica; very large connection counts may need a dedicated gateway.
Good fit
Small internal CRUD app on one instance
Redis adds a second store to provision, secure and back up with little benefit when PostgreSQL alone handles the load.
Poor fit
Alternatives
Similar stacks, and when you would choose them instead.
- NestJS + PostgreSQL
Start with NestJS and PostgreSQL alone while traffic is modest; PostgreSQL-backed queues and HTTP caching often cover early needs without a second data store.
CompareNestJS + Redis + PostgreSQL with NestJS + PostgreSQL - Express + Redis + PostgreSQL
Pick Express with Redis for the same cache-and-queue shape with less framework structure, suited to smaller services and teams.
CompareNestJS + Redis + PostgreSQL with Express + Redis + PostgreSQL - Django + Celery + Redis + PostgreSQL
The Python equivalent: Celery workers on Redis alongside a Django app, with a built-in admin for inspecting data.
CompareNestJS + Redis + PostgreSQL with Django + Celery + Redis + PostgreSQL - Go + Gin + PostgreSQL
Pick Go when raw throughput and memory per instance matter more than Nest's structure, often with Redis added the same way.
CompareNestJS + Redis + PostgreSQL with Go + Gin + PostgreSQL
Sources
Reviewed on November 19, 2026 against the documentation below. Found something out of date? Suggest a correction. Read our methodology.
- NestJS: Caching
Official CacheModule docs, including Redis-backed stores.
- NestJS: Queues
Official @nestjs/bullmq integration for Redis-backed job queues.
- BullMQ: Going to production
Redis settings BullMQ requires, such as maxmemory-policy noeviction.
- NestJS: WebSocket adapters
Shows a Redis-backed Socket.IO adapter for broadcasting across instances.
- NestJS: Redis microservice transport
Pub/sub-based transport and its delivery caveats.
Related stacks
Stacks that share technologies with NestJS + Redis + PostgreSQL.
NestJS + Prisma + PostgreSQL
NestJS modules and dependency injection with Prisma's schema-first, generated TypeScript client on PostgreSQL: typed end to end from database schema to controller.
- NestJS
- Prisma
- PostgreSQL
- +2
Learning: Moderate
Fastify + PostgreSQL
Fastify with PostgreSQL on Node.js, a schema-driven, plugin-based TypeScript API stack for latency-sensitive services.
- Fastify
- PostgreSQL
- Node.js
- +1
Learning: Moderate
Next.js + PostgreSQL
Next.js talking to PostgreSQL through a plain SQL driver such as node-postgres, postgres.js or Neon's serverless driver: no ORM, full control of the SQL.
- Next.js
- Node.js
- TypeScript
- +1
Learning: Moderate