Implement round-robin load balancer
DoorDashSoftware Engineer · OnsiteLast updated
This question evaluates a candidate's ability to implement a strict round-robin load balancer with O(1) average operations while handling concurrent nextServer and update calls, health-check-driven skipping, and failure scenarios, testing competencies in data structures, concurrent programming, and fault-tolerant system behavior.
Implement a load balancer that distributes incoming requests across N backend servers in strict round-robin order. Requirements: (
- Support addServer(id), removeServer(id), and nextServer() operations in O(
- average time; (
- Skip servers marked unhealthy via markHealthy(id, isHealthy) without breaking round-robin fairness; (
- Ensure thread-safe behavior under concurrent calls to nextServer and server updates; (
- Discuss failure scenarios (e.g., a server crashes mid-selection) and how you would design health checks; (
- Provide unit tests and analyze time/space complexity.
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.