When to reach for it
- Concurrency and isolation are critical.
- Agents possess their own internal state.
- Scaling should occur via independent units.
Each agent is its own mailbox, its own state, its own supervisor.
Agents or components run as independent actors: each owns its private state, processes one message at a time from its mailbox, and can spawn further actors — so there is no shared-memory contention and a crash is contained to a single actor.
In practiceA high-throughput document-processing system assigns each uploaded file to an independent actor, so a crash in one file's processing actor never affects the others running in parallel.
Each actor has its own state and a mailbox. It takes one message at a time, and the only way to affect another actor is to send it a message.
1 · One actor
2 · Many actors
| Actor | Mailbox | What happens | Outcome |
|---|---|---|---|
| File 1 | parse, summarise | Handles both messages in order | Summary delivered |
| File 2 | parse, summarise | Crashes while parsing | Reported as unreadable |
| File 3 | parse, summarise | Handles both messages in order | Summary delivered |
| File 4 | parse, summarise | Handles both messages in order | Summary delivered |
import asyncio
class FileActor:
def __init__(self, name):
# private state
self.name, self.mailbox, self.pages = name, asyncio.Queue(), None
async def run(self, supervisor):
try:
while True:
message = await self.mailbox.get() # one message at a time
if message == "parse":
self.pages = parse(self.name)
elif message == "summarise":
await supervisor.put((self.name, summarise(self.pages)))
except Exception as error: # the crash stays inside this actor
await supervisor.put((self.name, f"failed: {error}"))When to reach for it
When it backfires
An actor crashes between receive and ack. The message vanishes; the sender thinks it was processed; the system silently loses work.
Countermeasure
Use at-least-once delivery with idempotent handlers, or persist the inbox before processing. Make message loss a visible failure, not a silent one.
One actor consumes messages slower than they arrive. Its mailbox swells until memory is exhausted, and the backlog latency cascades to everyone waiting on its replies.
Countermeasure
Bound mailboxes and apply backpressure or load-shedding when full; monitor queue depth per actor and scale or shed before it becomes an outage.
Keep going
Search patterns, frameworks, and pages.