The 30 second answer
I add a cache when data is read often, changes rarely, and the database is the measured bottleneck. I use cache-aside with a time to live and delete entries on updates. The risks are stale data, a stampede of requests when a hot key expires, memory growth without eviction, and one more system to run, so I measure the hit rate.
When data is read often and changes rarely, and the database is the bottleneck. I use cache-aside in Redis with a TTL, and I delete the key on update. The risks are stale data, a cold cache after a restart, and many misses at once on a hot key. Under high load I also watch Redis memory and hot keys.
# add a cache when reads are hot, data changes rarely, and the DB is the measured bottleneck
cache.get(key) or (db.read(key) + cache.set(key, ttl=60))
# on write: delete the key
# risks: stale data, stampede on expiry, and caching a user-specific response under a shared keyAlternate interview scenarios
"Reads from our managed Postgres are slow. Should we keep a local synced copy of the data in the application, or make the database faster?"
A local copy is a bigger step than a cache. A sync engine subscribes to the database's logical replication stream, filters it down to a declared subset such as one tenant's rows, and keeps that subset in a store inside the app, on the client or at the edge. Reads inside the subset become local, but writes still go to the central Postgres through an API. The committed change only arrives back through the stream later. So the app must show optimistic local state and reconcile it, or roll it back if the server rejects the write. That reconciliation is a correctness problem the team has to own. Before adding it, I check why the database is slow. On network-attached storage, an I/O-bound workload can slow down while CPU and memory look fine, so I look at cache hit ratio, I/O wait and the volume's IOPS limits. Then I fix queries, pooling and storage, and add read replicas. A local copy pays off for offline use, unreliable networks, or many clients reading the same stable subset. It pays off less when the working set is hard to predict, such as AI agents whose queries change per task, because each copy gets little reuse.
Editor's note:
this scenario follows a ClickHouse engineering blog post (November 2026) that argues for a faster central Postgres. It is a vendor article; its throughput comparison is a vendor benchmark and is not repeated here as fact.
"Your Redis cache is working, but database load is still at 100%. What is wrong?"
A working cache can still miss the queries that cost the most. I check three things. First, the hit rate: Redis INFO reports keyspace hits and misses, and a low ratio means keys expire too soon, are evicted under memory pressure, or the cache keys are too specific, for example including a timestamp. Second, what the database is actually running: the top statements by total time often turn out to be writes, reports, or queries the cache never covered. Third, misses that arrive together: when a hot key expires, every request hits the database at once, so I add a lock or single flight per key, jittered TTLs, or early refresh. Bulk invalidation after a deploy can also empty the cache. The fix depends on which one it is: cache the right queries, size the cache, add the missing index, or move the heavy reads to a replica.
"We added nodes to our Redis Cluster for a flash sale, but one node is still at 100% CPU. Why didn't scaling help?"
That is usually a hot key, not a capacity problem. Redis Cluster maps every key to one of 16384 hash slots with CRC16 of the key modulo 16384, and each slot has one primary. More nodes spread different keys, but every request for one popular key still lands on the primary for its slot. Moving that slot only moves the problem. First I confirm it: per-node CPU and ops, client-side key sampling, and redis-cli --hotkeys, which only works when the maxmemory policy is an LFU policy. Then I pick a fix for how stale the value may be. A small local cache, ideally with Redis client-side caching so the server sends invalidation messages, removes most reads. Replica reads with READONLY add read capacity, but replication is asynchronous, so a replica may return stale data. For an extreme key I keep a few copies such as product:101:0 to :2, check that they hash to slots on different primaries, and update or invalidate all of them on writes. Hash tags do the opposite: {product:101} forces keys into the same slot. A cache stampede is a different problem, where many misses hit the database at once after expiry, and request coalescing addresses it.
"Which cache write strategy, eviction policy and invalidation approach would you choose, and Redis or Memcached?"
I pick per data type. Cache-aside is my default for read-heavy data. Write-through writes the cache and the store together, which keeps the cache fresh but adds write latency; it does not by itself give payment-grade consistency, because the database remains the record and the two writes can still diverge on failure. Write-back acknowledges after the cache write and flushes later, which is fast but can lose writes in a crash, so I use it only where loss is acceptable. Write-around skips the cache on writes, so rarely read data does not push out hot keys. Eviction and expiry are different things: a TTL expires a key on time, while maxmemory policies such as allkeys-lru, allkeys-lfu or volatile-ttl decide what to remove under memory pressure, and noeviction makes writes fail instead. For invalidation I combine TTLs with deleting keys on change, publishing change events, or reading the database change log with change data capture. For stampedes I add per-key locking, jittered TTLs, warming before expected peaks, or serving a stale value while one request refreshes, which HTTP standardises as stale-while-revalidate for CDNs. Redis gives data structures, persistence and replication; Memcached is a simple key-value cache, and both scale out across servers. A CDN caches responses at the edge, so it suits public, cacheable content.
Sources (16)
- Microsoft Azure Architecture Center: Cache-Aside patternlearn.microsoft.com
- Redis docs: EXPIREredis.io
- PostgreSQL 17 docs: Logical replicationpostgresql.org
- Amazon EBS volume types (IOPS and throughput limits)docs.aws.amazon.com
- ClickHouse blog: Does your application need local data or faster Postgres?clickhouse.com
- Redis docs: INFO (keyspace_hits, keyspace_misses, evicted_keys)redis.io
- PostgreSQL docs: pg_stat_statementspostgresql.org
- Redis docs: Cluster specification (hash slots, hash tags, READONLY)redis.io
- Redis docs: redis-cli (--hotkeys requires an LFU maxmemory-policy)redis.io
- Redis docs: Client-side caching (tracking and invalidation)redis.io
- Redis docs: READONLYredis.io
- Redis docs: Replication (asynchronous by default)redis.io
- DEV Community: Redis Hot Keys: Why Adding More Nodes Doesn't Always Helpdev.to
- Redis docs: Key eviction policiesredis.io
- RFC 5861: HTTP Cache-Control extensions for stale content (stale-while-revalidate)rfc-editor.org
- Memcached: About (a shared memory pool across servers)memcached.org