This question evaluates understanding of randomized selection, efficient in-memory data structures, and API/state management for a fixed-capacity load balancer that must support addNode, removeNode, and uniform random routing while handling duplicates, removals, and empty-state behavior.
Implement a minimal in-memory load balancer that routes each incoming request to one backend node chosen uniformly at random.
K
.
addNode(nodeId)
K
, define and document what happens (e.g., reject the add / throw).
removeNode(nodeId)
route()
(or
getNodeForRequest()
)
route()
efficient (ideally O(1)).
Describe the data structures and implement the API (language-agnostic or Java-style).