Machine Learning System Design Interview #6 - The Streaming Median Trap
Why exact statistics crash real-time fraud systems - and how sketching algorithms save you from OOM failure.
Youโre in a Senior ML System interview at Google DeepMind.
The interviewer smiles and sets a trap:
โWe need to detect fraud in real-time. Write a function to calculate the running Global Median of transaction values coming from the payment stream.โ
90% of candidates walk right into the ๐๐๐ (๐๐ฎ๐ญ ๐จ๐ ๐๐๐ฆ๐จ๐ซ๐ฒ) ๐๐ซ๐ซ๐จ๐ซ.
The reflex is to think in Python scripts.
- โEasy. Iโll maintain a list of transaction values.โ
- โOn every new event, Iโll append to the list, sort it, and pick the middle index.โ
- โOr Iโll just use numpy.median() on the buffer.โ
The interviewer stops you. โThe stream is unbounded. It never ends. You just tried to sort infinity.โ
In Batch processing, median is a sorting problem. You have the full dataset in RAM.
In Stream processing, you never have the full dataset.
If you try to store every transaction to calculate an exact median, your memory footprint grows linearly O(N) until your container crashes. You arenโt building a fraud detector; youโre building a memory leak.
The Solution: ๐๐ง๐๐จ๐ฎ๐ง๐๐๐ ๐๐ฉ๐ฉ๐ซ๐จ๐ฑ๐ข๐ฆ๐๐ญ๐ข๐จ๐ง ๐๐๐ญ๐ญ๐๐ซ๐ง.
Keep reading with a 7-day free trial
Subscribe to AI Interview Prep to keep reading this post and get 7 days of free access to the full post archives.

