ADR-00042 — Recently Viewed Products: Resilient Event-Stream Capture vs. a Synchronous Call From the UI

By Engineering Team•October 10, 2026•5 min read
  • Status: Accepted
  • Date: 2026-10-10
  • Authors: Engineering Team

Context

BRD-027 requires that looking at a product automatically, invisibly builds a recently-viewed history with no shopper action and no added friction. SR-028 turns that into concrete capture and read behavior. The central design question is where the capture happens and how it reaches user-preference-service — this record captures why the implemented shape (an event published by product-catalog, consumed asynchronously) was chosen over the more obvious alternative of having the mobile app itself call user-preference-service directly when a product loads.

Decision Drivers (FRs & NFRs)

  • FR-01/FR-02 (capture only on full-detail load, authenticated-only).
  • FR-03/NFR-02 (fire-and-forget, non-blocking capture).
  • FR-05 (tenant/user context restoration on the consuming side).
  • NFR-01 (accepted: no publish-side retry today).
  • NFR-05 (product-level-only granularity).

Decision 1 — Capture mechanism: resilient Pub/Sub event stream vs. a synchronous UI-to-user-preference-service call

Option 1 — Synchronous call from ui-application directly to user-preference-service when a product loads

In this shape, the mobile app itself would call user-preference-service (a RecordView-style endpoint) at the same moment it loads a product’s full details — either as a second call alongside the product-detail request, or chained after it.

  • Pros:
    • Conceptually simple: one obvious call site, one obvious owner, no intermediate transport to reason about.
    • The write would be confirmed before the UI considers the view “recorded” — no ambiguity about whether it happened.
  • Cons (Why Rejected):
    • Couples a client-visible flow to a background bookkeeping concern. Loading a product’s details is on the shopper’s critical path; a second network call (or a chained one) made from the UI for a feature the shopper never directly asked for adds latency and a new failure mode to a screen that has nothing to do with “recently viewed” from the shopper’s point of view.
    • The mobile client becomes a direct, authenticated caller of a second backend service for every single product view, widening the client’s trusted surface area and its exposure to that service’s availability — if user-preference-service is slow or briefly unavailable, the product-detail screen either waits on it, silently swallows the failure in client code, or needs its own client-side retry logic for a concern that has nothing to do with rendering a product.
    • Every future producer of a “view” signal would need to re-implement the same client-side call. product-catalog’s GetFullDetail is already the single, authoritative place a “product was fully viewed” fact is known server-side — pushing capture to the client duplicates that knowledge into every client surface that can reach a product-detail screen, rather than keeping it in the one service that already decided a full view occurred.
    • No natural retry/backpressure story. A dropped mobile network connection right after the product-detail response but before the second call completes silently loses that view, with no server-side record that a view was even attempted — compared to a backend-originated event, which at least has a known, inspectable publish point even before any retry/outbox is added.

Option 2 — product-catalog publishes a fire-and-forget Pub/Sub event on full-detail load; user-preference-service consumes it asynchronously (CHOSEN)

  • Pros:
    • Decouples the shopper-facing response from the bookkeeping write entirely. publishRecentView runs on a background goroutine over context.WithoutCancel(ctx), so GetFullDetail’s response to the mobile app is never delayed or put at risk by anything downstream of the publish call — a user-preference-service outage has zero effect on the product-detail screen (NFR-02).
    • Single, authoritative capture point. Because product-catalog is already the service that knows a full-detail view just happened, publishing from there means every current and future client of GetProductFullDetail (today: shop-service on behalf of ui-application; potentially a future admin preview or a different client surface) gets view-tracking “for free,” without needing its own capture logic.
    • The mobile app and shop-service never need to know user-preference-service exists for this feature. Nothing about the storefront-facing call path changed to add this capability — it was added purely on the publish side plus a new consumer, with no new client-visible endpoint.
    • Natural fit for the data’s own shape. A view event is a discrete, timestamped fact about something that already happened — exactly the shape an event stream is built for — rather than a request expecting a synchronous response the caller needs to act on.
  • Accepted Trade-offs:
    • Eventual, not immediate, consistency. There is a small window between a product view and that view being queryable in user-preference-service — acceptable because nothing in this feature’s UI reads back its own just-recorded write; the teaser and “see all” page are read on a subsequent, unrelated request.
    • No retry or dead-letter path today if the publish itself fails (e.g. product-catalog can’t reach Pub/Sub at that moment) — the view is simply lost, logged but not recovered. Accepted for now as a low-stakes loss (a missed “recently viewed” entry is not a missed order or a missed payment) — tracked as TD-00022 rather than solved speculatively ahead of real-world signal on how often it actually happens.

Decision 2 — Tracking granularity: product-level vs. SKU-level

Option 1 — Track the specific SKU/variant viewed

  • Cons (Why Rejected):
    • product-catalog’s GetFullDetail has no SKU-level concept of “the variant the shopper is currently looking at” in its own domain — SKU/variant data lives in inventory-service. Resolving a “primary” or “currently selected” SKU at publish time would require a new cross-service call from product-catalog into inventory-service on every single product view, purely to enrich an event that doesn’t otherwise need it.

Option 2 — Track at the product level only, no sku_id (CHOSEN)

  • Pros:
    • Keeps the publish path inside product-catalog’s own domain — no new cross-service dependency added just for this feature.
    • Matches how a shopper actually thinks about “I looked at this earlier” — as a product, not a specific color/size combination — and matches BRD-027’s explicit scope (tracking interest at the product level only).
  • Accepted Trade-offs:
    • If a future requirement needs variant-level recall (e.g. “you looked at this in blue”), this decision would need to be revisited — not a concern BRD-027 raises today.

Final Decision

A fire-and-forget Pub/Sub event published by product-catalog on every full-detail product view, consumed asynchronously by user-preference-service (Decision 1, Option 2), tracked at the product level only (Decision 2, Option 2).