Load Balancing And Resource Lifecycle Simulation
Asked of: Software Engineer
Last updated

What's being tested
These problems test stateful simulation with deterministic load-balancing behavior: routing, locking, lifecycle transitions, eviction, and shutdown handling. Interviewers are probing whether you can turn ambiguous product rules into clean data structures, preserve invariants, and handle edge cases without overcomplicating the code.
Patterns & templates
-
Entity state maps — use
dict[id] -> statefor connections, accounts, or targets; most operations should beO(1)average time. -
Round-robin pointer — maintain
next_index; after choosing a target, advance modulon, skipping unavailable or full targets carefully. -
Capacity-aware routing — track
load[target]and reject or reroute whenload[target] == capacity[target]; define deterministic tie-breaking upfront. -
Sticky assignment — keep
connection_id -> target; duplicateconnectshould usually return existing assignment, not consume capacity again. -
Lifecycle transitions — model
connect,disconnect,shutdown,lock,unlock, andevictas explicit state changes with invariant checks. -
LRU cache template — combine
dictplus doubly linked list orOrderedDict;get/put/evict areO(1). -
Ordered rerouting on shutdown — collect affected connections in stable order, free old capacity, then reassign deterministically to avoid hidden ordering bugs.
Common pitfalls
Pitfall: Treating duplicate connects as new connections, which silently inflates load and breaks capacity invariants.
Pitfall: Updating the round-robin pointer on failed assignment; clarify whether failed attempts should advance before coding.
Pitfall: Handling shutdown by deleting a server first, then losing the list or order of connections that must be rerouted.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
Related concepts
- Round-Robin Load BalancingCoding & Algorithms
- Database Stability And SLOsSoftware Engineering Fundamentals
- Reliability, Performance, And Infrastructure OperationsSystem Design
- Distributed Job Scheduler SystemsSystem Design
- Caching And Stateful Data Structure DesignCoding & Algorithms
- Real-Time Systems, WebSockets, and Long-Lived Connections