LLM Provider Pool Failover
Updated
Problem statement
You operate a prioritized pool of external LLM providers. The array providers lists their unique names from highest to lowest priority. Every provider is initially healthy.
Process the events in events from left to right:
["DOWN", provider]marksproviderunhealthy.["UP", provider]marksproviderhealthy.["REQUEST"]routes one request to the healthy provider with the smallest index inproviders. If every provider is unhealthy, the result for that request is"UNAVAILABLE".
UP and DOWN events are idempotent. A recovered higher-priority provider is eligible for the next request immediately.
Return a string array containing the routed provider name, or "UNAVAILABLE", for every REQUEST event in event order. Health-change events do not add an output.
Function
routeRequests(providers: String[], events: String[][]) → String[]Examples
Example 1
providers = ["openai","anthropic","gemini"]events = [["REQUEST"],["DOWN","openai"],["REQUEST"],["DOWN","anthropic"],["REQUEST"],["UP","openai"],["REQUEST"]]return = ["openai","anthropic","gemini","openai"]The first request uses openai. After it goes down, anthropic is the highest-priority healthy provider. After anthropic also goes down, the next request uses gemini. Bringing openai back makes it the highest-priority choice again.
Example 2
providers = ["alpha","beta"]events = [["DOWN","alpha"],["DOWN","beta"],["REQUEST"],["UP","beta"],["REQUEST"]]return = ["UNAVAILABLE","beta"]The first request arrives while both providers are down, so it produces "UNAVAILABLE". After beta recovers, the next request routes to beta.
Constraints
1 <= providers.length <= 10^51 <= events.length <= 10^5- Provider names are unique non-empty lowercase strings.
- Every
UPorDOWNevent names a provider inproviders. - Each event is exactly one of the three documented shapes, and at least one event is
["REQUEST"]. - The total number of characters across provider names and events is at most
10^6.
More Perplexity AI interview questions
- In-Memory Filesystem CommandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Resource Reconciler: Plan and Apply CreatesPHONE SCREEN · Seen Nov 2026
- Agent Task Dependency TrackerPHONE SCREEN · Seen May 2026
- Feature Flags with Rules, Dependencies and ExposureONSITE INTERVIEW · Seen Nov 2026
- Out-of-Order Bank Ledger BalancesOA · Seen Nov 2026
- Sort Topic Names by Prefix and NumberONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
- Design Authentication ManagerApple · PHONE SCREENApple interview questions
- ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
- Tiered Expiring Item StoreAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Multi-Level Inventory Storage SystemOptiver · OA · PHONE SCREENOptiver interview questions
- Limit Order Book Matching EngineCitadel · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions