Handle Billions of Sparse IDs With the Hashing Trick and Embedding Tables

Last updated: November 29, 2026

Quick Overview

A click-through model uses customer IDs, product IDs and seller IDs with billions of distinct values. Explain how you would represent them with embeddings, when to use the hashing trick, and how to reason about collisions.

Amazon
Machine Learning
Machine Learning Engineer
Amazon
November 29, 2026
Machine Learning Engineer
Technical Screen
Machine Learning
Medium

0

0

0 solved


A click-through model uses customer IDs, product IDs and seller IDs with billions of distinct values. Explain how you would represent them with embeddings, when to use the hashing trick, and how to reason about collisions.

Ads and recommendation models at Amazon have enormous sparse categorical features, and embedding tables can dominate model size. The interviewer checks memory arithmetic, collision math, and practical mitigations.

What the Interviewer Expects
  • Estimate embedding table memory
  • Explain the hashing trick and its collision trade-off
  • Compute collision probabilities
  • Describe mitigations: multiple hashes, frequency thresholds, mixed dimensions
  • Handle new IDs at serving time
Key Topics to Cover
Embeddings
Hashing trick
Sparse features
Hash collisions
Model memory
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
  • How would you shard a 500 GB embedding table across machines?
  • What do you do with IDs seen only once?
  • How do you keep embeddings for new IDs fresh without full retraining?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Explore ML Interview Prep
Sample Answer
Clarify

Ask distinct counts per feature, frequency skew (most IDs are rare), embedding dimension, and whether the model is retrained daily or continuously....

Approach

A full table costs rows times dimension times bytes: 1 billion product IDs at dimension 64 in fp32 is 109⋅64⋅4=25610^9\cdot64\cdot4=256 GB, before optimizer state. The hashing trick maps each value to $h(\text{...


Submit Your Answer
Markdown supported