Sharing memory versus passing messages
In message passing, units communicate by sending copies of data rather than touching shared memory. Because nothing is shared, there is no shared write to synchronize. The hard questions move to delivery guarantees.
The delivery spectrum
- At most once. A message may be lost but is never duplicated. Simple, but you can drop work.
- At least once. A message is retried until acknowledged, so it may arrive twice. Receivers must be idempotent.
- Exactly once. The ideal, but it requires deduplication state and acknowledgements; truly end to end exactly once is hard.
Ordering
Many systems guarantee order only per sender to receiver pair, not globally. If two senders message the same actor, their messages can interleave in any way. Protocols that depend on order must carry sequence numbers.
Sync versus async
A synchronous send blocks until the receiver is ready, which couples timing. An asynchronous send drops the message into a buffer and returns, decoupling sender from receiver at the cost of buffering and backpressure concerns.
Key idea
Message passing replaces shared memory with copies, so correctness hinges on delivery guarantees and ordering rather than locks.