22/27
Part 7 of 7 · Follow-upsLearn and do

What interviewers ask next

One write-up lists follow-ups after the count (1 report). Here they are, with the level that covers each:

  • Print the whole tree's structure. That's level 2.
  • A machine crashes or a message fails. Retries, a request id and cached answers, so nothing counts twice. That's level 3, and the next step covers a machine that never comes back.
  • Concurrency. Keep each request's state apart by its id. That's level 4. With threads, add a lock around each machine's state: a threading.Lock that only one thread can hold at a time, so two messages never change the same machine at once.
  • Build sendAsyncMessage yourself, and test it. The interviewer may send you back to code it.

Two more come up naturally with this question, though the reports don't list them: what if the links form a graph, and what a count costs.

Build the network yourself

The network has two jobs. send puts a message at the end of a queue and returns, without calling anything. A run loop takes the oldest message and calls receive on the machine it was sent to, until the queue is empty.

Add one guard. Two machines that always reply to each other never go quiet, so run stops after a limit and returns how many it delivered. A test that hangs teaches you nothing. A test that stops at 1,000 deliveries tells you something answers forever.

The editor holds Network, with send and run to write, and Echo, a machine that answers a ping with a pong, to try it on. Write send and run.