AI Interview Prep

AI Interview Prep

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.

Hao Hoang's avatar
Hao Hoang
Nov 26, 2025
โˆ™ Paid

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 ๐Ž๐Ž๐Œ (๐Ž๐ฎ๐ญ ๐จ๐Ÿ ๐Œ๐ž๐ฆ๐จ๐ซ๐ฒ) ๐ž๐ซ๐ซ๐จ๐ซ.

AI Interview Prep is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.

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.

Already a paid subscriber? Sign in
ยฉ 2026 Hao Hoang ยท Privacy โˆ™ Terms โˆ™ Collection notice
Start your SubstackGet the app
Substack is the home for great culture