As asked
When would you choose handle_call over handle_cast in a GenServer, and what are the failure modes you need to think about for each?
Sample answer outline
handle_call is synchronous, gives a reply, and lets the caller know if the server crashed (it gets an error). handle_cast is fire-and-forget, faster, but the caller has no visibility into failure or ordering. A strong answer mentions that using cast for state mutation without knowing if it succeeded can cause subtle bugs, and that call adds back-pressure naturally while cast can overwhelm a slow server.
Expect these follow-ups
- How would you implement a timeout on a GenServer call, and what happens to the server when the caller times out?
- Could you ever replace a synchronous call with a cast plus a separate monitor on the server? What would that buy you?