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

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
- A signed-in shopper opens a product’s full-detail screen in
ui-application, which callsshop-service’sgetProductFullDetail, which callsproduct-catalog’s gRPCProductService.GetProductFullDetail(SR-028 FR-01). ProductCrudService.GetFullDetailfetches the product viaGet, then callspublishRecentView(ctx, product.ID). Ifauth.GetUserID(ctx)is empty, this returns immediately — no event is produced for an unauthenticated or service call (SR-028 FR-02).publishRecentViewspawns a goroutine overcontext.WithoutCancel(ctx)and callsRecentViewEventPublisher.Publish, which buildsMessageEnvelope[RecentViewEventPayload]{Header: {TenantID, CorrelationID, TraceParent}, Data: {ProductID, UserID}}and publishes it toPUBSUB_TOPIC_RECENT_VIEW(defaultrecent-view-recorded). The originalGetFullDetailcall already returned to its caller before this completes — a publish failure is only logged (SR-028 FR-03/FR-04).user-preference-service’sRegisterRecentViewEventReceiver, subscribed viaPUBSUB_SUBSCRIPTION_RECENT_VIEW, receives the message. The shared Pub/Sub receiver wrapper auto-injectstenant_idinto context from the envelope header; the handler manually restoresuser_idfrom the payload viaauth.SetUserIDToContext, since the generic envelope header has no slot for it (SR-028 FR-05).- The handler calls
RecentViewService.RecordView(ctx, productID), which runs two sequential Mongo updates on the(tenant_id, user_id)-keyed document:$pullany existing entry for this product, then$pushwith$each/$slice: -50to 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). - When
shop-servicelater 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 callsRecentViewGRPCServer.GetRecentlyViewedProductIDs(offset, limit), withtenant_id/user_idread 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). shop-servicetreats the returned id list as the driving order: it hydrates title/image viaproduct-catalog’sGetProductDetailsByIDsand live price viainventory-service’s pricing join, keyed bymongo_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).ui-applicationrenders the joined result: theRecentViewSectionteaser 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 onmobileappconfig’s per-screen active-section list (SR-028 FR-16).- 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-catalogis 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.
Related Documents
- BRD-027 — Recently Viewed Products
- SR-028 — Recently Viewed Products: System Requirements
- ADR-00042 — Recently Viewed Products: Resilient Event-Stream Capture vs. a Synchronous Call From the UI
- Technical Debt — Recently Viewed Products Gaps
- Microservices: product-catalog, user-preference-service, shop-service