Problem · Design

Customer Bootstrap API

Learn this problem
MediumDoorDash logoDoorDashFULLTIMEPHONE SCREEN

Problem statement

Implement a deterministic customer-bootstrap endpoint that orchestrates three downstream services.

First resolve an email address through USER to obtain a customer identifier. After that succeeds, resolve PAYMENT and ADDRESS independently; these two lookups are logically concurrent.

The input response schedule contains rows [service, attempt, latencyMs, statusCode, value]. The service is USER, PAYMENT, or ADDRESS. A missing row represents a timeout. For each service, inspect attempts from 1 through maxAttempts:

  • A response succeeds when its latency is at most timeoutMs and its status is 200. Return its value.
  • A response with latency greater than timeoutMs, a missing response, or status 500 through 599 is retryable.
  • Any other status is terminal for that service.

If USER does not succeed, return three empty strings. Otherwise return [customerId, defaultCard, address]. A failed PAYMENT lookup contributes UNKNOWN_CARD; a failed ADDRESS lookup contributes UNKNOWN_ADDRESS. The independent downstream lookup may succeed even when the other one fails.

Function

bootstrapCustomer(email: String, timeoutMs: int, maxAttempts: int, responses: String[][]) → String[]

Examples

Example 1

email = "alex@example.com"timeoutMs = 100maxAttempts = 2responses = [["USER","1","20","200","c42"],["PAYMENT","1","150","200","card-old"],["PAYMENT","2","40","200","card-7"],["ADDRESS","1","30","503",""],["ADDRESS","2","25","200","12 Main St"]]return = ["c42","card-7","12 Main St"]

The user lookup succeeds immediately. The first payment response exceeds the timeout and the first address response is retryable, so both downstream services succeed on attempt 2.

Constraints

  • 1 <= email.length <= 254
  • 1 <= timeoutMs <= 60000
  • 1 <= maxAttempts <= 10
  • 0 <= responses.length <= 30
  • Every row has exactly five fields and names one of the three services.
  • Each service has at most one row for a given attempt number; attempt numbers are in [1, maxAttempts].
  • Latency and status fields are decimal integers. Latency is nonnegative.
  • Values contain at most 200 visible ASCII characters.

More DoorDash problems

drafts saved locally
public String[] bootstrapCustomer(String email, int timeoutMs, int maxAttempts, String[][] responses) {
  // write your code here
}
email"alex@example.com"
timeoutMs100
maxAttempts2
responses[["USER","1","20","200","c42"],["PAYMENT","1","150","200","card-old"],["PAYMENT","2","40","200","card-7"],["ADDRESS","1","30","503",""],["ADDRESS","2","25","200","12 Main St"]]
expected["c42", "card-7", "12 Main St"]
checking account