Problem
Ozon's matching team computes image and text embeddings for every new or changed product, hundreds of thousands per day. The first ETL was a daily batch PySpark job per date partition. Most of its time and memory went into neural-network inference on images and text, and the rest of the pipeline waited for it. Runtime and memory grew with the catalogue. The team capped the job so that at most one third of updated products went through, and the queue of unprocessed products kept growing.
Example from the article: during promotions and seasonal sales, prices change and many new products appear, so the batch application needed significantly more memory.
Solution in brief
Product updates go into a Kafka topic. A Spark Structured Streaming job runs continuously, applies the models through Pandas UDFs and writes embeddings to HDFS; a daily job folds them into the ETL tables. A cap on messages per batch bounds memory, and minPartitions equal to the executor count lets added executors help. A custom daemon module loads each model once per executor.
Questions this case answers
- How to run continuous ML model inference over a stream of changed records so that memory stays bounded and throughput scales with the number of workers
- How to avoid reloading a heavy model for every micro-batch in distributed Python workers
- How to compute image and text embeddings for hundreds of thousands of new and changed products per day without a daily batch job that outgrows its memory?
- How to run ML model inference continuously on a Kafka stream with PySpark Structured Streaming?
Tools and methods
- Apache Spark (Structured Streaming, PySpark 3.x) — continuous micro-batch processing with Spark SQL
- Apache Kafka — the stream of product-change events
- Pandas UDF — runs model inference inside Spark in batches
- Apache Hadoop (HDFS) and Apache Hive — data source and storage of streaming output
- BERT, ResNet50, fastText, NFNet — text and image embedding models
Google or a one-time email code. No password.
