Scale median under memory constraints

Read the full interview experience this question came from →

Quick Overview

This interview question evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer for Scale median under memory constraints states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Scale median under memory constraints

Company: Google

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Onsite

Assume the two-heap streaming-median approach exceeds available memory for a very large or unbounded stream. Identify the bottlenecks and propose scalable designs to continue producing exact or approximate medians and the loose-median interval under memory constraints. Consider options such as external-memory algorithms, bucketization, quantile sketches, distributed aggregation, and windowed processing. Explain trade-offs in accuracy, latency, memory, and I/O, and outline failure handling and back-pressure strategies.

Overview: This interview question evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer for Scale median under memory constraints states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Read the full Google Software Engineer interview experience this question came from

|Home/System Design/Google
Google logo
Google
Aug 8, 2025
hardSoftware EngineerOnsiteSystem Design
9
0

Scale median under memory constraints

Design a Scalable Streaming Median Service Under Memory Constraints

Context

You are building a service that consumes a very large or unbounded stream of numeric values and must continuously report:

  • The median (exact if feasible, otherwise approximate), and
  • A "loose-median" interval: a value range [L, R] guaranteed to contain the true median.

The classic two-heap (max-heap for lower half, min-heap for upper half) approach requires storing all seen values and therefore exceeds memory when the stream is very large.

Tasks

  1. Identify the bottlenecks of the in-memory two-heap approach for very large/unbounded streams.
  2. Propose scalable designs that continue producing exact or approximate medians and the loose-median interval under memory constraints. Consider:
    • External-memory (disk-backed) algorithms
    • Bucketization/histograms
    • Quantile sketches (e.g., GK, KLL, t-digest)
    • Distributed aggregation
    • Windowed (e.g., sliding/tumbling) processing
  3. Explain the trade-offs across accuracy, latency, memory, and I/O for each option.
  4. Outline failure handling and back-pressure strategies suitable for a production service.

State any minimal assumptions you make (e.g., numeric domain, tolerance for approximation, latency SLOs).

Clarifying Questions to Ask Guidance

  • Clarify users, core use cases, read/write patterns, scale, latency, availability, and data retention.
  • State explicit assumptions before making sizing or architecture decisions.
  • Prioritize the functional path first, then address reliability, security, observability, and rollout.

What a Strong Answer Covers Guidance

  • A scoped requirements summary with concrete non-goals and success metrics.
  • API, data model, architecture, consistency, capacity, and operations.
  • Reasoned trade-offs among simple and scalable designs, including bottlenecks and failure modes.
  • A validation, monitoring, migration, and launch plan appropriate for the risk level.

Follow-up Questions Guidance

  • What breaks first at 10x traffic or data volume?
  • How would you degrade gracefully during dependency failures?
  • What metrics and alerts would prove the design is healthy after launch?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...