Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Redis keyspace notifications: keep correctness outside an ephemeral event channel

Last updated: 5 Oct 20267 min read
tutorial
AdvancedBy AITrove Editorial

Redis keyspace notifications publish selected changes and expirations over Pub/Sub. The channel is useful for hints, metrics, and local cache refreshes, but it is not a durable change log. A subscriber disconnected during an expiration or failover loses the event; after reconnect there is no built-in offset to replay it. Expiration notification timing is also not a business deadline guarantee because key deletion can be discovered later. A system that must invoice, refund, or release capacity after a timeout needs a durable source of truth and a reconciliation job. Notifications may wake the job early, but the job must also find missed work on its own.

Operational decision

A reservation cache key expires after 47 minutes. A notification subscriber normally wakes a cleanup worker, but its connection drops for nine minutes during a broker restart. The authoritative reservation table stores expiry timestamps and state. Every two minutes, a bounded query finds overdue open reservations, marks them once through a conditional database update, and emits a unique release event. On reconnect, the subscriber resumes hint handling but does not assume it saw every expiration. The drill expires 83 synthetic keys during the disconnect and verifies all 83 reservations reach the intended state exactly once through reconciliation, without relying on a replayable Redis notification channel.

Output
Source of truth: reservation table with expiry and state
Redis TTL: 47 minutes, advisory cache behavior
Subscriber outage: 9 minutes
Missed notifications: 83 synthetic expirations
Reconciler: every 2 minutes, bounded overdue query
Effect key: reservation ID + release generation

Cost and verification

A reconciliation scan adds database read and write cost, so index expiry and state and process a capped batch. A long interval increases completion delay; a very short one can load the database unnecessarily. Measure backlog age and release count. Pub/Sub subscriptions also consume connection and network resources, so enable only event classes with a real consumer. This design deliberately tolerates duplicate hints: the conditional state transition decides whether the effect is new. If notifications are used for analytics, annotate data gaps during disconnects rather than treating the feed as complete history.

Common Mistakes

  • Do not make a keyspace notification the only trigger for a financial effect.
  • Do not assume an expiration event fires exactly at the TTL deadline.
  • Do not treat Pub/Sub reconnect as replay.

Connected lessons

Practice and check

devops
redis
data-operations
Storage details