Circuit Breaker Database Failover
Updated
Problem statement
A service sends requests to a database cluster with a PRIMARY, REPLICA_1, and REPLICA_2. Each server has an independent circuit breaker that starts CLOSED.
The input outcomes contains one row per request. Each row has exactly three values in server order: primary, replica 1, and replica 2. A value is either SUCCESS or FAILURE and describes what would happen if that server were attempted for that request.
Process requests in order. For each request:
- Consider the servers in the fixed order
PRIMARY,REPLICA_1,REPLICA_2. - Skip a server whose breaker is
OPEN. - Attempt each remaining server until one succeeds. A success resets that server's consecutive-failure count to
0and completes the request. - A failure increments only that server's consecutive-failure count. When the count reaches
2, its breaker becomesOPENpermanently for the rest of the batch. Continue to the next server for the same request.
Return one result per request: the name of the server that succeeded, or FAILED if every server is open or fails.
Function
routeDatabaseRequests(outcomes: String[][]) → String[]Examples
Example 1
outcomes = [["FAILURE","SUCCESS","SUCCESS"],["FAILURE","FAILURE","SUCCESS"],["SUCCESS","SUCCESS","SUCCESS"],["FAILURE","FAILURE","SUCCESS"]]return = ["REPLICA_1","REPLICA_2","REPLICA_1","REPLICA_2"]The primary fails twice and opens during the second request. Later requests skip it. Replica 1 succeeds on requests one and three, while replica 2 handles requests two and four.
Example 2
outcomes = [["FAILURE","FAILURE","FAILURE"],["SUCCESS","SUCCESS","SUCCESS"],["FAILURE","FAILURE","FAILURE"],["FAILURE","SUCCESS","SUCCESS"],["SUCCESS","SUCCESS","SUCCESS"]]return = ["FAILED","PRIMARY","FAILED","FAILED","FAILED"]The first request gives every server one failure. The primary then succeeds and resets. On the third request both replicas receive their second consecutive failure and open. The fourth request gives the primary its second consecutive failure, so all breakers are open from then on.
Example 3
outcomes = []return = []No requests produce no routing results.
Constraints
0 <= outcomes.length <= 10^5.- Every row has length
3. - Every value is
SUCCESSorFAILURE. - All breakers start
CLOSEDwith zero consecutive failures.
More Databricks Phone Screen questions
- Rolling Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimize CommuteOA · PHONE SCREEN · Seen Oct 2026
- Top-K Values per Key in MapReducePHONE SCREEN · Seen Oct 2026
- Customer Revenue with Direct ReferralsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- File Encryption Tree OptimizationPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Encrypted File Count and Minimum TimePHONE SCREEN · Seen Sep 2026
- Find First Anagram IndexPHONE SCREEN · Seen Aug 2026
- Ordered IP FirewallPHONE SCREEN · Seen Aug 2026
- Key-Value Store GET and PUT QPSPHONE SCREEN · Seen Aug 2026
- Snapshot Set IteratorPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
- Count Events in Rolling Minute WindowsMeta · PHONE SCREENMeta interview questions
- Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions
- Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
- Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
- Escape Room LeaderboardPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Music Player Operation SequenceAtlassian · PHONE SCREENAtlassian interview questions
- Resizable Array-Backed Integer SetThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions