Build a Coalescing Queue That Keeps Each Driver's Latest Location

Last updated: November 29, 2026

Quick Overview

Driver apps send location updates faster than a downstream consumer can process during spikes. Implement a bounded, thread-safe queue that keeps only the newest update per driver, preserves fairness across drivers, and applies backpressure when full.

Uber
Software Engineering Fundamentals
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


Driver apps send location updates faster than a downstream consumer can process during spikes. Implement a bounded, thread-safe queue that keeps only the newest update per driver, preserves fairness across drivers, and applies backpressure when full.

Uber's location pipeline only cares about the freshest position for most consumers, so a plain FIFO wastes work on stale points and grows without bound under load. Interviewers check producer-consumer synchronization with condition variables, the coalescing idea, and the choice between blocking, dropping, and timing out.

What the Interviewer Expects
  • Explain why a plain bounded FIFO is wrong for latest-value data
  • Coalesce by key while keeping each key's queue position
  • Use a lock with two condition variables for not-empty and not-full
  • Avoid lost wakeups by waiting with a predicate
  • Offer a timeout so producers can choose to drop under pressure
Key Topics to Cover
Producer-consumer
Condition variables
Backpressure
Coalescing
Fairness
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • Should an update for an already queued driver move it to the back? What are the fairness effects?
  • How would you expose metrics for coalesced and dropped updates?
  • How would this look with asyncio instead of threads?
  • Which consumers must not use coalescing (for example fare distance)?
Sharpen Your Skills on Codemia

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

Practice System Design Problems
Sample Answer
Requirements

put(driver_id, update, timeout): if the driver is already queued, replace its update in place (never blocks); otherwise wait for space, up to timeout, and return False if none. get(timeout): ret...

High-Level Design

An OrderedDict gives O(1) keyed replace and O(1) pop from the front. Keeping a replaced key in its original position means a chatty driver cannot jump the line or starve others, and its latest posit...


Submit Your Answer
Markdown supported