---
title: Consistency and data ownership
summary: Authoritative stores, derived projections, transactional boundaries, and propagation guarantees in Catalog.
version: 1.0.0
type: engineering
order: 1
badges:
  - content: Architecture
    backgroundColor: green
    textColor: green
---

## Purpose & Scope

This document defines data ownership, transactional boundaries, cache invalidation, and eventual consistency guarantees for the [[domain|catalog]] subdomain, governing [[service|catalog-api]] and [[service|catalog-ingestion]]. Use it to reason about which stores are authoritative systems of record versus replayable projections before modifying write paths, search indexing, or cross-domain rating handlers.

## Visual Reference

The visual below illustrates how catalog mutations, scheduled vector indexing, and cross-domain rating events propagate across authoritative and derived stores.

<MermaidFileLoader file="mermaids/01-consistency-and-data-ownership-diagram-1.mmd" />

_Catalog Write, Cache Invalidation, and Index Propagation Pipeline_

## Core Invariants & Design Rules

- **Authoritative vs. derived separation:** [[container|catalog-database]] (PostgreSQL) is the sole system of record for [[entity|book]], [[entity|author]], [[entity|category]], and [[entity|publisher]] state, while [[container|catalog-blob]] owns binary cover artwork referenced by URN. Both [[container|catalog-cache]] (Redis) and [[container|catalog-vector]] (Qdrant) are disposable projections that can be cleared or rebuilt without data loss.
- **Transactional index queuing:** Mutations to [[entity|book]] records in [[container|catalog-database]] atomically upsert affected book identifiers into an internal pending-update queue via database triggers, coalescing repeated edits under a fresh `revision` UUID and timestamp.
- **Advisory-locked batch ingestion:** [[service|catalog-ingestion]] processes queued updates under PostgreSQL advisory lock `740031001` in batches of up to `200` items, acknowledging only rows whose `(book_id, revision)` pair still matches the batch snapshot so concurrent writes are never lost.
- **Soft-delete propagation:** Deleting a [[entity|book]] sets `is_deleted = true`, triggers the pending-update queue, and causes [[service|catalog-ingestion]] to remove the corresponding UUID from [[container|catalog-vector]].
- **Taxonomy deletion rules:** Deleting a [[entity|category]] or [[entity|publisher]] preserves associated books by clearing the reference, whereas deleting an [[entity|author]] with active books is rejected.
- **Discount price invariant:** A book's discount price must always remain non-negative and less than or equal to its original price.

:::warning
**Never use derived stores for purchase or checkout decisions.** [[service|order-api]] and [[service|basket-api]] must resolve prices and book existence exclusively through gRPC queries backed by [[container|catalog-database]]—never from [[container|catalog-vector]] or stale client caches.
:::

## Boundaries & Guarantees

| Concern         | Strategy & Guarantee                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Failure / Edge-Case Behavior                                                                                                                                                                                                                                                                                                                                                                                      | Related Resources                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| :-------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Persistence** | <ResourceLink id="catalog-database" type="container">catalog-database</ResourceLink> provides ACID transactions for catalog entities, pending vector updates, and Wolverine outbox/inbox tables; <ResourceLink id="catalog-blob" type="container">catalog-blob</ResourceLink> stores cover images with expiring read-only SAS URLs (`1h` default).                                                                                                                                                                                                                                                                                                                                               | Uncommitted writes never enqueue vector updates or outbox messages; missing blobs surface as unavailable cover URLs without corrupting book records.                                                                                                                                                                                                                                                              | <ResourceLink id="catalog-database" type="container">catalog-database</ResourceLink>, <ResourceLink id="catalog-blob" type="container">catalog-blob</ResourceLink>, <ResourceLink id="adr-001-postgresql-system-of-record" type="adr">adr-001-postgresql-system-of-record</ResourceLink>, <ResourceLink id="adr-005-blob-storage-for-book-images" type="adr">adr-005-blob-storage-for-book-images</ResourceLink>                                                                                                                                                                                                           |
| **Caching**     | <ResourceLink id="catalog-cache" type="container">catalog-cache</ResourceLink> uses FusionCache L1/L2 with a Redis backplane and `2h` fail-safe; book detail (`book:{id}`) and summary (`book:summary:{id}`) keys expire in `30m` and are actively invalidated on write; dashboard metrics (`catalog:dashboard:v1`) expire every `15s`.                                                                                                                                                                                                                                                                                                                                                          | List (`books:list`) and search (`books:search`) keys are tag-invalidated; if Redis is unavailable, FusionCache falls back to L1/fail-safe or direct database reads.                                                                                                                                                                                                                                               | <ResourceLink id="catalog-cache" type="container">catalog-cache</ResourceLink>, <ResourceLink id="adr-004-fusioncache-redis-for-catalog-reads" type="adr">adr-004-fusioncache-redis-for-catalog-reads</ResourceLink>                                                                                                                                                                                                                                                                                                                                                                                                       |
| **Messaging**   | <ResourceLink id="scheduler-service" type="service">scheduler-service</ResourceLink> triggers <ResourceLink id="catalog-ingestion" type="service">catalog-ingestion</ResourceLink> every `5m` UTC via <ResourceLink id="ProcessVectorBatchIntegrationEvent" type="event">ProcessVectorBatchIntegrationEvent</ResourceLink>; <ResourceLink id="catalog-api" type="service">catalog-api</ResourceLink> consumes <ResourceLink id="FeedbackCreatedIntegrationEvent" type="event">FeedbackCreatedIntegrationEvent</ResourceLink> and <ResourceLink id="FeedbackDeletedIntegrationEvent" type="event">FeedbackDeletedIntegrationEvent</ResourceLink> to project `average_rating` and `total_reviews`. | Missing books on feedback creation emit <ResourceLink id="BookUpdatedRatingFailedIntegrationEvent" type="event">BookUpdatedRatingFailedIntegrationEvent</ResourceLink> for compensation; missing books on feedback deletion complete as a no-op; exhausted retries route to <ResourceLink id="bookworm.{env}.catalog.dead-letter-queue" type="channel">`bookworm.{env}.catalog.dead-letter-queue`</ResourceLink>. | <ResourceLink id="ProcessVectorBatchIntegrationEvent" type="event">ProcessVectorBatchIntegrationEvent</ResourceLink>, <ResourceLink id="FeedbackCreatedIntegrationEvent" type="event">FeedbackCreatedIntegrationEvent</ResourceLink>, <ResourceLink id="FeedbackDeletedIntegrationEvent" type="event">FeedbackDeletedIntegrationEvent</ResourceLink>, <ResourceLink id="BookUpdatedRatingFailedIntegrationEvent" type="event">BookUpdatedRatingFailedIntegrationEvent</ResourceLink>, <ResourceLink id="bookworm.{env}.catalog.dead-letter-queue" type="channel">`bookworm.{env}.catalog.dead-letter-queue`</ResourceLink> |
| **Concurrency** | <ResourceLink id="catalog-ingestion" type="service">catalog-ingestion</ResourceLink> uses PostgreSQL advisory lock `740031001` and `(book_id, revision)` optimistic matching; inbound rating events use a `24h` Redis integration-event idempotency guard; Qdrant upserts are idempotent by book UUID.                                                                                                                                                                                                                                                                                                                                                                                           | Duplicate rating events within `24h` are ignored; concurrent book edits during an ingestion batch advance `revision` and are automatically picked up on the next run.                                                                                                                                                                                                                                             | <ResourceLink id="product-ingestion" type="flow">product-ingestion</ResourceLink>, <ResourceLink id="adr-003-database-queue-for-vector-indexing" type="adr">adr-003-database-queue-for-vector-indexing</ResourceLink>, <ResourceLink id="adr-006-reviews-rating-projection-on-book" type="adr">adr-006-reviews-rating-projection-on-book</ResourceLink>                                                                                                                                                                                                                                                                    |

<AccordionGroup>
	<Accordion title="Rating projection compensation semantics">
		[[service|rating-api]] is the authoritative owner of individual [[entity|feedback]] records.
		[[service|catalog-api]] maintains only derived `average_rating` and `total_reviews` columns on
		[[entity|book]]. If [[event|FeedbackCreatedIntegrationEvent]] arrives for a nonexistent or
		deleted book, [[service|catalog-api]] emits [[event|BookUpdatedRatingFailedIntegrationEvent]] so
		[[service|rating-api]] can revert the orphaned feedback.
	</Accordion>
	<Accordion title="Vector index rebuildability">
		Because [[container|catalog-vector]] is a pure projection of [[container|catalog-database]], any
		schema or embedding-model change can be recovered by re-enqueuing all active books into the
		pending-update queue and letting [[service|catalog-ingestion]] overwrite Qdrant points
		deterministically by UUID.
	</Accordion>
</AccordionGroup>

## Safe Change & Verification Checklist

- Keep searchable attributes synchronized between PostgreSQL pending-update triggers and [[service|catalog-ingestion]] embedding text generation, and plan a full vector re-index when indexed fields change.
- Invalidate `book:{id}`, `book:summary:{id}`, and affected `books:list` / `books:search` tags on every book mutation, and bump versioned cache key prefixes (`v1`) if cached DTO shapes change.
- Preserve `snake_case` naming for all [[container|catalog-database]] schema migrations and keep all Qdrant upserts idempotent by book UUID.
- Verify downstream gRPC compatibility with [[service|basket-api]], [[service|order-api]], and [[service|mcp-server]], and confirm Pact contract tests pass for all rating and scheduler events.

## Related Resources

- [[service|catalog-api]] — Authoritative catalog REST/gRPC API and rating projection consumer
- [[service|catalog-ingestion]] — Scheduled vector indexing worker
- [[flow|product-ingestion]] — End-to-end vector indexing and advisory-lock workflow
- [[adr|adr-001-postgresql-system-of-record]], [[adr|adr-002-hybrid-vector-search-qdrant]], [[adr|adr-003-database-queue-for-vector-indexing]], [[adr|adr-004-fusioncache-redis-for-catalog-reads]], [[adr|adr-006-reviews-rating-projection-on-book]]
- [[doc|platform/006-api-and-contracts]] — Consolidated HTTP, gRPC, and Kafka contracts
