Supervision strategy for a stateful web client?

Thanks @tomekowal for the insights. Totally get the b) topic on Worker.start_link/1 running in the context of the WorkerSupervisor, and therefore somehow bringing the self() call ‘down’.

Regarding your a) suggestion to use a :rest_for_one strategy, and that the worker can’t exist without the agent: In principle I understand that the worker needs an agent to store it’s state. However, the implementation currently has an interesting quirk: The worker doesn’t store the Agent’s pid, but always asks the parent Supervisor for the agent’s pid. In a situation where the worker is humming along, it has an up-to-date copy of the current state in the worker. If the Agent now crashes, the Supervisor re-starts a fresh (empty) agent. In the next ‘save’ operation (from the worker to the agent), the latest state get’s ‘replicated’ from the worker to the agent. So by keeping the worker running when the agent dies, I still have a copy of the current state.

Does that make sense?