1:1 mentoring with Big Tech AI engineers
Q28Premium

Two sessions update the same memory at once. How do you keep state consistent?

Memory & State

State ManagementConcurrencyMemoryArchitecture

Asked at Amazon · Microsoft · Databricks

How to Answer

“There are two different problems hiding in that question.

If it’s two sessions of the same user — a phone and a laptop — it’s ordinary database concurrency and I’d treat it as such. Version every memory row, compare-and-set on update, and on conflict re-read and re-apply rather than overwrite. Last-write-wins is fine for a preference and catastrophic for a running total.

If it’s two agents writing shared state in a multi-agent system, the real answer is usually don’t. Shared mutable state between agents is what makes those systems impossible to debug. Give each agent its own scratch state, and have exactly one writer for anything shared — a coordinator, or an append-only log the others read.

And there’s a wrinkle specific to agents: a long run reads state at step one and acts at step seven. Whatever it read may be stale by then. So for anything that matters, re-validate at the point of action, not at the point of planning.”

The deep dive — diagrams, tradeoff tables, and the follow-up trap

Loading…