Recently Viewed Products: Component Topology and Data Flow

By Engineering Team•October 10, 2026•6 min read
Metadata Details
System Name Recently Viewed Products — product-catalog → user-preference-service → shop-service → ui-application
Document ID ARCH-2026-PERS-001
Author Engineering Team
Status Implemented (gaps noted inline)

Realizes SR-028’s requirements under the decision recorded in ADR-00042.

Diagram

Recently Viewed Products — component topology and data flow from product-catalog's Pub/Sub publish on full-detail load, through user-preference-service's capped history, to shop-service's join and ui-application's teaser and full browsable page

Components

Component Responsibility
ui-application’s product full-detail screen Triggers the capture side as a byproduct of its own, unrelated load — never calls any recent-view endpoint itself.
product-catalog’s ProductCrudService.GetFullDetail The sole trigger point for a view event; skips publishing entirely for an unauthenticated caller.
product-catalog’s RecentViewEventPublisher (message_publisher/recent_view_event_publisher.go) Builds the MessageEnvelope/payload and publishes it fire-and-forget, on a background goroutine detached from the request’s cancellation.
Pub/Sub topic recent-view-recorded Decouples the publish side from the consume side — product-catalog and user-preference-service never call each other directly for this feature.
user-preference-service’s RegisterRecentViewEventReceiver Subscribes to the topic, restores user_id into context (tenant is auto-injected by the shared envelope wrapper), and invokes RecentViewService.RecordView.
user-preference-service’s recent_views Mongo collection One document per (tenant_id, user_id); stores up to 50 product ids, oldest-first, de-duplicated by move-to-front on re-view.
user-preference-service’s RecentViewGRPCServer Exposes GetRecentlyViewedProductIDs(offset, limit), reversing stored order to most-recent-first before windowing.
shop-service’s getRecentView / RecentViewSearchStrategy Calls the gRPC read as the driving, order-defining id list; hydrates title/image from product-catalog and live pricing from inventory-service, dropping any id missing a counterpart on either side.
ui-application’s RecentViewSection widget Renders the storefront teaser (limit=10); tapping an item navigates back to that product’s full-detail screen.
ui-application’s “see all” recent-view screen Reuses the generic SearchScreenController with sectionType: 'recent_view' for a paginated, full browsable list.

End-to-end flow

  1. A signed-in shopper opens a product’s full-detail screen in ui-application, which calls shop-service’s getProductFullDetail, which calls product-catalog’s gRPC ProductService.GetProductFullDetail (SR-028 FR-01).
  2. ProductCrudService.GetFullDetail fetches the product via Get, then calls publishRecentView(ctx, product.ID). If auth.GetUserID(ctx) is empty, this returns immediately — no event is produced for an unauthenticated or service call (SR-028 FR-02).
  3. publishRecentView spawns a goroutine over context.WithoutCancel(ctx) and calls RecentViewEventPublisher.Publish, which builds MessageEnvelope[RecentViewEventPayload]{Header: {TenantID, CorrelationID, TraceParent}, Data: {ProductID, UserID}} and publishes it to PUBSUB_TOPIC_RECENT_VIEW (default recent-view-recorded). The original GetFullDetail call already returned to its caller before this completes — a publish failure is only logged (SR-028 FR-03/FR-04).
  4. user-preference-service’s RegisterRecentViewEventReceiver, subscribed via PUBSUB_SUBSCRIPTION_RECENT_VIEW, receives the message. The shared Pub/Sub receiver wrapper auto-injects tenant_id into context from the envelope header; the handler manually restores user_id from the payload via auth.SetUserIDToContext, since the generic envelope header has no slot for it (SR-028 FR-05).
  5. The handler calls RecentViewService.RecordView(ctx, productID), which runs two sequential Mongo updates on the (tenant_id, user_id)-keyed document: $pull any existing entry for this product, then $push with $each/$slice: -50 to append it at the end and cap history at 50 entries in the same atomic step — moving a re-viewed product to the front and silently evicting the oldest entry once the cap is reached (SR-028 FR-06/FR-07).
  6. When shop-service later needs the shopper’s recently viewed products — either for the storefront teaser (getRecentView, limit=10) or for the “see all” page (RecentViewSearchStrategy, offset/limit-aware) — it calls RecentViewGRPCServer.GetRecentlyViewedProductIDs(offset, limit), with tenant_id/user_id read from gRPC metadata. The service reverses the stored oldest-first array to most-recent-first and windows it before returning (SR-028 FR-09/FR-10).
  7. shop-service treats the returned id list as the driving order: it hydrates title/image via product-catalog’s GetProductDetailsByIDs and live price via inventory-service’s pricing join, keyed by mongo_product_id. Any id missing a detail or pricing counterpart is dropped with an info log rather than rendered with a placeholder (SR-028 FR-13/FR-14).
  8. ui-application renders the joined result: the RecentViewSection teaser on the main storefront screen, and the dedicated “see all” screen for the paginated view. Whether the teaser actually renders on a given screen additionally depends on mobileappconfig’s per-screen active-section list (SR-028 FR-16).
  9. Tapping any product in either view navigates back into that product’s full-detail screen (SR-028 FR-15) — which, on load, repeats step 1, closing the loop BRD-027 describes.

Why this is simple, and what it does not yet guarantee

Capture and read are fully decoupled: product-catalog never knows whether user-preference-service is healthy, and user-preference-service never knows (or needs to know) which client surface eventually reads the history back. This keeps the shopper-facing product-detail response immune to this feature’s own failure modes, per ADR-00042. It does not yet guarantee:

  • Delivery of every view event. A publish failure inside product-catalog is logged and discarded, with no outbox or retry recovering it — see TD-00022.
  • Immediate read-after-write consistency. There is a small, accepted window between a view and that view being queryable — never observed by this feature’s own UI, since nothing here reads back its own just-recorded write on the same screen.
  • Variant-level recall. Tracking stops at the product level by design (ADR-00042, Decision 2) — a future “you looked at this in blue” requirement would need a new decision, not an extension of this one.