Problem, as an interviewer would state it:
"Build a batching utility (like Facebook's DataLoader): individual load(key) calls made within the SAME tick should coalesce into ONE real bulk request, with each caller correctly getting back only their own result."
Examples:
const [u1, u2, u3] = await Promise.all([loader.load(1), loader.load(2), loader.load(3)]);
// only ONE real batchFn([1,2,3]) call happens, despite 3 separate load() calls
Clarifying questions expected:
- What defines "the same tick" for batching purposes — the current synchronous execution, a microtask boundary, or a real timer-based window?
- Does the batch function receive keys in the exact order they were requested, and must results map back correctly by that same order?
- Should a load() call made in a LATER tick (after the current batch has already started) join the same batch, or start a new one?
Code / implementation expected: Yes — real, direct proof that 3 concurrent load() calls trigger exactly 1 real batch call, with each result correctly routed to its own original caller.