Redis › Keyspace Notifications
How would you build a reliable cache invalidation system using keyspace notifications, while accounting for their delivery limitations?
AdvancedAnswer
You would use keyspace notifications as a fast, best effort mechanism to quickly invalidate related cache entries, but combine it with a periodic reconciliation process that independently verifies cached data against the source of truth, ensuring that even if a notification is occasionally missed, stale data does not persist indefinitely.
SUBSCRIBE __keyevent@0__:set
-- On notification, invalidate related cache entries
-- A separate periodic job also double checks cache freshnessReal-world example An e-commerce platform uses keyspace notifications for fast, immediate cache invalidation when product data changes, while also running an hourly reconciliation job that catches any rare cases where a notification might have been missed.