Storefront has been decoupled into micro-frontends with a dedicated commerce app and shared shell.

Read the architecture guide →

ADR-003: Maintain the vector index asynchronously through a database-backed queue

Database triggers enqueue changed books, and Catalog Ingestion drains the queue in batches to update Qdrant, decoupling writes from embedding generation.

October 20, 2026AcceptedIntegration

1. Context & Problem

Generating AI search embeddings is relatively slow and relies on external services. Performing embedding generation inside 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 while an administrator saves a product would add noticeable delay to every catalog edit—and worse, an outage in the embedding model or search store would cause product updates to fail.

In addition, a BookEntityv1.0.0BookCanonical sellable title in the product catalog, encapsulating descriptive metadata, pricing, stock availability, taxono...Ownercatalog-experience-teamOpen docs‘s searchable details do not change only when the book record itself is edited; they also change when an AuthorEntityv1.0.0AuthorRepresents a credited author of one or more books in the product catalog, enforcing display-name validity and referentia...Ownercatalog-experience-teamOpen docs, CategoryEntityv1.0.0CategorySingle-level taxonomy classification grouping books by subject or genre within the product catalog.Ownercatalog-experience-teamOpen docs, PublisherEntityv1.0.0PublisherRepresents a publishing house or imprint associated with books in the product catalog.Ownercatalog-experience-teamOpen docs, or book_authors link is updated. Relying on application code to remember every indirect path risks silent search drift. Catalog needed a durable handoff from committed database changes to the search projection without treating every intermediate edit as a separate event to replay.

2. Business Value

  • Fast, resilient catalog administration: Product saves complete immediately and remain available even when AI embedding or search services are slow or degraded.
  • No missed indirect updates: Database-level change capture automatically queues affected books whether an edit touches a book directly or updates an author, category, or publisher.
  • Lower cost on rapid edits: Multiple edits to the same book before processing starts are collapsed into one pending refresh of the latest state.
  • Protection against race conditions: Concurrent edits made while a search batch is already running are automatically preserved for the next cycle rather than being overwritten or discarded.

3. How It Works

  1. Capture pending work inside the save transaction: Whenever changes are saved to BookEntityv1.0.0BookCanonical sellable title in the product catalog, encapsulating descriptive metadata, pricing, stock availability, taxono...Ownercatalog-experience-teamOpen docss, AuthorEntityv1.0.0AuthorRepresents a credited author of one or more books in the product catalog, enforcing display-name validity and referentia...Ownercatalog-experience-teamOpen docss, CategoryEntityv1.0.0CategorySingle-level taxonomy classification grouping books by subject or genre within the product catalog.Ownercatalog-experience-teamOpen docss, PublisherEntityv1.0.0PublisherRepresents a publishing house or imprint associated with books in the product catalog.Ownercatalog-experience-teamOpen docss, or book_authors links 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, automatic database rules record each affected book in a pending-work table as part of the exact same save.
  2. Coalesce repeated edits: The queue keeps one pending entry per book. If a book changes multiple times before indexing runs, its existing waiting entry is updated with a fresh version marker so the worker reads only the latest product state rather than replaying every draft.
  3. Process bounded batches on a schedule: Every five minutes, Catalog IngestionServicev1.0.0Catalog IngestionInternal background worker that reads pending Catalog book updates and synchronizes semantic search vectors in Qdrant. SubscribesProcessVectorBatchIntegrationEventOwnercatalog-experience-teamDiagramRepositoryOpen docs claims an exclusive turn so only one batch runs at a time, reads up to 200 waiting books, prepares searchable text and embeddings, and updates or removes the corresponding entries in Catalog VectorContainerv1.0.0Catalog VectorNon-authoritative Qdrant vector search index owned by the Catalog bounded context for hybrid semantic and keyword book d...Ownercatalog-experience-teamDiagramOpen docs.
  4. Clear only matching versions: After every search update in the batch succeeds, the worker removes each waiting entry—but only if its version marker still matches what was read at the start of the batch. If a newer edit arrived mid-batch, that entry stays queued for the next scheduled run.

4. Trade-offs & Lessons Learned

Alternatives considered

  • Update the search index synchronously inside Catalog API: Keeps search fresher, but puts embedding latency directly on the user request path and turns a search outage into a catalog-write outage.
  • Use an external message broker for indexing: Offers strong decoupling and fan-out, but adds another infrastructure dependency and makes it harder to guarantee that a committed product save and its queued indexing message stay atomic.
  • Trigger indexing directly from application code: Straightforward for a single write endpoint, but too easy to forget across indirect updates to authors, categories, publishers, or book-author links.

Trade-offs & operational considerations

  • Eventual consistency without a strict freshness SLA: The five-minute cadence is an execution schedule, not a guarantee that search updates finish within five minutes. Large backlogs drain across multiple 200-item batches because only one batch runs at a time.
  • At-least-once retries instead of distributed transactions: Because the database and search store do not share an all-or-nothing transaction, failures can leave partial search updates; stable book identifiers make retrying on the next cycle safe.
  • Database load and monitoring: Trigger writes and batch reads add load to Catalog DatabaseContainerv1.0.0Catalog DatabaseAuthoritative PostgreSQL system of record owned by the Catalog bounded context for books, authors, categories, publisher...Ownercatalog-experience-teamDiagramOpen docs. Operations teams must monitor pending queue size, oldest pending age, ingestion outcomes, and search-store health.

5. Technical Reference