← Google Interview Insights

Google·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
May 2026

Summary

Google system design round for a software engineer role. The whole session was basically one long deep-dive on streaming medians at scale, and it went places I did not expect.

Questions Asked (1)

Q1

The classic two-heap approach for streaming medians runs out of memory on a very large or unbounded stream. Walk through where the bottlenecks are and how you'd redesign the system to keep producing medians, either exact or approximate, under tight memory constraints.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

I started confidently with the two-heap setup and then kind of froze when they said 'now assume memory is the constraint.' My first instinct was to throw a quantile sketch at it and call it a day, but they pushed back immediately on accuracy guarantees.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by dissecting the memory bottlenecks of the two-heap approach: each element is stored, so memory grows linearly with stream size. Then propose a redesign that either bounds memory via approximation (e.g., sketches) or uses external storage with periodic compaction. Emphasize trade-offs between exactness, memory, and latency, and tailor the solution to the constraints.

Pro tip: Show awareness that Google often deals with massive data streams, so mention real-world systems like BigQuery or Dataflow and how they handle approximate quantiles. Also, discuss how you'd validate the solution with metrics like error bounds and throughput.

1. Identify bottlenecks

Explain that the two-heap approach stores all elements, leading to O(n) memory, and that rebalancing operations add overhead. Also note that for unbounded streams, memory will eventually exhaust.

2. Clarify requirements

Ask whether exact medians are required or if approximate is acceptable, and discuss memory constraints, latency, and accuracy trade-offs.

3. Propose approximate solutions

Suggest memory-efficient algorithms like t-digest, Greenwald-Khanna, or count-min sketch with a heap for approximate medians, highlighting their error guarantees.

4. Consider exact alternatives

If exact is needed, propose external sorting or storing data on disk with periodic merging, or using a distributed system with map-reduce to compute medians in batches.

5. Evaluate trade-offs

Compare approaches on memory usage, accuracy, latency, and complexity, and recommend a solution based on the specific constraints.

Key Points to Mention

  • Memory complexity of two-heap: O(n) due to storing all elements.
  • Approximate algorithms: t-digest, Greenwald-Khanna, count-min sketch, reservoir sampling.
  • Error guarantees and confidence intervals for approximate medians.
  • External storage and batch processing for exact medians.
  • Distributed computing frameworks like MapReduce or streaming engines (e.g., Apache Flink).
  • Trade-offs between exactness, memory, latency, and implementation complexity.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.