ADR-006: Keep only a derived rating summary on Catalog books
Reviews owns individual feedback; Catalog stores just an average rating and review count per book, updated from feedback integration messages.
1. Context & Problem
Storefront product listings need to display each BookEntityv1.0.0BookCanonical sellable title in the product catalog, encapsulating descriptive metadata, pricing, stock availability, taxono...Ownercatalog-experience-teamOpen docs‘s customer rating and let shoppers sort or filter results by rating. Querying the ReviewsDomainv1.0.0ReviewsCaptures individual customer feedback for books, publishes rating changes for Catalog discovery, and provides privacy-sc...Ownercatalog-experience-teamDiagramOpen docs domain for every book on every listing page would tightly couple catalog browsing to Reviews availability and add runtime overhead.
On the other hand, copying full FeedbackEntityv1.0.0FeedbackRepresents an individual customer's rating and optional written review for a Catalog book.Ownercatalog-experience-teamOpen docs records into the Catalog domain would blur domain ownership and duplicate review content, moderation rules, and lifecycle logic. Catalog needs a local rating summary to support product discovery without taking ownership of individual customer reviews.
2. Business Value
- Fast, resilient product discovery: Catalog listings display, sort, and filter by book ratings locally without making a live call to the Reviews domain on every read.
- Clean domain boundaries: The Reviews domain remains the single authority for customer feedback, moderation, and customer-specific rules, while Catalog focuses on product information and discovery.
- Auditable recovery: Because Catalog’s rating values are strictly derived from Reviews notifications, any drift or failed update can be reconciled directly from authoritative Reviews records.
3. How It Works
The ReviewsDomainv1.0.0ReviewsCaptures individual customer feedback for books, publishes rating changes for Catalog discovery, and provides privacy-sc...Ownercatalog-experience-teamDiagramOpen docs domain remains the sole owner of individual customer FeedbackEntityv1.0.0FeedbackRepresents an individual customer's rating and optional written review for a Catalog book.Ownercatalog-experience-teamOpen docs. Rather than storing review text or individual ratings, Catalog keeps only two derived summary figures—an average rating and a total review count—alongside each BookEntityv1.0.0BookCanonical sellable title in the product catalog, encapsulating descriptive metadata, pricing, stock availability, taxono...Ownercatalog-experience-teamOpen docs in Catalog DatabaseContainerv1.0.0Catalog DatabaseAuthoritative PostgreSQL system of record owned by the Catalog bounded context for books, authors, categories, publisher...Ownercatalog-experience-teamDiagramOpen docs.
When feedback is created or removed in Reviews, Reviews sends an asynchronous notification to Catalog APIServicev1.0.0Catalog APIInternal HTTP and gRPC service for Catalog product management, hybrid discovery, and authoritative book metadata. PublishesBookUpdatedRatingFailedIntegrationEventSubscribesCreatePublisher, UpdatePublisher +24APIsOpenAPI, AsyncAPIOwnercatalog-experience-teamDiagramRepositoryOpen docs identifying both the book and the feedback entry. Catalog API adds the rating when feedback is created and removes it when feedback is deleted. Business users creating or updating book records cannot manually edit these summary figures.
If a newly created feedback notification arrives for a book that does not exist in Catalog, Catalog API publishes a failure notification referencing the feedback so the discrepancy can be handled. If a deletion notification arrives for an unknown book, Catalog safely takes no action because there is no local summary to adjust.
Alternatives considered
- Copy full feedback records into Catalog: Keeping full reviews locally would answer feedback queries inside Catalog, but it would create ownership conflicts and risk inconsistent moderation or deletion behavior across domains.
- Have storefronts read Reviews directly: Letting customer experiences fetch ratings straight from Reviews for every listing would create a runtime dependency on Reviews availability for basic catalog browsing.
- Store the rating summary in an unlinked summary table: Separating the summary from the book record would require extra lookups or joins for data that appears on nearly every product listing.
4. Trade-offs & Lessons Learned
- Eventual consistency: Because rating summaries are updated through asynchronous messages, a book’s displayed rating and review count can briefly lag behind newly submitted or deleted feedback.
- Reconciliation over manual fixes: When message delivery or handling fails and leaves a book’s summary stale, operators must inspect message delivery and handler logs, then replay failed messages or recalculate summaries from Reviews through an approved recovery process—never invent rating values by editing the book record directly.
- Independent from search indexing: Rating summaries live in the relational catalog database for browsing and sorting, not inside the semantic search index; search-index membership and rating freshness are managed as separate concerns.
- Explicit missing-book handling: Catalog explicitly surfaces missing-book errors when new feedback cannot be applied, while treating deletions for unknown books as harmless no-ops.
5. Technical Reference
-
Related decision: ADR-001: Use PostgreSQL as the Catalog system of recordDecision Recordv1.0.0ADR-001: Use PostgreSQL as the Catalog system of recordCatalog Database (PostgreSQL) is the single authoritative store for books, authors, categories, and publishers; cache an...Ownercatalog-experience-teamOpen docs
-
Stored projection columns:
average_ratingandtotal_reviewson the book record in PostgreSQL (read-only projection; must not be exposed as writable fields on business-user book create/update operations). Excluded from Qdrant search records. -
Integration event handling:
- Feedback createdEventv1.0.0Feedback createdIndicates that a customer feedback rating was created for a book. Rating API
publishes this event so Catalog can update ...Ownercatalog-experience-teamSchemaDiagramOpen docs: Identifies both book and feedback; adds the feedback rating to
average_ratingand incrementstotal_reviews. If the target book does not exist,catalog-apipublishes Book rating update failedEventv1.0.0Book rating update failedIndicates that Catalog could not apply a feedback-created event because the referenced book was not found. Ownercatalog-experience-teamSchemaDiagramOpen docs using the feedback ID. - Feedback deletedEventv1.0.0Feedback deletedIndicates that a customer feedback rating was deleted for a book. Rating API publishes this event so Catalog can remove ...Ownercatalog-experience-teamSchemaDiagramOpen docs: Identifies both book and feedback; removes the rating from the book’s projection. If the target book does not exist, the handler performs a no-op.
- Feedback createdEventv1.0.0Feedback createdIndicates that a customer feedback rating was created for a book. Rating API
publishes this event so Catalog can update ...Ownercatalog-experience-teamSchemaDiagramOpen docs: Identifies both book and feedback; adds the feedback rating to