# Cache invalidation is a distributed systems problem

DevFeed: [Cache invalidation is a distributed systems problem](<https://devfeed.tech/articles/cache-invalidation-is-a-distributed-systems-problem-in-a-convenience-costume-39604.md>)

Original publisher: [Read original article](<https://ankit-rana.com/logs/52-cache-invalidation-distributed-problem/>)

Author: hello@ankit-rana.com

Published: 2026-09-13T00:00:00Z

Content type: tutorial

Language: en

Sources: [Ankit Rana | Mechanical Sympathy](<https://devfeed.tech/sources/ankit-rana-mechanical-sympathy.md>)

Topics: [Cache](<https://devfeed.tech/topics/cache.md>), [Caching](<https://devfeed.tech/topics/caching.md>), [distributed-systems](<https://devfeed.tech/topics/distributed-systems.md>)

Tags: [cache](<https://devfeed.tech/tags/cache.md>), [cache-invalidation](<https://devfeed.tech/tags/cache-invalidation.md>), [caching](<https://devfeed.tech/tags/caching.md>), [consistency](<https://devfeed.tech/tags/consistency.md>), [distributed](<https://devfeed.tech/tags/distributed.md>), [distributed-systems](<https://devfeed.tech/tags/distributed-systems.md>), [ordering](<https://devfeed.tech/tags/ordering.md>), [race-conditions](<https://devfeed.tech/tags/race-conditions.md>), [redis](<https://devfeed.tech/tags/redis.md>), [ttl](<https://devfeed.tech/tags/ttl.md>)

## AI overview

Cache invalidation coordinates updates between a database and a cache without a shared transaction. The article explains how operation ordering can let a concurrent reader repopulate stale data and recommends writing to the database before invalidating the cache, followed by a second invalidation to close the remaining race.

## Source excerpt

A cache and a database are two stores that must agree, which makes every invalidation a distributed transaction without a coordinator. The ordering matters more than the mechanism: invalidating before the database write leaves a window where a concurrent reader repopulates the cache with the old value and it stays wrong until the TTL expires. Deleting the key rather than writing the new value removes a whole class of ordering bug, because two concurrent deletes commute and two concurrent writes do not.