PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/System Design/DoorDash

Debug round-robin request router

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of round-robin routing, health-aware load balancing, dynamic membership management, rotation-index correctness, testing, and concurrency considerations.

  • medium
  • DoorDash
  • System Design
  • Software Engineer

Debug round-robin request router

Company: DoorDash

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: Technical Screen

Given a list of backends and an incoming stream of requests, implement a round-robin request router that returns the next healthy server for each request. Handle server add/remove and health changes, ensure fair rotation with correct wrap-around, and avoid skipped or duplicated assignments. You are given failing tests indicating incorrect routing—identify and fix the bug, then write tests for single server, multiple servers, removal during routing, and health flapping. Analyze complexity and thread-safety considerations.

Quick Answer: This question evaluates understanding of round-robin routing, health-aware load balancing, dynamic membership management, rotation-index correctness, testing, and concurrency considerations.

Related Interview Questions

  • Design a resilient bootstrap API - DoorDash (medium)
  • Design Real-Time Driver Pay Aggregation - DoorDash (hard)
  • Design personalized restaurant search and recommendations - DoorDash (medium)
  • Design Food Ratings and Driver Payouts - DoorDash (medium)
  • Design a Customer Review Page - DoorDash (medium)
DoorDash logo
DoorDash
Aug 9, 2025, 12:00 AM
Software Engineer
Technical Screen
System Design
21
0

Round-Robin Request Router with Health and Dynamic Membership

You are given a list of backend servers and an incoming stream of requests. Implement a round-robin request router that returns the next healthy server for each request.

Requirements

  • Round-robin across servers with correct wrap-around.
  • Only return healthy servers; skip unhealthy ones.
  • Support server add and remove at runtime.
  • Support health state changes at runtime.
  • Ensure fair rotation (no skipped or duplicated assignments when state changes happen).
  • If no healthy servers exist, the router should signal that state (e.g., by raising an exception or returning a sentinel).

Bug-Fix Prompt

You are given failing tests indicating incorrect routing order after server removal and during health flapping. Identify the likely bug causing skipped or duplicated assignments and fix it.

Deliverables

  1. Implement the router with the following interface (or equivalent in your language):
    • add_server(id)
    • remove_server(id)
    • set_health(id, healthy: bool)
    • next() -> id (returns the next healthy server)
  2. Fix the routing bug so that:
    • The rotation index is correctly advanced only after returning a server.
    • Removal of a server adjusts the rotation index to avoid skipping or duplicating assignments.
  3. Write tests for:
    • Single server
    • Multiple servers
    • Removal during routing
    • Health flapping (servers toggling between healthy/unhealthy)
  4. Analyze time/space complexity and discuss thread-safety considerations and mitigations.

Assumptions

  • Server IDs are unique and comparable (e.g., strings or integers).
  • If all servers are unhealthy (or there are none), the router returns a defined error or raises an exception.
  • New servers are appended to the rotation and should be included in subsequent calls to next().

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More DoorDash•More Software Engineer•DoorDash Software Engineer•DoorDash System Design•Software Engineer System Design
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.