VINOTH S

Architecting high-performance digital environments with intentional asymmetry and technical precision.

© 2024 Digital Architect.

Built with Intentional Asymmetry.

VINOTH S

Architecting high-performance digital environments with intentional asymmetry and technical precision.

© 2024 Digital Architect.

Built with Intentional Asymmetry.

Scaling to 10x Traffic with Redis
Backend Architecture 8 min read

Scaling to 10x Traffic with Redis

How I used Redis caching to reduce MongoDB read load by 80% on Srimaccafes, cutting average API response time from 240ms to 12ms.

Library
Scaling to 10x Traffic with Redis
01

The Problem

Srimaccafes was experiencing growing read load on the product catalog API. During peak hours, each product listing request would trigger 3-5 MongoDB queries — one for the product, one for the category, one for the inventory count. At 200 concurrent users, this resulted in an average response time of 240ms and noticeable UI jank on the storefront.

02

Why Redis?

The product catalog is read-heavy and update-sparse. Products are updated by an admin at most a few times per day, but they are read by hundreds of customers continuously. This is the textbook use case for a read-through cache. Redis was chosen for its sub-millisecond latency, built-in TTL support for automatic cache expiry, and its first-class support in Node.js via the ioredis client.

03

The Caching Strategy

We implemented a Cache-Aside (Lazy Loading) pattern. On a cache miss, the API queries MongoDB, stores the result in Redis with a 5-minute TTL, and returns the data. On subsequent requests within the TTL, the data is served directly from Redis. For the admin panel's write operations, a Cache Write-Through pattern was used — updating MongoDB and the Redis cache simultaneously to prevent stale reads.

Implementation
// Cache-Aside Pattern
async function getProduct(id: string) {
  const cacheKey = `product:${id}`;
  const cached = await redis.get(cacheKey);

  if (cached) return JSON.parse(cached); // Cache hit

  // Cache miss – fetch from DB
  const product = await Product.findById(id).lean();
  if (product) {
    await redis.set(cacheKey, JSON.stringify(product), 'EX', 300);
  }
  return product;
}

Verified Outcomes

API response time dropped from 240ms → 12ms (95th percentile)

MongoDB read operations reduced by 80% during peak hours

System successfully handled a 10x traffic surge during a promotional campaign

Zero stale cache incidents in production since launch

Architect Info

Vinoth S

Full Stack Developer & Digital Architect specializing in scalable systems and premium user experiences.

Collaborate

Related Deep Dives

Next.js Performance Patterns for E-commerce

Next.js Performance Patterns for E-commerce

Bulletproof Razorpay Webhooks

Bulletproof Razorpay Webhooks

VINOTH S

Architecting high-performance digital environments with intentional asymmetry and technical precision.

© 2024 Digital Architect.

Built with Intentional Asymmetry.