Back to Blog
Jun 12, 2026
6 min read
Mukesh Kaswan

Scaling NestJS APIs to 100K+ Requests: System Design Learnings

NestJSPostgreSQLCachingSystem Design

When building CredCheck, our credit assessment platform, one of the main goals was ensuring the API could evaluate business requests with sub-second latency while processing 100K+ requests monthly without degradation. Here is how we scaled our NestJS and PostgreSQL backend.

1. Connection Pooling with Prisma

By default, serverless environments or high-concurrency microservices can quickly exhaust PostgreSQL connections. We implemented connection pooling using Prisma and PgBouncer, setting the optimal pool size based on our instance memory configurations:

// Database connection string configurations
DATABASE_URL="postgresql://user:pass@host:5432/db?connection_limit=20"

2. Multi-Level Caching

Not all assessment parameters change frequently. We implemented a two-tier caching strategy:

  • In-Memory Cache (NestJS CacheManager): For static configuration lookups and integration credentials (TTL: 10 mins).
  • Redis Cluster Cache: For historical assessment queries and computed credit indexes (TTL: 1 hour).

3. Database Indexing & Query Optimizations

We realized queries on multi-tenant assessment logs slowed down due to sequential scans. By adding composite indexes covering tenant IDs and creation dates, we cut query lookup times by 84%:

CREATE INDEX CONCURRENTLY idx_tenant_assessments 
ON "AssessmentLog" ("tenantId", "createdAt" DESC);