How product recommendations work

How BlueShop chooses, filters and measures product recommendations.

About this guide

Prepared with AI under human direction. Implementation details were checked against source code and test scenarios where noted. Read the earlier implementation plan or its Markdown version.

Source check: 12 September 2026. Eligibility, serving checks, product/variant response fields, strategy chains, order-fact identity and measurement were checked against backend commit d305706a. This is a source check, not a new deployment or runtime test. The films are July recordings and may describe older behavior. See the pinned source links below.

1. What it does

BlueShop has a dedicated recommendation-service bounded context. It serves explainable product recommendations at four storefront placements:

Placement Customer experience Context sent to Recommendation
HOME Popular or personalized discovery Recently viewed products and, when authenticated, server-side purchase history
CART Complementary products before checkout Current cart product IDs
ORDER_CONFIRMATION Relevant next products after purchase Product IDs preserved from the completed cart
PDP_SIMILAR Semantically similar products The current product ID

The system combines five strategies:

Serving checks every candidate after cache lookup against Catalog, Stock and Recommendation's local eligibility projection. The local row must exist, be published, identify a default variant, have positive availableToSell, and report IN_STOCK or LOW_STOCK. Missing rows and UNKNOWN availability are rejected. Catalog must also return a published product, and Stock must return positive availability for the candidate variant with a status other than OUT_OF_STOCK. These checks do not reserve stock; checkout still owns reservation.

2. Three Ways To Choose Products

BlueShop does not use one universal recommendation score. It combines three decision layers with different scopes, inputs, and meanings:

Layer Question answered Current inputs Current strategies
Global What is broadly relevant now? Decayed order demand, category and featured-product facts POPULARITY
Product-to-product What belongs with or resembles this product set? Co-purchase pairs, curated relations, multilingual embeddings CO_PURCHASE, CURATED_RELATION, SIMILAR_CONTENT
Customer-to-product What is relevant to this specific customer? Purchase history and Catalog-persisted recently viewed products Interleaved PERSONAL_HISTORY and view-seeded SIMILAR_CONTENT on authenticated HOME
Recommendation architecture diagram 1

Global layer

The global layer is customer-independent. It provides a baseline for anonymous traffic, cold starts, and fallback capacity. Popularity is derived from order facts with time decay rather than from page-view volume.

Product-to-product layer

This layer starts from one or more seed products. It can express observed co-purchase behavior, explicit catalog-manager intent, or semantic similarity. It powers cart, order-confirmation, and PDP contexts and also contributes to HOME personalization.

Customer-to-product layer

This layer combines long-term and short-term customer context:

Personalization does not put customer identity into measurement events. Recommendation uses the authenticated UUID only for serving, while served/clicked CloudEvents remain anonymous and no-PII.

3. System Context And Ownership

Recommendation architecture diagram 2

Ownership boundaries

Boundary Owns Recommendation keeps only
Catalog Products, lifecycle, categories, curated cross-sell/upsell relations Publication/category snapshots, relation projections, embedding source facts
Stock Authoritative availability and reservations Asynchronous availability projection and source freshness
Order Order lifecycle and commercial snapshots Order-product facts and customer purchase profile
Recommendation Candidate generation, ranking, serving policy, measurement Affinity, popularity, eligibility, relations, embeddings, inbox/outbox
Analytics Analytical facts and dashboards Item-grain served/clicked projections and CTR views

Catalog and Stock remain the authorities for publication and availability. Recommendation uses local projections to find candidates, then checks Catalog, Stock and the local eligibility policy before returning them. A missing or incomplete local row is rejected, even if another lookup succeeds.

4. Public And Internal Contracts

The gateway exposes the service under /api/recommendation.

Operation Access Purpose
GET /v1/recommendations Public; optional JWT Serve one placement using up to 20 seed product IDs and at most 12 product/variant results
POST /v1/recommendations/clicks Public Accept a client-reported click beacon; request shape is validated, but membership in the served set is not
POST /internal/v1/recommendations/recompute admin role Refresh known catalog snapshots, embeddings, and derived projections

A recommendation response carries:

The API returns product and variant IDs rather than duplicating Catalog DTOs. The storefront preserves recommendation order and hydrates cards through Catalog's bulk endpoint.

5. Event Ingestion And Derived Data

Recommendation architecture diagram 3

Two views of a purchase

Model Grain Question it answers
order_product_facts One order and one variant What happened in this exact transaction?
customer_product_purchases One customer and one product What is this customer's accumulated purchase relationship with the product?

Delivery semantics

Data schema evolution

The first eight Flyway migrations introduced:

  1. Baseline schema and service RLS.
  2. Order-product facts and purchase profile.
  3. Eligibility and curated relations.
  4. Affinity and popularity scores.
  5. Transactional inbox.
  6. Separate catalog and availability freshness clocks.
  7. vector(384) product embeddings and HNSW index.
  8. Recommendation measurement outbox.

Later migrations add order/variant identity, variant stock eligibility and default-variant serving; remove the unused order-fact price; and maintain database roles, RLS and outbox trace context. The checked migration directory reaches V20, with V13 intentionally retired. Recommendation stores behavioral purchase facts; Order and Analytics retain commercial amounts.

The vector PostgreSQL extension is installed by GitOps with elevated platform privileges; application Flyway only owns service schema objects.

6. Actual Serving Strategy

The historical plan contains several candidate chains considered during design. The implementation described here uses these chains:

Context Actual ordered strategy chain
Anonymous HOME POPULARITY
Authenticated HOME, no purchases SIMILAR_CONTENT -> CURATED_RELATION -> POPULARITY
Authenticated HOME, with purchases Interleaved PERSONAL_HISTORY + SIMILAR_CONTENT -> CURATED_RELATION -> POPULARITY
CART CO_PURCHASE -> CURATED_RELATION -> POPULARITY
ORDER_CONFIRMATION CO_PURCHASE -> CURATED_RELATION -> POPULARITY
PDP_SIMILAR SIMILAR_CONTENT
Recommendation architecture diagram 4

Ranking details

If Catalog omits a product or reports it unpublished, the service invalidates the candidate cache and deletes that product from the local eligibility projection. If the result is short, it refreshes candidates and retries the serving checks once. A Catalog or Stock lookup error or timeout returns an empty recommendation set. Positive availability is a serving-time observation, not a checkout reservation.

Personal history

PERSONAL_HISTORY is a fallback sequence, not a weighted blend:

  1. Co-purchase neighbours of recent purchases.
  2. Customer-category popularity if no affinity result exists.
  3. Semantic neighbours of the purchase seeds if the first two lanes are empty.

7. Curated Recommendation Flow

Recommendation architecture diagram 5

Catalog owns curated relations. Recommendation preserves their order while applying the same serving checks as other strategies: published Catalog product, positive Stock availability for the candidate variant, and a complete, sellable local eligibility row. Curation does not bypass those checks.

8. Semantic Recommendation Flow

Recommendation architecture diagram 6

Runtime model

Semantic text prioritizes structured product tags when present. Otherwise it combines localized name, description, short description, SKU, brand, and localized attribute values.

Semantic cold start does not require order history. A newly published product can receive an embedding from its Catalog event and immediately participate in PDP_SIMILAR once its snapshot and availability are current.

9. Storefront Integration

Recommendation architecture diagram 7

The Angular implementation follows BlueShop's frontend boundary rules:

10. Measurement And BI

Recommendation architecture diagram 8

Measurement contract

RecommendationServed records the anonymous set ID, placement, anonymous/authenticated request context, seed product IDs, ranked product/variant items, environment, traffic class, and generation time.

RecommendationClicked records the set ID, placement, product, variant, one-based rank, strategy, environment, traffic class, and click time. The public request supplies the set ID, placement, product, variant, rank, and strategy; the public traffic-class header is also caller-controlled and defaults to LIVE when absent or malformed. The service owns only environment and receipt time.

Neither event includes customer identity, contact data, address data, cost, or margin. The click endpoint validates field shape and enum parsing, but does not look up the served set or verify that the product, variant, rank, placement, or strategy belonged to it. A conforming caller can therefore forge a tuple that ClickHouse later joins to a served tuple. These events are useful client instrumentation, not trustworthy proof of a human choice, causal impact, or customer identity.

Analytical model

A served-measurement persistence error is logged but does not fail the recommendation response. Click persistence is an explicit accepted request path, but its values remain client-reported.

11. Security, Privacy And Operations

Security

Operational cadence

12. Try It And Read The Code

Applications And References

Recommendation Films

These five films include on-screen captions and can be watched without audio:

PERSONALIZATION LOOP / 42.12S

Checkout to personalized recommendations

Follow a customer through address entry and checkout, then see recommendations that exclude the purchase. Back on HOME, suggestions combine purchase history and recent browsing.

PURCHASE PROFILE / 47.92S

One order becomes personalization

The film shows a test order, a later product view and the resulting HOME recommendations. The linked browser test checks one PERSONAL_HISTORY result, one SIMILAR_CONTENT result, and exclusion of both starting products.

PRODUCT PERFORMANCE / 42.60S

Which recommendations received clicks?

Compare impressions, client-reported clicks, CTR and average rank by product, placement and strategy, then inspect one recorded click. Click reports are not checked against the served recommendation set.

CLASSIC BUSINESS LOOP / 73.36S

Recommendation: the complete business loop

Shows a catalog manager curating two related products, a stock adjustment projecting known OUT_OF_STOCK state and removing that candidate, and a customer following the eligible recommendation to its product page. The film follows the change from the catalog manager to the storefront.

SEMANTIC COLD START / 88.12S

A new product finds its place

The film shows a newly eligible product receiving a "Similar products" strip. SIMILAR_CONTENT strategy, its explanation, and operation without purchase history are source- and BDD-backed behavior, not claims established by the film itself.

Source Code And Tests

Concern Source
HTTP boundary RecommendationController.java
Product/variant responseRecommendationItemResponse.java
Strategy chains FallbackChain.java
Candidate engine HeuristicRecommendationEngine.java
Serving-rule orchestration DefaultRecommendationApplicationService.java
Order facts and customer purchase profile R2dbcOrderFactRepository.java
Eligibility behavior EligibilityPolicy.java
Semantic inference OnnxProductTextEmbedder.java
Semantic SQL R2dbcSemanticSimilarityRepository.java
Measurement RecommendationMeasurementService.java
Public click request RecommendationClickRequest.java
Analytics projection RecommendationMeasurementProjectionService.java
Product-level BI view V023__recommendation_product_performance.sql
Storefront state recommendations.store.ts
Permanent browser journeys storefront-recommendations.spec.ts
Recommendation BDD recommendation-rules.feature
Order/variant fact identityV10__require_variant_order_fact_identity.sql
Commercial measure removalV14__remove_order_fact_commercial_measures.sql
Traceable specification recommendation.spec.yaml

13. Delivered Versus Deferred

Capability State Notes
Dedicated recommendation bounded context Delivered Reactive Spring Boot service with service-owned schema and policies
HOME, CART, order confirmation and PDP placements Delivered One reusable storefront component and Signal Store
Co-purchase, popularity and purchase-history strategies Delivered Deterministic, explainable derived projections
Customer-level purchase and recently-viewed blending Delivered Authenticated HOME alternates long-term purchase history with short-term semantic browsing intent
Catalog-manager curated relations Delivered Catalog-owned source, Recommendation-owned serving projection
Semantic recommendations Delivered Local multilingual ONNX inference plus pgvector
Publication And Variant Availability Checks Delivered with limit Every request checks Catalog, Stock and the local eligibility policy; missing or UNKNOWN local eligibility rejects the candidate
Missing Or Lagging Eligibility Availability And Freshness Limit Missing or incomplete local data removes candidates. Projection lag or lookup failures can reduce or empty results; serving does not reserve stock
Served/client-reported click measurement and product-level Recommendation BI Delivered with trust limit No-PII pipeline is useful for instrumentation; click tuples are not verified against served sets
Gorse learned engine and A/B routing Deferred by design Current client-reported click data is not a trustworthy learned-engine gate
Elasticsearch More-Like-This adapter Not built pgvector shipped directly
Semantic fallback in CART Not implemented Actual chain is co-purchase, curated, popularity
Non-semantic fallback on PDP Not implemented Actual PDP chain is semantic-only; thin results hide the strip
Weighted blending across all strategies Not implemented Current engine uses ordered priority fill; only the two customer-level HOME signals are deterministically alternated
Infinite event replay as disaster recovery Not claimed Full historical recovery requires PostgreSQL backup plus retained Kafka replay

14. Result

Recommendation combines these parts:

The learned engine remains deferred. The current click stream cannot gate a learned engine because callers control the click tuple and traffic class. Such a gate requires server-side served-set validation, abuse controls, and experiment-quality evidence first.