The Actor Model
Most concurrency tools start from the same picture: several threads share an object, and we add locks so they take turns. That works, but every new shared object is a new place to forget a lock, and every operation that touches two objects is a new chance to deadlock.
The actor model starts from the opposite picture. Nothing is shared. Each piece of state belongs to exactly one actor, and the only way to change it is to send that actor a message. The actor handles its messages one at a time, so its state is never touched by two threads at once, and there is nothing to lock.
The idea is old (it dates from the 1970s), but it powers real systems today: Erlang and Elixir, which run telecom switches and chat backends, Akka and its fork Apache Pekko on the JVM, and Microsoft Orleans for game and cloud services. This post builds a tiny actor in Python, then covers the parts that make actor systems work in practice: mailboxes, tell vs ask, running many actors on few threads, and supervision.
💡 Why this matters in an interview: you rarely need an actor framework in an LLD round. But "one owner per piece of state, talk by messages" is a clean answer to many concurrency follow-ups ("what if bids arrive at the same time?"), and knowing its trade-offs shows real depth.
The Problem: Shared State Behind Locks
Here is a bank account protected the usual way:
class Account:
def __init__(self, balance: int) -> None:
self.balance = balance
self._lock = threading.Lock()
def withdraw(self, amount: int) -> bool:
with self._lock:
if amount > self.balance:
return False
self.balance -= amount
return True
This is correct, and for one class it is the right answer. The trouble grows with the system:
- Every access needs the lock. A new method that reads
balancewithout it reintroduces a race, and nothing warns you. - Operations across objects need several locks. A transfer locks two accounts, and two transfers in opposite directions can deadlock unless every caller takes the locks in the same order (see Deadlocks, Livelocks and Starvation).
- Slow work under a lock blocks everyone. If
withdrawalso called a fraud check over the network while holding the lock, every other caller would wait.
The actor model removes the shared part of "shared mutable state". Each account's balance is owned by one actor, and only that actor's code ever reads or writes it.