Mailbox: A queue of incoming messages an actor processes one at a time, so its own state never needs locks. In the actor model, a mailbox is the queue of incoming messages for one actor. The actor takes messages from its mailbox one at a time and handles each fully before starting the next.
Because only the actor itself touches its state, and only one message at a time, there are no race conditions inside an actor and no need for locks.
What should you keep in mind with Mailbox?
The mailbox can also become a bottleneck. If messages arrive faster than the actor can process them, the mailbox grows and memory use climbs. Monitoring mailbox size, limiting it, or adding more actors to share the work are the usual answers. A queue worker processing jobs one by one follows the same idea, which is why queue length is such an important metric to watch.
Use when code runs things at the same time - threads, async/await, queues and workers, parallel requests, cron jobs, webhooks that retry - or when a bug only happens "sometimes" or under load. Covers race conditions, deadlocks, mutexes/locks, atomic operations, idempotency, message queues and backpressure, with Laravel and database examples.
Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.