Skip to content

Reliability: In-memory TTL cache not shared across instances, causes data inconsistency in distributed deployments #3574

@anshul23102

Description

@anshul23102

Problem

TTLCache uses in-memory storage (cache.ts line 18). In distributed/serverless deployments, each instance has separate cache causing inconsistent data.


Recommended Solution

Use Redis for distributed caching:

import { Redis } from '@upstash/redis';

const redis = new Redis({
  url: process.env.REDIS_URL
});

export class DistributedTTLCache<T> {
  async get(key: string): Promise<T | null> {
    const data = await redis.get(key);
    return data as T | null;
  }
  
  async set(key: string, value: T, ttlSeconds: number): Promise<void> {
    await redis.setex(key, ttlSeconds, JSON.stringify(value));
  }
}

Program Template

  • GSSoC '26

Suggested Labels

architecture, caching, redis, distributed, gssoc-eligible
EOF
)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions