SR-028 — Recently Viewed Products: System Requirements
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 | SR-2026-PERS-001 |
| Author | Engineering Team |
| Status | Implemented (gaps noted inline) |
Traces back to BRD-027 — Recently Viewed Products.
This spec covers the full chain: product-catalog publishing a view event when a product’s full detail is loaded, user-preference-service persisting and serving that history, shop-service joining it with live catalog/pricing data for two call sites, and ui-application’s teaser widget and “see all” screen.
Functional Requirements
Capturing a View (product-catalog)
- FR-01 (View captured only on full-detail load): A recent-view event is published only from
ProductCrudService.GetFullDetail— the code path backing the mobile product-detail screen (ProductService.GetProductFullDetailgRPC).Get’s other callers (GetProductSummary,GetBatchProductSummaries) never trigger a view event, so a product merely appearing in a list or search result is not counted (BRD-027’s out-of-scope: tracking at anything less than a full-detail open). - FR-02 (Authenticated-only): The event is skipped entirely if
auth.GetUserID(ctx)is empty — an unauthenticated or service-to-service call never produces a recently-viewed entry, satisfying BRD-027’s BR-07. - FR-03 (Fire-and-forget publish): The event is published on a background goroutine over
context.WithoutCancel(ctx), so a publish failure is logged but never blocks or fails theGetProductFullDetailresponse itself. (Gap — no retry/outbox exists for a failed publish; see TD-00022.) - FR-04 (Envelope shape): The published payload carries
product_idanduser_idonly — nosku_id— over topicPUBSUB_TOPIC_RECENT_VIEW(defaultrecent-view-recorded), wrapped in the standardmessage.MessageEnvelopeheader (tenant_id,correlation_id,trace_parent).
Persisting the History (user-preference-service)
- FR-05 (Subscribe and record):
user-preference-servicesubscribes viaPUBSUB_SUBSCRIPTION_RECENT_VIEW(defaultrecent-view-recorded);tenant_idis auto-injected into context by the shared Pub/Sub receiver wrapper, whileuser_id— absent from the generic envelope header — is read from the payload and manually restored viaauth.SetUserIDToContextbefore the service call. - FR-06 (Move-to-front de-duplication): Recording a view that matches a product already in the shopper’s history removes the existing entry (
$pull) and re-appends it at the end of the stored (oldest-first) array, so the product moves to the most-recent position instead of appearing twice (BRD-027 BR-02). - FR-07 (Bounded history, oldest evicted): The stored array is capped at 50 entries (
$pushwith$each/$slice: -50), applied atomically in the same update that appends the new entry, so the oldest view silently drops off once the cap is reached (BRD-027 BR-03). - FR-08 (Per-shopper isolation): History is stored one document per
(tenant_id, user_id)— a shopper’s list is never visible to, or mixed with, another shopper’s (BRD-027 BR-07). - FR-09 (Recency-ordered, paginated read):
RecentViewService.GetRecentlyViewedProductIDs(offset, limit)reverses the stored oldest-first order to most-recent-first before windowing byoffset/limit, so a caller requesting a smalllimit(the teaser) and a caller paginating through more of the list (the “see all” page) are both served correctly by the same method. - FR-10 (gRPC-only, metadata-sourced identity): The read is exposed as a single gRPC RPC;
tenant_id/user_idare read from gRPC metadata, never from the request message, consistent with every other gRPC read in this service.
Presenting the History (shop-service + ui-application)
- FR-11 (Storefront teaser):
shop-service’sgetRecentViewcallsGetRecentlyViewedProductIDs(0, limit)(limit=10) as the driving, order-defining id list, hydrates title/image fromproduct-catalog, joins live pricing frominventory-servicebymongo_product_id, and returns the result asRecentViewSection— rendered byui-application’sRecentViewSectionwidget on the main storefront screen (BRD-027 BR-04). - FR-12 (Full browsable page): The same driving-id-list join pattern backs a second, offset/limit-aware call site —
RecentViewSearchStrategy, registered undersectionType: "recent_view"— poweringui-application’s dedicated “see all” screen (BRD-027 BR-05). - FR-13 (Order preserved end-to-end): In both call sites, the final product order is rebuilt by iterating
user-preference-service’s returned id list, never the unordered detail/pricing join response — the recency ordering established in FR-09 survives all the way to what the shopper sees. - FR-14 (Missing-counterpart products dropped, not placeholder-rendered): A product id present in the recently-viewed list but missing a
product-catalogdetail or aninventory-servicepricing counterpart (e.g. a product mid-migration, or since archived) is dropped from the rendered list with an info log — never rendered with a blank title or a zero price. - FR-15 (Tap-through returns to product detail): Each rendered item carries enough identity (
product_id) forui-applicationto navigate directly back into that product’s full-detail screen on tap, closing the loop BRD-027’s BR-06 describes — and, incidentally, the same screen whose load triggers FR-01’s capture again. - FR-16 (Config-gated visibility): Whether
RecentViewSectionactually renders on a given storefront screen is additionally gated bymobileappconfig’s per-screen active-section list — a correct data pipeline still renders nothing if that screen’s config has no active entry forrecent_view.
Non-Functional Requirements
- NFR-01 (No publish-side retry or dead-letter path): A publish failure in
product-catalogis logged and discarded — there is no outbox, retry queue, or dead-letter mechanism recovering a lost view event. (Gap — tracked as TD-00022.) - NFR-02 (Non-blocking capture): Capturing a view must never add latency to, or risk failing, the product-detail response it rides on — enforced structurally by the fire-and-forget goroutine pattern (FR-03), not by a timeout or circuit breaker.
- NFR-03 (Bounded storage per shopper): Because history is capped at 50 entries per shopper (FR-07), this feature’s storage footprint per shopper is bounded and does not grow unboundedly with browsing activity over time.
- NFR-04 (Tenant and user scoping on every write and read): Every write (via the Pub/Sub envelope and restored
user_id) and every read (via gRPC metadata) carriestenant_idanduser_id— never trusted from a request body — consistent with this monorepo’s global multi-tenancy rule. (Gap — no retention policy, and no account-deletion flow reaches this data yet; see TD-00022 TD-23.) - NFR-05 (Product-level granularity, by design): Tracking stops at the product level and deliberately omits
sku_id, avoiding an extra cross-service call fromproduct-catalogtoinventory-serviceat publish time purely to resolve a “primary SKU.” This is a recorded design decision, not a gap — see ADR-00042.
Related Documents
- BRD-027 — Recently Viewed Products
- ADR-00042 — Recently Viewed Products: Resilient Event-Stream Capture vs. a Synchronous Call From the UI
- Architecture — Recently Viewed Products: Component Topology and Data Flow
- Technical Debt — Recently Viewed Products Gaps
- Microservices: product-catalog, user-preference-service, shop-service