Implement and compare round-robin and consistent hashing
DoorDashSoftware Engineer · OnsiteLast updated
This question evaluates a candidate's ability to implement and reason about load balancing algorithms (round-robin and consistent hashing), covering competencies in data structures, hashing, concurrency, correctness, and unit testing.
Implement a round-robin load balancer that selects among service nodes, skipping unavailable nodes and wrapping around correctly. Fix typical pitfalls: avoid typos in status constants, ensure the current-index state persists correctly across calls (thread-safe, no unintended resets), and guarantee the algorithm never returns an unavailable node; add comprehensive unit tests to catch these cases. Then implement a consistent-hashing load balancer with virtual nodes; support node additions/removals with minimal key movement and demonstrate how you locate the next available node when the initial target is down. Compare the two approaches in terms of time/space complexity, rebalancing behavior, cache affinity, failure handling, hotspot risk, and typical production use cases.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.