---
id: catalog-cache
name: Catalog Cache
version: 1.0.0
summary: Non-authoritative FusionCache and Redis caching layer owned by the Catalog bounded context for fast book detail lookups and dashboard summaries.
owners:
  - catalog-experience-team
container_type: cache
badges:
  - content: Cache
    backgroundColor: orange
    textColor: orange
technology: azure-managed-redis
authoritative: false
access_mode: readWrite
classification: internal
retention: transient
residency: eastasia
purpose: Non-authoritative cache used by Catalog API for frequently requested book details and dashboard aggregates.
styles:
  icon: /icons/database/redis.svg
---

## Purpose & Ownership Boundary

Catalog Cache is the non-authoritative, read-through caching tier owned by [[service|catalog-api]] in the Catalog bounded context in front of [[container|catalog-database]]. It pairs an in-process L1 memory tier with a shared Redis L2 distributed tier and backplane to accelerate repeated book detail lookups and dashboard aggregations across replicas.

## Data Store Profile

| Property                            | Value                                                                               |
| :---------------------------------- | :---------------------------------------------------------------------------------- |
| **Bounded Context / Owner**         | Catalog — [[team\|catalog-experience-team]]                                         |
| **Engine / Technology**             | Redis + FusionCache (Azure Managed Redis in cloud; Redis container locally)         |
| **Store Type**                      | Cache                                                                               |
| **Primary Writer(s)**               | [[service\|catalog-api]]                                                            |
| **Primary Reader(s)**               | [[service\|catalog-api]]                                                            |
| **Authoritative / Source of Truth** | Derived Read Model (Ephemeral)                                                      |
| **Data Classification**             | Internal                                                                            |
| **Retention / TTL Policy**          | Transient (30-minute default TTL; 15-second dashboard TTL; 2-hour fail-safe window) |

## Logical Data Layout & Key Patterns

| Key Pattern                  | Stored Data                                                                                                                             | TTL / Eviction                              | Invalidation / Update Trigger                                                                |
| :--------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------ | :------------------------------------------------------------------------------------------- |
| `book:{id}`                  | Pre-DTO [[entity\|book]] projection (title, description, permanent blob URN, pricing, status, relations, rating summary, `row_version`) | `30 minutes` (`Caching:Expiration` default) | Event-driven eviction on book mutations, propagated across replicas via the Redis backplane. |
| `catalog:dashboard:v1`       | Aggregated catalog dashboard counts and summary metrics                                                                                 | `15 seconds`                                | Time-based TTL expiration only (no event-driven eviction).                                   |
| Feature-scoped list keys     | Paginated catalog book list payloads                                                                                                    | `30 minutes` (`Caching:Expiration` default) | TTL expiration or tag/key eviction on catalog updates.                                       |
| Integration idempotency keys | 24-hour message deduplication markers                                                                                                   | `24 hours`                                  | Automatic TTL expiration after consumer processing.                                          |

## Consistency, Isolation & Security Guardrails

- **Permanent URNs over SAS URLs:** Cached book entries store the permanent blob URN from [[container|catalog-database]] rather than expiring SAS URLs, ensuring every API read resolves a fresh read-only SAS token from [[container|catalog-blob]].
- **Fail-safe & stampede protection:** Distributed Redis locking coordinates cache-miss factories across replicas, and a 2-hour fail-safe window serves stale entries briefly if the backing database is momentarily degraded.
- **Dashboard staleness window:** Dashboard aggregates (`catalog:dashboard:v1`) can lag live writes by up to `15 seconds` due to TTL-only expiration.

:::warning
**Shared Redis Key-Prefix & Flush Isolation:** Catalog Cache shares the `redis` cluster with [[container|basket-database]], [[container|order-cache]], [[container|rating-cache]], and Notification idempotency markers. Never issue a global `FLUSHALL`/`FLUSHDB` on the shared instance—doing so simultaneously erases active customer baskets, distributed checkout locks, and 24-hour Kafka idempotency guards across five services. Always target `book:{id}` or `catalog:*` keys for manual invalidation.
:::

## Operational & Resilience Notes

<AccordionGroup>
	<Accordion title="Hosting, scaling, and environment parity">
		- **Local vs. Cloud:** Local development runs a persistent single-container Redis instance with
		RedisInsight; cloud environments run Azure Managed Redis (`BalancedB0` in Dev, `BalancedB1` with
		HA in Staging, `BalancedB5` with HA in Production). - **Disposable state:** Every entry in
		Catalog Cache is fully rebuildable from [[container|catalog-database]] on cache miss. -
		**Observability:** Monitor FusionCache OpenTelemetry hit/miss metrics and Redis latency when
		diagnosing elevated PostgreSQL read load.
	</Accordion>
</AccordionGroup>

## Architecture Visualizations

<NodeGraph />

<MermaidFileLoader file="mermaids/catalog-cache-diagram-1.mmd" />

## Related Documentation

- [[service|catalog-api]] — Owning service read/write paths and cache eviction handlers.
- [[container|catalog-database]] — Authoritative PostgreSQL system of record behind this cache.
- [[container|catalog-blob]] — SAS URL resolution for cached book image URNs.
- [[adr|adr-004-fusioncache-redis-for-catalog-reads]] — Decision adopting two-tier FusionCache with Redis backplane.
- [[doc|operational/005-backup-restore-and-dr]] — Platform backup, restore, and disaster recovery runbook.
