---
title: "The generative recommender behind Shopify's commerce engine"
description: "Shopify built a foundational generative recommender on HSTU that treats buyer journeys as raw event sequences and trains an autoregressive, causally masked model to predict the next product."
url: "https://swe.quest/articles/the-generative-recommender-behind-shopify-s-commerce-engine-f5ed1bac0cf956d4"
canonical: "https://shopify.engineering/generative-recommendations"
source: "Shopify Engineering"
published: "2026-02-25"
difficulty: "hard"
kind: "Case study"
reading_minutes: 8
tags: ["recommendation-systems","model-training","machine-learning","ecommerce"]
---

# The generative recommender behind Shopify's commerce engine

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2026-02-25, 8 min read, Case study. Original: [https://shopify.engineering/generative-recommendations](https://shopify.engineering/generative-recommendations)

## Summary

Shopify built a foundational generative recommender on HSTU that treats buyer journeys as raw event sequences and trains an autoregressive, causally masked model to predict the next product. The quality gains came from three ideas. Timestamps are encoded directly in attention through RoPE-style rotary encoding plus relative time bias, including the current session time. Negative sampling is scaled with shared and positive-aware hard negatives under sampled softmax. A boosting-inspired objective rewards recall that the rest of the retrieval ensemble misses. Optimized CUDA kernels gave up to 7.3x training speedup, and online A/B tests showed +0.94% Shop orders, +5% high-quality CTR and +0.71% conversion. Next steps explore semantic IDs to replace huge product-ID embedding tables.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Recommendations & ranking](https://swe.quest/tags/recommendation-systems.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [E-commerce](https://swe.quest/tags/ecommerce.md) (Domains)

## Prerequisites

- transformer attention
- sequential recommendation
- sampled softmax and contrastive learning
- retrieval and ranking pipelines ([easy posts on Recommendations & ranking](https://swe.quest/tags/recommendation-systems.md?difficulty=easy))

## Keywords

Shopify, HSTU, RoPE, sampled softmax, CUDA, semantic IDs, Shop app

## Related posts

- [Shopify’s generative discovery model](https://swe.quest/articles/shopify-s-generative-discovery-model-99e5ac502d9a8c68.md): Shopify Engineering · 2026-11-11 · Hard · 12 min read · Recommendations & ranking, Search, LLMs, Inference & serving, Model training
  Shopify trained a single generative model, adapted from an open-weight LLM, that emits semantic-ID tokens to generate product candidates for both personalized search and recommendation across a catalog of billions.
- [GenRecs Tokenization: Transforming Ads Recommendation at Meta with Stable Model Vocabulary](https://swe.quest/articles/genrecs-tokenization-transforming-ads-recommendation-at-meta-with-stable-model-e3f3b6ea2626a2c2.md): Meta Engineering · 2026-10-19 · Hard · 6 min read · Recommendations & ranking, Ads, LLMs, Machine learning
  Meta's ads recommender replaces per-item IDs with GenRecs Tokenization, a stable semantic vocabulary.
- [From Scoring to Spelling: Rebuilding Ads Retrieval at Instacart](https://swe.quest/articles/from-scoring-to-spelling-rebuilding-ads-retrieval-at-instacart-1eba18ee15c15a7e.md): Instacart Tech · 2026-06-02 · Hard · 13 min read · Recommendations & ranking, Ads, Inference & serving, ML platforms
  Instacart replaced its BERT-based ads retrieval model, which scored every atomic product ID in a fixed vocabulary, with a generative model that autoregressively decodes Semantic IDs (RQ-VAE codeword sequences) via beam search.
- [Advancing Generative Recommendation Inference: our collaboration with NVIDIA on TensorRT LLM](https://swe.quest/articles/advancing-generative-recommendation-inference-our-collaboration-with-nvidia-on-edd2a66abab4a278.md): Spotify Engineering · 2026-10-16 · Hard · 7 min read · Inference & serving, Recommendations & ranking, LLMs, Cost optimization
  Spotify consolidated its LLM-based generative recommendation inference onto TensorRT LLM, working with NVIDIA to add the features it had been splitting across engines. vLLM handled beam search for semantic-ID candidate generation, but its beam search runs outside the core GPU engine and recomputes partially filled KV blocks.
- [Meta’s Generative Ads Model (GEM): The Central Brain Accelerating Ads Recommendation AI Innovation](https://swe.quest/articles/meta-s-generative-ads-model-gem-the-central-brain-accelerating-ads-5d5a24731a15c0eb.md): Meta Engineering · 2025-11-10 · Hard · 10 min read · Recommendations & ranking, Ads, Model training, ML platforms
  GEM is Meta's LLM-scale foundation model for ads recommendation, trained on thousands of GPUs and used as a teacher to improve hundreds of downstream vertical ranking models; it lifted ad conversions 5% on Instagram and 3% on Facebook Feed.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
