---
id: rating-cache
name: Rating Cache
version: 1.0.0
summary: Non-authoritative FusionCache and Redis caching layer owned by the Reviews bounded context for AI-generated book feedback summaries and review lists.
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 for per-book feedback summaries and lists returned by Rating API.
styles:
  icon: /icons/database/redis.svg
---

## Purpose & Ownership Boundary

Rating Cache is the non-authoritative FusionCache L1 + Redis L2 caching tier owned exclusively by [[service|rating-api]] in the Reviews bounded context. Caching avoids repeated multi-step LLM summarization runs for identical books while keeping [[container|rating-database]] (Azure Cosmos DB) as the sole source of truth for customer feedback.

## Data Store Profile

| Property                            | Value                                                                                                 |
| :---------------------------------- | :---------------------------------------------------------------------------------------------------- |
| **Bounded Context / Owner**         | Reviews — [[team\|catalog-experience-team]]                                                           |
| **Engine / Technology**             | Redis + FusionCache (Azure Managed Redis in cloud; Redis container locally)                           |
| **Store Type**                      | Cache                                                                                                 |
| **Primary Writer(s)**               | [[service\|rating-api]]                                                                               |
| **Primary Reader(s)**               | [[service\|rating-api]]                                                                               |
| **Authoritative / Source of Truth** | Derived Read Model (Ephemeral)                                                                        |
| **Data Classification**             | Internal                                                                                              |
| **Retention / TTL Policy**          | Transient (`6 hours` for reviewed books; `1 minute` when `reviewCount == 0`; 2-hour fail-safe window) |

## Logical Data Layout & Key Patterns

| Key Pattern                                       | Stored Data                                                                                                  | TTL / Eviction                              | Invalidation / Update Trigger                                                                     |
| :------------------------------------------------ | :----------------------------------------------------------------------------------------------------------- | :------------------------------------------ | :------------------------------------------------------------------------------------------------ |
| `rating:summary:v1:{BookId}` (`reviewCount > 0`)  | JSON summary payload (`summary`, `classification`, `averageRating`, `reviewCount`, `evidence`, `confidence`) | `6 hours` (L1 & L2)                         | Actively evicted on feedback deletions/reversions; refreshes by 6-hour TTL on additional reviews. |
| `rating:summary:v1:{BookId}` (`reviewCount == 0`) | Empty-state summary payload (avoids LLM calls)                                                               | `1 minute` (L1 & L2)                        | Actively evicted immediately when the first feedback is created, deleted, or reverted.            |
| Feedback list keys (tagged by `BookId`)           | Paginated [[entity\|feedback]] list payloads                                                                 | `30 minutes` (`Caching:Expiration` default) | Actively evicted by tag on feedback creation, deletion, or reversion.                             |
| Integration idempotency keys                      | 24-hour Kafka message deduplication markers                                                                  | `24 hours`                                  | Automatic TTL expiration after consumer processing.                                               |

## Consistency, Isolation & Security Guardrails

- **Asymmetric summary staleness window:** Deletions, reversions, and the first review on an unreviewed book evict `rating:summary:v1:{BookId}` immediately; adding another review to an already-reviewed book refreshes on the `6-hour` TTL to bound LLM summarization cost.
- **Stampede & fail-safe protection:** Distributed Redis locking ensures only one replica invokes [[agent|rating-agent]] on a cache miss, and a 2-hour fail-safe window protects availability during transient downstream issues.
- **Targeted invalidation:** To force regeneration for a single book, delete only `rating:summary:v1:{BookId}`.

:::warning
**Shared Redis Key-Prefix & Flush Isolation:** Rating Cache shares the `redis` cluster with [[container|basket-database]], [[container|catalog-cache]], [[container|order-cache]], and Notification idempotency markers. Never flush the shared Redis instance globally—doing so clears active customer baskets, distributed checkout locks, and 24-hour Kafka idempotency markers across five services.
:::

## 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 cached summary
		and review list is fully rebuildable from [[container|rating-database]] and
		[[agent|rating-agent]] on cache miss.
	</Accordion>
</AccordionGroup>

## Architecture Visualizations

<NodeGraph />

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

## Related Documentation

- [[service|rating-api]] — Owning service REST endpoints, A2A gRPC server, and summary query.
- [[container|rating-database]] — Authoritative Azure Cosmos DB store behind this cache.
- [[agent|rating-agent]] — AI agent invoked on summary cache misses.
- [[adr|adr-004-read-only-governed-feedback-summarization]] — Decision governing read-only AI summarization.
- [[doc|operational/005-backup-restore-and-dr]] — Platform backup, restore, and disaster recovery runbook.
