Specify Proximity-Based Request Routing

Quick Overview

Clarify proximity metrics, destination eligibility, tie rules, and capacity before designing a request-routing algorithm.

Specify Proximity-Based Request Routing

Company: Stripe

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Online Assessment

Design proximity-based request routing. Explain what information a request and a destination must provide, how proximity is measured, and how the routing decision should account for unavailable or unsuitable destinations. ### Constraints Only the proximity-routing objective is supplied. The distance metric, destination eligibility, capacity, tie rule, and output format are unresolved. Do not infer a particular external routing problem. Any concrete selection algorithm must be tied to explicitly stated assumptions. ### Clarifying Questions - Does proximity mean geographic distance, network latency, topology distance, or another score? - Which destinations are eligible, and are health and capacity constraints part of selection? - How are ties and the absence of an eligible destination handled? - Are inputs a fixed snapshot or changing while requests are routed? ```hint Filter before optimizing the score The nearest destination is useful only if it is allowed and able to serve the request under the declared policy. ``` ### What a Strong Answer Covers - A complete routing contract with proximity and eligibility distinguished. - A conditional baseline algorithm and data structures appropriate to the metric. - Deterministic ties, stale-state behavior, validation, and resource tradeoffs. ### Follow-up Questions - When would a spatial index help, and when would it be irrelevant? - How would you avoid routing every request to one nearby destination?

Overview: Clarify proximity metrics, destination eligibility, tie rules, and capacity before designing a request-routing algorithm.

Community answers

Answer by sunil.shah

If we assume geographic proximity, then each request contains a latitude/longitude and each destination contains latitude/longitude plus operational metadata such as availability and capacity. I would first filter destinations to only those eligible to serve the request. For example, remove destinations that are offline, at capacity, or incompatible with the request. Then I would compute the distance between the request and every remaining destination. For geographic coordinates, I could use Haversine distance. The destination with the minimum distance is selected. If two destinations have the same distance, I would use a deterministic tie-breaking rule such as destination ID unless the product specifies something like remaining capacity. If no destinations are eligible, the routing result should explicitly indicate that no route is available rather than silently choosing an unsuitable destination.

Answer by greatestn00bc0der

As to my understanding, proximity based routing is based on distances between the sources and destination. If we consider them to be on the 2D Plane, the source can be represented as (X_s, Y_s, payload) and the destination can be something like (X_d, Y_d, status, capacity, payload). Now initial check would be to look for only valid destinations, if any destination node is 'inactive' we can ignore them, and only use the valid 'active' destination nodes. Next, we need to find the destination that has the minimal distance from the source, we can use method like Euclidean Distance to find the min distance and make that as the destination, and based on that we can transfer the payload from source to destination. Another crucial check would be the capacity of the destination, if its lesser then the payload then it can be ignored and we go to the next best 'valid' destination node.
Stripe logo
Stripe
Sep 10, 2026
easySoftware EngineerOnline AssessmentSoftware Engineering Fundamentals
36
0

Design proximity-based request routing. Explain what information a request and a destination must provide, how proximity is measured, and how the routing decision should account for unavailable or unsuitable destinations.

Constraints

Only the proximity-routing objective is supplied. The distance metric, destination eligibility, capacity, tie rule, and output format are unresolved. Do not infer a particular external routing problem. Any concrete selection algorithm must be tied to explicitly stated assumptions.

Clarifying Questions Guidance

  • Does proximity mean geographic distance, network latency, topology distance, or another score?
  • Which destinations are eligible, and are health and capacity constraints part of selection?
  • How are ties and the absence of an eligible destination handled?
  • Are inputs a fixed snapshot or changing while requests are routed?

What a Strong Answer Covers Guidance

  • A complete routing contract with proximity and eligibility distinguished.
  • A conditional baseline algorithm and data structures appropriate to the metric.
  • Deterministic ties, stale-state behavior, validation, and resource tradeoffs.

Follow-up Questions Guidance

  • When would a spatial index help, and when would it be irrelevant?
  • How would you avoid routing every request to one nearby destination?