Hot and warm memory tiers.
TTL issues lead to stale data and unbounded memory growth. This playbook ensures TTL is applied consistently in hot tier and enabled in Cosmos.
- Stale data served
- Memory growth with low eviction
- Verify TTL is set on write.
- Check Redis key TTL and Cosmos TTL policy.
- Identify keys missing TTL.
- Fix TTL settings in write paths.
- Enable Cosmos container TTL if disabled.
- Run cleanup for stale keys.
- Add unit tests for TTL behavior.
- Enforce TTL defaults at builder level.
- Set TTL explicitly on all hot writes.
- Enable TTL at the Cosmos container level.
- Add tests verifying expiry.
async def set_session(key: str, value: str):
await hot_memory.set(key, value, ttl=300)import asyncio
async def test_ttl_expiry():
await hot_memory.set("k", "v", ttl=1)
await asyncio.sleep(2)
assert await hot_memory.get("k") is Noneflowchart TD
A[TTL not expiring] --> B[Inspect write paths]
B --> C{TTL set?}
C -->|No| D[Fix hot writes]
C -->|Yes| E[Check Cosmos TTL settings]
E --> F[Enable container TTL]
If data growth threatens capacity, scale tiers and notify platform owner.