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.

  • NestJSNestJS
  • PostgreSQLPostgreSQL
  • RedisRedis
  • TypeScriptTypeScript
  • Node.jsNode.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

    NestJS

    Backend

    Handles requests, business logic and APIs

    Learning: Hard

    Status: Active

  • PostgreSQL

    PostgreSQL

    Database

    Stores and queries the data

    Learning: Moderate

    Status: Active

  • Redis

    Redis

    Cache

    Keeps frequently read data in memory

    Learning: Moderate

    Status: Active

  • Node.js

    Node.js

    Runtime

    Runs the code on the server or device

    Learning: Moderate

    Status: Active

  • TypeScript

    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. 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. 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. 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. 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. 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

How quickly a team ships features

Ease of learning
6.2 out of 10, catalog average 7.2

Higher means easier to pick up

Scalability
8.0 out of 10, catalog average 7.6

How far it grows before a redesign

Performance
7.6 out of 10, catalog average 7.5

Speed of the running application

Maintainability
7.6 out of 10, catalog average 7.2

How well the codebase ages

Ecosystem
7.8 out of 10, catalog average 8.2

Libraries, hosting, docs and hiring

Flexibility
7.4 out of 10, catalog average 7.4

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.

Sources

Reviewed on November 19, 2026 against the documentation below. Found something out of date? Suggest a correction. Read our methodology.

Stacks that share technologies with NestJS + Redis + PostgreSQL.