Data Center Health Registry, Haversine Distance and Nearest-Healthy Routing
Company: Stripe
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
Build a small in-memory service that sends each client to a nearby data center. The exercise has three parts, each building on the previous one, and is meant to be finished in about an hour. It is closer to a math problem than to an algorithms problem: most of the risk lies in getting the distance calculation and the corner cases exactly right.
### Constraints and Clarifications
- Assume each data center has a unique identifier and a location given as latitude and longitude in decimal degrees.
- All state lives in memory, and nothing needs to be persisted.
### Clarifying Questions
- Are operations called as methods on a class, or delivered as a list of commands whose printed output is compared with expected text?
- Are coordinates guaranteed to be valid, or should invalid ones be rejected?
- How should numeric outputs, such as distances, be formatted and rounded?
### Part 1 — Data center registration and health state management
Support registering a data center with its identifier and location, updating its health state, and reading its current health state.
```hint Pin down the states
Decide up front what an update for an identifier that was never registered should do, and keep the allowed health states an explicit, closed set rather than free-form strings.
```
#### Clarifying Questions for this Part
- Which health states exist: only healthy and unhealthy, or more?
- Is a newly registered data center healthy by default, or unhealthy until its first health report?
- What should happen when an identifier is registered twice?
#### What This Part Should Cover
- A data model keyed by identifier that holds the location and the current health state
- Validation of identifiers, coordinates and state values
- Defined behavior for duplicate registrations and unknown identifiers
### Part 2 — Computing the haversine distance
Implement a function that returns the great-circle distance between two points on the Earth, each given as latitude and longitude in degrees, using the haversine formula.
```hint Units and rounding
Check what unit the trigonometric functions expect, and what floating-point rounding can do to the value you pass to the inverse sine.
```
#### Clarifying Questions for this Part
- Which Earth radius and which unit, kilometers or miles, does the expected output use?
#### What This Part Should Cover
- The haversine formula with the correct conversion from degrees to radians
- Numerical robustness for identical and nearly antipodal points
- Correct behavior across the 180th meridian and near the poles
### Part 3 — Proximity-based routing
Given a client's latitude and longitude, return the identifier of the nearest data center that is currently healthy, measured with the distance from Part 2.
```hint Decide the corner cases first
Before writing the loop, settle what the function returns when two data centers are equally close and when no data center is healthy.
```
#### Clarifying Questions for this Part
- How should exact distance ties be broken?
- What should be returned when no data center is healthy?
- Is a single data center expected, or a ranked list that allows failover?
#### What This Part Should Cover
- Filtering by health state before choosing by distance
- Deterministic tie-breaking and an explicit result when nothing is routable
- The cost per request and how it grows with the number of data centers
### What a Strong Answer Covers
- A clean separation between the registry, the distance function and the routing policy
- Correct, tested distance math, since every routing decision depends on it
- Behavior for each corner case stated before coding, not discovered by the grader
- Steady progress through all three parts within the hour
- A clear view of how the design would change beyond a handful of data centers
### Follow-up Questions
- With thousands of data centers and many routing requests per second, how would you avoid scanning every data center on each request?
- How would you stop a data center whose health flaps between states from causing routing churn?
- How would you route when the nearest healthy data center is close to its capacity?
Overview: A three-part coding exercise: register data centers with locations and health states, compute great-circle distances with the haversine formula, then route each client to the nearest healthy data center. It tests clean class design, correct spherical distance math, tie-breaking and corner-case handling under time pressure.
Read the full Stripe Software Engineer interview experience this question came from