CSE Roadmap

Common tier · about 4 hours · 6 parts

Part 2 of 6 · 2 min read

Definitions and setup

Covers: Definitions; Why concurrent writers lose updates.

Definitions

Shared state, blackboard, message passing

  • Shared state: data that several agents can read and write.
  • Blackboard: shared state used as the main coordination surface, where agents post and read partial results.
  • Message passing: agents communicate by sending messages; no agent mutates another's state directly.

Lost update, last-writer-wins, race condition

  • Race condition: the outcome depends on the timing of concurrent operations.
  • Lost update: two concurrent read-modify-write operations; one write overwrites the other.
  • Last-writer-wins: the store keeps the most recent write and silently discards the rest.

Optimistic concurrency, compare-and-set, reducer

  • Optimistic concurrency: proceed without locking, and at write time check that nothing changed (a version number); if it did, redo the work.
  • Compare-and-set (CAS): write only if the current value or version matches what the writer read.
  • Reducer (merge function): a rule that combines concurrent updates, such as append to a list, add to a counter, or union of sets; it is safe when the operation is commutative and associative.

Delivery semantics, idempotency key, ordering

  • At-most-once: send once; a lost message is lost.
  • At-least-once: retry until acknowledged; messages may arrive more than once.
  • Idempotency key: a unique id the receiver remembers, so applying the same message twice has the effect of applying it once.
  • Ordering: sequence numbers let the receiver apply messages in the order they were sent even if they arrive out of order.

Why concurrent writers lose updates

AAAWgmp1bWIAAAAeanVtZGMycGEAEQAQgAAAqgA4m3EDYzJwYQAAABZcanVtYgAAAEdqdW1kYzJtYQARABCAAACqADibcQN1cm46YzJwYToxYmQ1ZmM1OS1iODQ5LTQ3ODMtYTFmZi0wZDI3ZDI4ZmI2OTcAAAADl2p1bWIAAAApanVtZGMyYXMAEQAQgAAAqgA4m3EDYzJwYS5hc3NlcnRpb25zAAAAALxqdW1iAAAARGp1bWRjYm9yABEAEIAAAKoAOJtxE2MycGEuaW5ncmVkaWVudC52MwAAAAAYYzJzaDEY/MKDwMj5GVPX1kPHjWUAAABwY2JvcqNpZGM6Zm9ybWF0bWltYWdlL3N2Zyt4bWxqaW5zdGFuY2VJRHgseG1wOmlpZDowZGRhNWExNC1lY2RiLTRlYjMtOTUwNy03ZjllNzAwYjJlYjBscmVsYX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][x, A][x, B] (A is lost)Three fixesOptimistic concurrencywrite only if the version is unchanged; otherwise re-read and redo the work. Correct, but each redo is a model call.Merge by operationsend 'append' or 'add' instead of a new value; the store merges them. No retries, but only for operations that commute.One writer per fieldgive each field an owner and let others send it messages. Removes the race by design.A contested decision (two agents both claim the same task) cannot be merged: it needs a rule, a priority or a person.
Two agents read the same list; the first write is lost. Three fixes below.

Three facts from the example:

  1. Overwrites lose data in proportion to concurrency. Lost items rose from 5 (two agents) to 14 (four), 24 (six) and 54 (twelve).
  2. The long "think" step is what makes it likely. The window between read and write is an LLM call, seconds long, not microseconds.
  3. Optimistic retries are expensive for agents. A conflict means redoing the model call that produced the update. Retries grew faster than the number of agents (6 at two agents, 83 at six, 327 at twelve).