← Back
00:00

Session Manager Load Balancing Implementation

Palantir interview questions · Medium · Coding round · reported 1× · 6 tests

Implement a SessionManager that distributes sessions across three servers: s1, s2, and s3.

Interface

class SessionManager {
  start_session(sessionId: string): void;
  get_allocation(): Record<string, Set<string>>;
}

Rules

  • start_session(sessionId) assigns the session to the server currently holding the fewest sessions.
  • If multiple servers are tied for the fewest sessions, break ties by server name order: s1, then s2, then s3.
  • If the same sessionId is submitted again, silently ignore it.
  • get_allocation() returns the current mapping from server ID to the set of assigned session IDs.
  • The allocation must always stay balanced, so the difference between the most-loaded and least-loaded server is never more than 1.
Idle