AO
Back

Session Manager Load Balancing Implementation

CodingPhone, OnsiteLast reported May 2026Low Frequency

Problem Overview

Part 1 — Session Manager

Reported once: the coding half of a one-hour first-round phone screen. You are given a template class to implement: a session manager with two functions.

  • start_session(session_id: str) -> None starts a new session on one of the servers. A session id that has already started must not be added again.
  • get_allocation() -> Dict[str, Set[str]] returns each server mapped to the set of session ids it holds.

Sessions must stay balanced. The report's example has three servers, [s1, s2, s3]: at all times no server's session count may differ from any other server's by more than 1, so [8, 8, 8] and [8, 8, 7] are fine.

At the end you write your own test cases; the report says a few normal cases and edge cases were enough.

What the tests call. SessionManager(servers), then start_session(session_id) and get_allocation(). Our setup — ask your interviewer: the class name SessionManager and a constructor that takes the list of server ids (the report doesn't say how the servers are given; a constructor with no argument that uses s1, s2, s3 also passes). The tests check that counts never differ by more than 1, that every started id sits on exactly one server, and that a repeated id is not added again (ignoring it or raising both pass). They do not check server names, tie-breaks, or which server gets a given session.

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Round robinour analysis: also meets the reported balance rule while sessions are only added; the min-heap is the reported approach
Linear min() over the countsour analysis: O(servers) per insert instead of O(log servers); with three servers it is equally fine

What Reports Emphasize

Edge cases probed: A repeated session id: an id that has already started must not be added again (the one edge case the report names; it doesn't say whether to ignore it or raise)

Practice

Write your own against 5 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Palantir with friends?

Send them this page. It is free to read, no account needed.

More Palantir Questions

Free preview

Every question in the Palantir catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 11 Palantir questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Palantir · Coding · Reported 1× across candidate reports
Is this helpful?