Erlang / Erlang Basics Interview questions
What is the difference between synchronous and asynchronous message passing in OTP?
Both ultimately use the same underlying ! primitive, but OTP's gen_server:call and
gen_server:cast wrap it with very different guarantees about waiting for a result.
| call (synchronous) | cast (asynchronous) |
| Caller blocks until a reply arrives or it times out. | Caller sends and continues immediately; no reply is expected. |
| Caller gets a monitor, so a server crash surfaces as an error rather than an infinite wait. | No monitor by default; if the message is lost or the server crashes, the caller has no way to know. |
| Naturally provides back-pressure — a slow server slows down its callers. | No back-pressure; a fast producer can flood a slow server's mailbox. |
The rule of thumb: use call when the caller needs a result or needs to know the operation
actually happened; use cast for fire-and-forget notifications where losing one occasionally, or
not knowing immediately if the target is alive, is acceptable.
More Related questions...