Payment Partner Routing: Round-Robin and Percentage Splits with Bank Availability
Quick Overview
A coding question about routing payments to partner banks by country and currency while skipping banks marked unavailable. The first part asks for round-robin routing that keeps banks equally loaded, and the second for percentage splits such as 70/30, testing state design, determinism and edge-case handling.
Payment Partner Routing: Round-Robin and Percentage Splits with Bank Availability
Company: Stripe
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Online Assessment
Build a router that picks a partner bank for each payment. Partners are configured per country and, within a country, per currency:
```text
US:
USD: chase, bank_of_america
EUR: wells, bank_of_america
UK:
USD: symphony, tello
EUR: bank2, bank9
```
A separate availability list says whether a bank is available at the current moment, and it can change while the router runs:
```text
Chase: no
bank_of_america: yes
```
A bank that does not appear in the availability list is assumed to be available. An unavailable bank must not receive payments.
Assume the router is built from these two lists and exposes `route(country, currency)`, which returns the name of the chosen bank, plus a way to update a bank's availability.
### Clarifying Questions
- Does "equally loaded" mean equal counts within each country and currency pool, or equal totals per bank? bank_of_america serves both US USD and US EUR.
- The availability list writes `Chase` and the partner list writes `chase`. Should names match case-insensitively?
- Is load measured in number of payments or in payment amount?
- What should `route` do when every bank in the pool is unavailable, or when the country or currency is not configured?
- Will `route` be called from several threads, or from several servers that should share one view of the load?
### Part 1: Round-robin routing
Route payments in round-robin order so that the banks are equally loaded, skipping unavailable banks.
```hint Keep a position
Round-robin needs state that survives between calls. Decide what that state is keyed by, and where it should point after a bank is skipped.
```
#### What This Part Should Cover
- The state kept between calls and what it is keyed by.
- Skipping unavailable banks, including a bank whose availability changes mid-stream.
- Behavior when no bank in the pool is available or the pool is unknown.
- Tests built on a fixed sequence of calls.
### Part 2: Percentage-based routing
Now route by configured percentages. For example, 70% of USD payments in the US go to chase and 30% to bank_of_america.
```hint Exact or on average
Decide whether 70% must hold over every short run of payments or only on average over many, then pick a mechanism that delivers that.
```
#### Clarifying Questions for this Part
- When chase is unavailable, should its share move to bank_of_america, or should those payments fail?
- Do pools without a configured split keep the round-robin behavior from Part 1?
- How should a split that does not add up to 100% be handled?
#### What This Part Should Cover
- A mechanism that meets the split exactly over short runs or in expectation, with the choice justified.
- Behavior when a weighted bank is unavailable.
- Validation of the split configuration.
- How the Part 1 behavior fits in as the equal-split case.
### What a Strong Answer Covers
- Data structures that fit the nested country and currency configuration and the default-available rule.
- Deterministic, testable routing in both parts, ideally through one code path.
- Explicit handling of unavailable banks, empty pools and unknown inputs.
- What changes when calls are concurrent or the router runs on several servers.
### Follow-up Questions
- A bank returns after an hour of being unavailable. Should it catch up on the payments it missed, and what could go wrong if it does?
- How would you keep the 70/30 split accurate with the router running on several servers?
- How would you move traffic away from a bank that is marked available but whose payments are failing at a high rate?
- How would you retry a payment on another bank in the pool after the first bank declines it?
Overview: A coding question about routing payments to partner banks by country and currency while skipping banks marked unavailable. The first part asks for round-robin routing that keeps banks equally loaded, and the second for percentage splits such as 70/30, testing state design, determinism and edge-case handling.
A separate availability list says whether a bank is available at the current moment, and it can change while the router runs:
Chase: no
bank_of_america: yes
A bank that does not appear in the availability list is assumed to be available. An unavailable bank must not receive payments.
Assume the router is built from these two lists and exposes route(country, currency), which returns the name of the chosen bank, plus a way to update a bank's availability.
Clarifying Questions Guidance
Does "equally loaded" mean equal counts within each country and currency pool, or equal totals per bank? bank_of_america serves both US USD and US EUR.
The availability list writes
Chase
and the partner list writes
chase
. Should names match case-insensitively?
Is load measured in number of payments or in payment amount?
What should
route
do when every bank in the pool is unavailable, or when the country or currency is not configured?
Will
route
be called from several threads, or from several servers that should share one view of the load?
Part 1: Round-robin routing
Route payments in round-robin order so that the banks are equally loaded, skipping unavailable banks.
What This Part Should Cover Guidance
The state kept between calls and what it is keyed by.
Skipping unavailable banks, including a bank whose availability changes mid-stream.
Behavior when no bank in the pool is available or the pool is unknown.
Tests built on a fixed sequence of calls.
Part 2: Percentage-based routing
Now route by configured percentages. For example, 70% of USD payments in the US go to chase and 30% to bank_of_america.
Clarifying Questions for this Part Guidance
When chase is unavailable, should its share move to bank_of_america, or should those payments fail?
Do pools without a configured split keep the round-robin behavior from Part 1?
How should a split that does not add up to 100% be handled?
What This Part Should Cover Guidance
A mechanism that meets the split exactly over short runs or in expectation, with the choice justified.
Behavior when a weighted bank is unavailable.
Validation of the split configuration.
How the Part 1 behavior fits in as the equal-split case.
What a Strong Answer Covers Guidance
Data structures that fit the nested country and currency configuration and the default-available rule.
Deterministic, testable routing in both parts, ideally through one code path.
Explicit handling of unavailable banks, empty pools and unknown inputs.
What changes when calls are concurrent or the router runs on several servers.
Follow-up Questions Guidance
A bank returns after an hour of being unavailable. Should it catch up on the payments it missed, and what could go wrong if it does?
How would you keep the 70/30 split accurate with the router running on several servers?
How would you move traffic away from a bank that is marked available but whose payments are failing at a high rate?
How would you retry a payment on another bank in the pool after the first bank declines it?