Skip to content
Case Study · Retail & E-commerce

Next Item Recommender Using BERT4Rec

Replacing collaborative filtering with a bidirectional Transformer sequence model for a 10M-user e-commerce catalogue — and serving it under 70ms in production.

Services
ML Model Design, Training, Deployment
Client
Confidential — enterprise e-commerce
Date
End 2024 – Early 2025
Scale
10M users · 2M products
Next Item Recommender Using BERT4Rec
+25%
Hit Rate@10 over the collaborative-filtering baseline
+18%
NDCG@10 over the collaborative-filtering baseline
+15%
Uplift in live conversion rate
<70ms
Real-time API latency per recommendation request
The Brief

Predicting the Next Purchase, Not Just Similar Products

A large e-commerce client operating across fashion, electronics, and lifestyle wanted better accuracy and relevance from their recommendation engine. They had been running standard collaborative filtering, which hit a wall on three fronts: scalability, cold start, and an inability to read sequential patterns in user behaviour.

The objective was a next-item recommendation system that predicts the most probable next purchase. We modelled the problem sequentially and built on BERT4Rec — a Transformer-based sequential recommendation architecture that treats a user's interaction history the way BERT treats a sentence.

Why sequential over collaborative filtering: collaborative filtering answers "what do similar people buy?" Sequence models answer "given what this person just did, what comes next?" — which is the question that actually converts in a multi-category session.
On this page
Stack
BERT4Rec PyTorch ONNX TensorRT Kubernetes FEAST NVIDIA A100 Prometheus Grafana
Challenges

Four Problems Standing in the Way

01

Data Sparsity & Sequence Noise

Behaviour data was sparse across long-tail products
Many users had very short interaction histories
Browsing noise that does not reflect purchase intent
Normalizing for sequence quality was non-trivial
02

Scalability

Over 10 million users and 2 million products
Traditional recommenders struggled at this scale
Sequential dependencies compound the compute cost
03

Cold Start & Long Tail

New products and users entered continuously
Collaborative filtering broke down on both
BERT4Rec needed fine-tuning to predict from few interactions
04

Latency Requirements

Recommendations required in real time, under 100ms
Serving a deep Transformer at that budget is a systems problem
Careful inference and caching design was mandatory
Approach

Model Training Setup

Interaction logs in, masked-item prediction out — four stages from raw event stream to a converged model in roughly 20 hours of distributed training.

Data Pipeline

User-item interaction logs: views, add-to-carts, purchases
Events chronologically ordered and tokenized like words in NLP
Each item represented as a unique token
Contextual embeddings for time of day, device type, user segment

Model Architecture

BERT4Rec — bidirectional Transformer encoder from BERT
A user's interaction sequence is treated as a sentence
Trained to predict masked items, like masked language modelling
Max sequence length set from typical session-length analysis

Training Strategy

Masked item prediction over randomly masked positions
Negative sampling: multiple negatives per positive interaction
Warm-up with cosine-annealing learning-rate schedule
Distributed multi-GPU training on A100s with mixed precision

Evaluation Protocol

Hit Rate@K on held-out next items
NDCG@K for ranking quality
Mean Reciprocal Rank for first-relevant-hit position
Baseline comparison against the incumbent CF model
Model configuration
Hidden size
256
Transformer layers
4
Attention heads
8
Max sequence length
50
Training hardware
Multi-GPU A100
Time to convergence
~20 hrs
Evaluation

Measured Against the Collaborative-Filtering Baseline

Offline evaluation ran on held-out sequences using the three standard ranking metrics — Hit Rate@K, NDCG@K, and Mean Reciprocal Rank — before anything reached live traffic.

Hit Rate@K — did the true next item appear in the top K?
NDCG@K — how highly was it ranked within them?
Mean Reciprocal Rank — position of the first relevant hit
Same traffic window and held-out split as the baseline model
Offline lift over baseline
Hit Rate@10 +25%
NDCG@10 +18%
Live conversion rate +15%
Bounce rate −12%
Baseline: production collaborative-filtering model, same traffic window, same held-out sequences.
Production

Model Deployment Setup

A deep sequence model at sub-100ms is a systems problem before it's a modelling problem. Here's the serving path a request actually takes.

01

ONNX Export

Trained model exported to ONNX for optimized, framework-independent inference.

02

TensorRT Serving

GPU-based serving compiled through TensorRT for low-latency execution.

03

Kubernetes

Hosted on a K8s cluster with horizontal scaling driven by traffic load.

04

FEAST Feature Store

Latest user sequence pulled at inference time from the feature store.

05

Real-Time API

REST endpoint under 70ms per request, with a caching layer for frequent queries.

Reliability & fallback

Caching layer in front of frequent query patterns
Fallback to default recommendations on system failure
Horizontal autoscaling tied to live traffic load

Monitoring & retraining

Prometheus + Grafana for real-time performance tracking
Weekly retraining to absorb new products and trends
Automated alerts on model drift and performance degradation
Impact

What It Moved for the Business

Higher Conversion Rates

Personalized, context-aware recommendations drove a +15% uplift in conversion — strongest in multi-category sessions.

Reduced Bounce Rates

More engaging recommendations lengthened sessions and cut bounce rate by roughly 12%.

Better User Experience

Real-time accuracy plus cross-device consistency, thanks to centralized sequence tracking.

Operational Efficiency

Automated retraining and scalable serving cut operational overhead and sped up model updates.

Room to Scale

The Transformer backbone extends to multi-modal inputs (images, descriptions) and multi-task cross-sell and upsell heads.

Conclusion

Switching from collaborative filtering to BERT4Rec-based sequential recommendation materially advanced the client's recommendation capability — better business metrics, and a future-proof architecture aligned to their growth.

The Transformer backbone leaves room to grow: multi-modal inputs (product images and text descriptions) and multi-task heads for cross-sell and upsell are natural extensions on the same trained sequence encoder. The project underscores what advanced architectures are worth in large-scale, real-time e-commerce personalization — provided the serving path is designed with the same rigour as the model.

Have a Recommendation Problem Like This?

Bring your catalogue size, your event volume, and your current baseline metrics. In 30 minutes we'll tell you whether a sequence model is worth it — and roughly what it takes to serve one.

Discuss your AI project Discuss your project