AO
Back

Multi-threaded Package Manager

Tech Deep DiveOnsiteLast reported September 2025Low Frequency

Problem Overview

Palantir's Learning round. Two posts describe this question, and they may come from one author plus a friend: one is a whole-loop guide partly compiled from other people's reports, the other describes the author's and a friend's Learning rounds. Part 2 comes from that second post only. The interviewer explains what a package manager is (one post: like NPM), shows the class definitions for packages and repositories, and asks you to explain the code before you change it. Documentation is given for every new library or piece of code. One post says the round is an hour, with about 15 minutes of behavioural questions first.

Given — the classes (our setup; ask your interviewer). The posts say class definitions were shown but give no fields, so these are ours, and so are the method names. The editor cannot start threads, so the tests pass in a RecordingExecutor: it runs each request when it is submitted, returns a finished Future, and logs every submit and every blocking Future call (.result(), .exception(), and the wait and as_completed functions). It logs done() and running() checks too: a loop that polls a future until it finishes before the next request is sent is still waiting on it, so the tests count any poll made before the last request is sent as a wait. Polling once every request is out (for example, a pointer walking the queue) is fine. Send requests through the given _get_package_future.

class PackageNotFound(Exception): ...
class Package:
    def __init__(self, name: str, version: str, payload: bytes = b""): ...
class Repository:
    def __init__(self, name: str, packages=()): ...
    def add(self, pkg: Package) -> None: ...
    def get(self, name: str) -> Package: ...      # one network call; raises PackageNotFound
class RecordingExecutor:                         # test support
    def submit(self, fn, *args) -> Future: ...    # .log gets "submit:" / "await:" / "poll:<repo>"
class PackageManager:
    def __init__(self, repos, executor): ...                       # executor is required
    def _get_package_future(self, repo, name: str) -> Future: ...  # given: one request
    def get_package(self, name: str) -> Package: ...               # Part 1
    def get_package_cached(self, name: str) -> Package: ...        # Part 2

Part 1 — Send every request before waiting

get_package(name) is given as the loop the posts quote (with our helper's name):

for repo in self.repos:
    try:
        return self._get_package_future(repo, name).result()
    except PackageNotFound:
        continue
raise PackageNotFound(name)

Every request goes over the network and .result() blocks, so the next repository is asked only after the previous one has answered. Explain the code, then rewrite get_package(name) so that every repository's request has been sent before you wait on any of them. Return the package, and raise PackageNotFound if no repository has it. The posts' fix: add every future to a queue or array, then walk it. One poster used a pointer in a while loop and says other ways work too.

Clarify first: if several repositories host the package, should the first one in the list win (what the given loop does) or the first to answer? The posts don't say, so the tests only use packages with one host. You may stop at the first hit or wait on every request.

Part 2 — Cache the repository, not the package

One post describes this part: a lot of code, with the bug inside the function itself. The fix is not to cache packages, because they can be too large, but the repository they live in: fix the values in the hash table. get_package_cached(name) is our small reconstruction of that bug, not the real code, and the separate method is our setup. Its table is keyed by package name and stores the Package. Fix it: keep the table keyed by package name, store which repository has the package (the Repository, its name or its index; your choice), and on a cached lookup fetch the package from that repository. The tests check that a cached lookup asks that repository (asking others too is allowed) and that no value in the table holds a Package.

Not reported, not graded (our analysis). Completion order (as_completed), cancelling requests still in flight after a hit, network errors versus "not found", a cached repository that no longer has the package, and thread safety of the cache. Forward Deployed candidates get a different Learning exercise: see the internal SQL-language page.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Concurrency · 1Trade-off discussion · 2
Concurrency

This code makes a network call per repository and blocks on each one. How would you make it more efficient?

Probes for: After the comprehension check
Trade-off discussion

Can you explain what this code does? (walking through the package and repository class definitions)

Probes for: Before the coding portion, after the interviewer explains the domain

There is a bug in the caching logic in this code. Find and fix it.

Probes for: Second half of the round

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Pointer in a while loop over the collected futuresOne poster's traversal after adding every request to an array; the post says other ways work too.
Completion order with as_completed or wait(FIRST_COMPLETED)Our analysis, not reported: returns the fastest repository that has the package instead of the first in the list, which changes the answer when several repositories have it. Ask which one the interviewer wants.

What Reports Emphasize

Interviewer hints: The interviewer explains what a package manager is, shows the class definitions for packages and repositories, asks you to explain the code, and gives documentation for every new library or piece of code, so no background knowledge is needed (one post).

What passers do: The one post with an outcome went on to the hiring-manager round; its author says the interviewer explained a concept, gave a function and documentation, then showed code and asked them to explain it and make it more efficient.; The fix both posts describe: add every future to a queue or array so every request is sent, then walk it calling .result() on each. One poster used a pointer in a while loop and says other ways work too (that post gives no outcome).; Advice from the posts, not observed outcomes: reading a little about threads and thread pools beforehand makes the round easy to follow, and you can ask the interviewer as many clarifying questions as you like.

Why people fail: One post says everyone seems to be failing the Learning round (one person's impression) and claims a weak Learning round gets this problem repeated by the hiring manager; the other post says it heard secondhand that the hiring manager repeats your weakest earlier round.

Practice

Write your own against 7 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 · Tech Deep Dive · Reported 2× across candidate reports
Is this helpful?