How Shopify improved consumer search intent with real-time ML

Jonathan Sabbagh, Danny McCormick18 Oct 2024

Problem

Storefront search that matches the intent of a query rather than its keywords alone needs text and image embeddings for every product. Merchants change products and upload images at any moment and expect the storefront to reflect it immediately. A batch job leaves the search index stale. A streaming pipeline with GPU inference fixes that, but it brings out-of-memory errors, GPUs fed batches of one and cost trade-offs.

Example from the article: Shopify runs about 2,500 embeddings per second (about 216 million per day) across its image and text pipelines on Google Cloud Dataflow, and tuned worker memory, model loading and batching to keep it affordable.

Solution in brief

Shopify builds embeddings as a shared ML asset from streaming pipelines. Each pipeline reads a change event, preprocesses it, runs the model on a GPU and writes the vector both to the warehouse and to an output topic that feeds search. Three tuning decisions keep it affordable: fewer threads per process to cut memory, the default model-per-process layout to keep throughput, and in-bundle batching to avoid a latency penalty.

Questions this case answers
  • How to run model inference over a bursty event stream so that the GPU stays saturated and worker memory stays within budget
  • How to keep a search index of embeddings continuously up to date when the underlying content changes at any moment
  • How to keep product text and image embeddings for semantic search fresh within seconds of a merchant edit?
  • How to stop a GPU embedding pipeline from running out of memory without paying for bigger machines?

Tools and methods

  • Text and image embeddings — vectors compared by similarity to match a query with products
  • Google Cloud Dataflow — streaming runner for the pipelines
  • Apache Beam (ModelHandler, RunInference, BatchElements) — inference and batching primitives
  • BigQuery — offline copy of embeddings for reports and dashboards
  • T4 GPU workers (n1-standard-16) — inference hardware
Continue reading — it's free

Google or a one-time email code. No password.