Event-State Duality
Event-state duality is a modeling principle and an instance of duality and symmetry: the relationship between two views of behavior:
- Events emphasize occurrence, ordering, causality, and change.
- States emphasize information, condition, continuity, and samples or cuts through behavior.
The event-state duality relates the semantic constructs event and state, and constrains how the model explains their correspondence.
The principle takes a symmetric view: neither events nor states are primary, and each can be defined in terms of the other. A process can be described as a state-based automaton, which waits in states and moves by transitions, or as an event-based schedule, which is a set of occurrences with order constraints among them. The two views are structurally different, but taken as wholes each determines the other.
That exact correspondence holds for occurrence structure: which events have occurred in which states. Domain events carry more than occurrence. They carry intent, payload, source, and causation that a state does not retain, and different event histories can converge to the same state. The relationship between domain events and state is therefore an operational interpretation layered on the duality, not the duality itself.
Elements and Predicates
The duality rests on element-predicate duality, a relationship familiar from programming: a predicate over a type picks out elements of that type. A Predicate<T>, a function T -> Bool, determines a subset of a collection, and with enough predicates it can single out an individual item.
The relationship reads in both directions. A predicate is a function on elements, and an element is equally a function on predicates: the one that evaluates each predicate at that element.
This is the perspective of the Yoneda lemma in miniature: an element can be characterized by how it answers the predicates that observe it.
Event-state duality applies this relationship to behavior.
- In a schedule, events are the elements and states are the predicates. A state is a predicate over events that answers, for each event, whether it has occurred.
- In an automaton, states are the elements and events are the predicates. An event is a predicate over states that answers, for each state, whether the event has occurred by then.
Both views are one table read in two directions, with states as rows and events as columns:
Reading across a row gives a state as a predicate on events. Reading down a column gives an event as a predicate on states. Transposing the table exchanges elements and predicates without adding or losing anything, which is the sense in which each view fully determines the other. Pratt formalizes such a table as a Chu space; the formal apparatus is not needed to apply the principle.
Not every predicate is admitted. The structure of a schedule is expressed by which predicates count as states. If must precede , no admitted state has occurred while has not. If and are unordered, states in which either has occurred without the other are both admitted. Order constraints among events are therefore constraints on the admitted states, and the reverse holds for an automaton.
Beyond Bool
Predicates need not be Boolean. Replacing with a richer set of values extends the same duality:
Pratt's enriched case develops this generalization, under which the relations between events and between states become the measures of time and information described below. Both measures are Lawvere distances, the motivating example of enrichment.
A richer distinguishes event histories that a simpler collapses. Pratt illustrates the point with four choices of , whose values are read as the adverbs before (), during (), after (), and instead (, canceled):
- With , concurrency and interleaving collapse. The concurrent schedule and the choice between then or then admit the same four states: neither, only, only, both.
- Adding separates them. admits a state in which and are both in progress, and no interleaving does.
- Adding separates when a choice is made. With , and both admit the same states: nothing, done, and done, and done. With , the process has a state after in which and both remain possible, while in every state after has already canceled one of them, because the choice was made before .
Making both distinctions requires both additional values.
An event-sourced entity uses only the first of these choices. Its recorded schedule never contains a value, because serialization turns concurrent inputs into then or then . It never contains either, because a rejected or failed command produces no event: the log records what occurred and nothing about what was canceled instead. The table is Boolean and linear, a staircase in which event has occurred in state exactly when .
Sequence numbers are the coordinates of that staircase. For a sequential entity whose version is produced by the event at position , comparing an event position with a state version answers whether the event occurred before, at, or after the state:
Event position and state version coincide, and the duality is nearly trivial. The richer values belong to the input schedule and the system history, where they do occur. Two commands decided against the same version are concurrent. Optimistic concurrency commits one and rejects the other, a conflict resolved by cancellation, and the event-sourced log records only the winner. Process histories in durable execution and sagas, by contrast, commonly record that work was scheduled, started, completed, failed, or canceled, and so keep a richer explicitly.
Time and Information
The two sides of the duality carry different measures.
- Time relates events to one another. In its simplest form it asks whether one event must precede another, as happened-before does. In richer forms it asks how much time must separate them.
- Information relates states to one another. In its simplest form it asks whether one state extends another: whether everything that has occurred in has also occurred in . In richer forms it asks how much more is known in than in .
States bear information and change time: while behavior waits in a state, what is known stays fixed and time passes. Events bear time and change information: an event marks a moment and changes what is known. Pratt states the intuition this way:
The behavior of an automaton is to alternately wait in a state and perform a transition or event. We may think of the state as bearing information representing the “knowledge” of the automaton when in that state, and the event as modifying that information. At the same time we may think of the event as taking place at a moment in time, and the state as modifying or whiling away time.
Treated as Lawvere distances, time and information compose along paths: the time from to is bounded by the time from to plus the time from to , and the minimal time between every pair of events can be computed from direct constraints by the Floyd-Warshall algorithm, which is matrix multiplication with for addition and for multiplication. Casley, Crew, Meseguer, and Pratt develop this view of schedules as enriched structures in Temporal Structures. Time develops the event-side measure, including logical clocks, vector clocks, and wall-clock time.
Measures Induced by the Table
Time and information need not be specified separately. Once carries the structure of a quantale, both are induced by the table. To compare two columns, compare them position by position with the implication of , then combine the results with its composition. In the Boolean case, state is below state exactly when every event that has occurred in has also occurred in :
Comparing rows in the same way gives the order of events: precedes when every state in which has occurred is also one in which has occurred.
A theorem of Plotkin, reported by Pratt, shows that nothing is lost by deriving the measures this way. For any quantale , processes whose events and states carry -enriched structure form a category isomorphic to the plain tables over the values of , when both are restricted to tables without repeated rows or columns:
The enrichment of events and states adds nothing that the table does not already determine. Changing the structure on changes the induced distances, but not which maps exist between processes. Pratt calls the resulting method light enrichment: start from the table over , give a structure, and read time from the rows and information from the columns. He adopts it even when is not a quantale, leaving open when the two methods disagree.
Branching and Concurrency
The two views branch differently.
- In an automaton, branching is disjunctive. A state with several outgoing transitions admits alternatives, and a run takes one of them. This is choice.
- In a schedule, branching is conjunctive. Events with no established order between them all occur. This is concurrency, made explicit in process structures by fork and join.
Each kind of branching appears in the other view in dual form. Concurrent events and in a schedule appear in the automaton as a diamond of states (before both, after only, after only, after both) whose two paths are both admissible and converge. Alternatives in an automaton appear in the schedule as events in conflict: events that never occur together in any state.
From Sequential to Concurrent: Children and Ponies
Pratt gives an example that shows the passage from sequential to concurrent behavior. Three children, , , and , each take one ride, and ponies are available. Take , so that each child has not yet ridden, is riding, or has finished. The possible states are the vectors over , and they form a cube: 8 vertices in which no child is riding, 12 edges in which one is, 6 faces in which two are, and 1 interior cell in which all three are.
A step may advance any number of children by one value, from to or from to . Time is the length of the shortest path of steps, less one. Writing for :
With three ponies all children ride at once, the fully concurrent case. Two ponies remove the interior cell, and the path must go around it. One pony removes every state in which two children ride together, leaving the vertices and edges of the cube, and the path runs along the edges: the fully sequential case.
The events are the same in all three cases, and no order among them is specified. What changes is which states are admitted, and the time measure induced by the admitted states moves from parallel to sequential. Excluded states act as holes in the state space, as in Papadimitriou's geometric view of concurrency control, in which mutual exclusion is a hole that every path must go around. The ponies play the role of a shared resource with a fixed number of permits, such as a semaphore, a worker pool, or a rate limit, which bounds how much of the available concurrency a scheduler can use.
The example also shows why is needed. With the three cases admit the same eight states, and counting the events that change between and gives 3 in every case. A Boolean table cannot see the difference between riding together and taking turns.
Input and Recorded Schedules
The event side of an entity's behavior involves two schedules, with a serialization point between them.
- The input schedule consists of exogenous events such as commands, messages, and signals. Input events can be concurrent: their schedule is a partial order in which some pairs are unordered.
- A serialization point, such as an inbox, an actor mailbox, a lock, or an expected-version check, selects an order in which inputs are applied.
- The recorded schedule consists of endogenous events. Each is produced by a transition applied to the current version, so for a sequential entity the recorded schedule is linear by construction.
For a sequential entity, the recorded history is a chain of state actions:
State at version is the result of applying the endogenous event that produced version . An event-sourced log is this recorded schedule. It is a linearization of the input schedule, not a record of it.
What Serialization Loses
A linear recorded schedule cannot distinguish an order that causality required from an order the serialization point chose. Two commands decided independently and one command that reacted to another look the same once both are in the log. For a sequential entity, the concurrency structure of the duality survives only in the input schedule, and serialization discards it unless it is recorded separately.
Serialization Need Not Be the Case
Serialization is a choice made for an invariant or an authority, not a requirement of automata. It is needed when concurrent inputs do not commute and an invariant scope requires one authoritative order. Otherwise it is a realization choice, and the following alternatives preserve progressively more concurrency.
- Serialize while recording dependencies. Each input records what it observed: an expected version, a causal context, or a vector clock. The recorded schedule is then a linear order together with an independence relation, so the concurrency can be recovered. An expected-version check already records part of this, since a command decided against version declares its dependency on .
- Apply independent or commuting inputs without ordering. When the state actions of and commute, or touch disjoint parts of the state as in partition models, every order yields the same result and none needs to be chosen.
- Treat state as the set of what has occurred. In state-based CRDTs and other monotone designs, a state is a set of events or a join of their effects, and merging takes the union. This is the schedule view made literal, with each state the predicate of which events have occurred: information only grows. The CALM theorem marks the limit, since non-monotone decisions require coordination.
- Keep non-linear histories. A system such as Git applies branches separately and merges them later. The state history is a directed acyclic graph that keeps the diamond and closes it with a merge rather than flattening it in advance. Concurrency control must match the history shape. A linear entity can use expected-version checks to ensure one successor from a current version. A non-sequential history may instead ask whether proposed successors have acceptable parents, whether references may advance, and whether concurrent heads should be rejected, merged, or preserved.
- Represent concurrency in the automaton itself. Higher-dimensional automata include states in which several events are in progress at once, so concurrency is not reduced to interleaving even within a single run.
System State
State need not mean the state of one entity. System state, the combined state of many entities, components, or observers, is the state view of an event history that is generally not sequential. User interactions with an interface, for example, occur across sessions, devices, and components. They can be recorded in a history, but that history is a partial order rather than a sequence, and nothing requires a single serialization point.
For such a history, a system state is a consistent cut: a set of events closed under happened-before, so that whenever it contains an event it also contains every event that event depends on. Consistent cuts are the rows of the table for a concurrent schedule. Entity state is the special case in which the entity's events are totally ordered and every cut is a prefix. A snapshot, a projection, or an observer's view selects one such cut, and different observers may select different cuts of the same history.
Process Algebra
Pratt defines process composition directly on the table. A process is a set of events together with its admitted states, and each operator builds the event set and admitted states of a composite from those of its parts. Write and , and say that a process has terminated in a state when each of its events is either done () or canceled ().
| Operator | Events | Admitted states | Time combines by |
|---|---|---|---|
| Concurrence | states whose restriction to is admitted by and whose restriction to is admitted by | ||
| Sequence | as for concurrence, and in every state either has not started or has terminated | ||
| Choice | the initial state, then states that progress in one of or while the other's events are canceled | ||
| Orthocurrence | tables in which is a state of for each , and is a state of for each |
Concurrence is conjunction of constraints: each part keeps its own constraints and nothing relates them. Sequence adds the constraint that waits for to terminate. Choice needs , because the unchosen branch is canceled rather than merely not yet started. Orthocurrence has no common counterpart among standard process operators: every event of one process meets every event of the other.
The time measures combine as the operators suggest. Concurrent parts and alternatives take the time of the slower one, ; sequential parts add, . In the Boolean case, where time is reachability, all three combine by conjunction.
Pratt ends by noting a tension. Time computed this way, by induction on the structure of a process term, depends only on the endpoints of each part and mixes several measures. The global measure, the shortest path through the admitted states, also sees holes such as those in the children and ponies example, where removed states force a longer route. Compositional estimates and global measures can therefore disagree, and reconciling them remains open.
Process Calculi relates this algebra to CCS, CSP, and the π-calculus, where the choice of corresponds to the choice of behavioral equivalence.
States, Events, and Predicates
Event-state duality is one side of a triangle. Element-predicate duality also relates states to the predicates they satisfy, studied as invariants and assertions, and events to predicates, studied as predicate transformers and trace properties. State space is the domain of state machines, event space the domain of processes, and predicate space the domain of assurance. Each side is a table of the kind described above, and each benefits from a richer than Boolean truth values.
Duality and Operational Interpretation
The element-predicate table relates bare occurrences: an event is identified only by which states it separates. Under that reading, the events between two states are recoverable as the difference of their rows, which is why the duality loses nothing in either direction.
Domain events are occurrences that carry values. The state action interprets such events as functions on state. Folding events into state through this action is the common operational direction:
The reverse direction is not ordinarily used to obtain domain events. Comparing states can reveal that something changed, but not the intent, source, or causation that the domain event carried:
Change data capture is an instance of this reverse direction. It derives change events that describe differences in stored data, not the domain events that caused them. Both transforms are model-dependent. They depend on the observer, boundary, accumulation or detection function, available observations, and the semantic purpose of the model.
Philosophical Parallel
Hegel's distinction between being and becoming provides a useful conceptual parallel. State corresponds loosely to determinate being: what is, relative to a subject, boundary, shape, and point in behavior. Event, transition, and behavior correspond to becoming: occurrence, change, and the movement by which states become determinate. Pratt draws a parallel of the same kind with the symmetric treatment of matter and mind, in which neither side is reduced to the other.
The parallel is not a formal identification. In the Cohesive model, state and event remain semantic constructs with observer-relative roles. The useful point is that state is not intelligible apart from the behavior and event histories through which it is determined, while events are not intelligible apart from the states they affect, reveal, or relate.
This also suggests a notion of indeterminate state. An indeterminate state is not necessarily the absence of state. It is a recognized subject, possibility, external process, or pending situation whose relevant dimensions are not yet determined relative to an observer, boundary, shape, or version. Indeterminacy may be epistemic, shape-relative, operational, semantic, or external. State becomes determinate for the model through observation, event interpretation, or a commitment boundary.
Formal relations
refines: Element-Predicate Duality — Is the case of element-predicate duality in which events are elements and states are predicates, or, transposed, states are elements and events are predicates.refines: Duality and Symmetry — Instantiates the broader duality principle through the occurrence correspondence between event schedules and state histories, with accumulation and difference as model-dependent operational interpretations.
External References
- G. W. F. Hegel, Book I of Science of Logic: Being.
- F. W. Lawvere, Some Thoughts on the Future of Category Theory, 1991.
- Ross Casley, Roger F. Crew, José Meseguer, and Vaughan R. Pratt, Temporal Structures, Category Theory and Computer Science, LNCS 389, 1989.
- Vaughan R. Pratt, The Duality of Time and Information, CONCUR 1992, LNCS 630, 237-253.
- Vaughan R. Pratt, Event-State Duality: The Enriched Case, CONCUR 2002. Springer entry
- Vaughan R. Pratt, Transition and Cancellation in Concurrency and Branching Time, Mathematical Structures in Computer Science 13(4):485-529, 2003.