Skip to content
Design10 min readUpdated 27 Oct 2026

Appendix E. Primers

These primers give the background of Section 3 with worked examples, for readers who want it in one place. Appendix D says what to read next.

E.1 Hypergraphs and their incidence graphs#

Take a session among a client c, a server s and an auditor a (Figure 3).

  • As a hyperedge it is one element e with three incidences: (e,c,𝖼𝗅𝗂𝖾𝗇𝗍,0), (e,s,𝗌𝖾𝗋𝗏𝖾𝗋,0) and (e,a,𝖺𝗎𝖽𝗂𝗍𝗈𝗋,0).

  • As a graph it would be a clique of three binary edges, c–s, s–a and a–c. The clique loses two facts: that the edges are one session, and which participant plays which role.

  • In general, a hyperedge with k participants costs k incidences, while a clique costs k(k−1)/2 edges and loses the hyperedge’s identity.

The incidence graph is bipartite. Its node sorts are elements {c,s,a} and hyperedges {e}, with one edge per incidence. Kernels store this form, and graph algorithms run on it.

Network measures transfer directly:

  • an element’s degree is its number of incidences;

  • betweenness centrality estimates how much dependency or traffic passes through an element, a proxy for blast radius;

  • a sparse cut between communities is a candidate boundary for a region [265].

In a multilayer network each layer is a subgraph over a shared vertex set, with edges between layers [197]. In RG, connections stay within a layer, and assertions play the inter-layer role.

E.2 Categories in four steps#

Categories and functors#

A category has objects and arrows, an identity arrow on each object, and an associative composition of arrows. Sets and functions form the category 𝖲𝖾𝗍. Any partial order is a category with at most one arrow between two objects. A functor maps objects to objects and arrows to arrows, preserving identities and composition [221].

C-sets#

Directed graphs are the C-sets on the category E⇉V, whose two arrows are s and t. An instance chooses sets and functions. For example, V={1,2,3} and E={a,b}, with s(a)=1,t(a)=2,s(b)=2,t(b)=3. A morphism of graphs is a pair of functions (fE,fV) that commutes with s and t, which is a natural transformation. The Reaktor schema (Figure 6) has more objects and arrows, but the principle is the same [280].

Gluing and rewriting#

Let two scopes G and H share a boundary port p, given by monomorphisms {p}→G and {p}→H. Their pushout G+{p}H is their disjoint union with the two copies of p identified.

A DPO rule that adds an interceptor to a call has three parts:

  • L contains the session hyperedge e and the interceptor’s port q;

  • K=L;

  • R is L plus the incidence (e,q,𝗂𝗇𝗍𝖾𝗋𝖼𝖾𝗉𝗍𝗈𝗋,0).

Applying it deletes nothing and glues one incidence.

A rule that deletes a node n has L={n} and K=R=∅. The dangling condition forbids applying it while n still owns ports. The rule must delete those ports and their incidences explicitly, which is why RG never leaves a dangling reference.

In an adhesive category, such as any category of C-sets, pushouts along monomorphisms behave like unions of sets [210]. That is what makes independent rules commute (Theorem 10).

Open systems#

A cospan J→G←K is G with an input boundary J and an output boundary K. Two cospans compose by pushout over the shared boundary (Figure 11). A hypergraph category adds the ability to split and merge wires, governed by the special Frobenius laws. This is exactly what a net does when it joins several ports [136]. Free hypergraph categories correspond to cospans of hypergraphs [35], which is the content of Theorem 3(a).

E.3 Fixpoints, semirings, Datalog and incrementality#

Dependency resolution as a lattice#

For each consumer port, take values in the flat lattice {⊥}∪𝑃𝑟𝑜𝑣𝑖𝑑𝑒𝑟𝑠∪{⊤}:

  • ⊥ means no candidate yet;

  • ⊤ means ambiguous;

  • joining two different providers gives ⊤.

A message along a Bind from provider p is p. Shadowing, where an inner scope hides the providers of outer ones, is not monotone, so it is computed first, in its own stratum: for each consumer, the nearest enclosing scope that offers the contract. The candidates in that scope are then joined. Within each stratum every function is monotone, so the least fixpoint exists and does not depend on order (Theorem 6). At the fixpoint each consumer holds one provider, ⊥ (a missing-provider finding) or ⊤ (an ambiguity finding with both witnesses) [82, 266].

Path problems#

With the Boolean semiring (∨, ∧), path problems compute reachability, for example routes reachable from the root. With max-plus (max, +), they compute the worst-case latency of a call chain from per-hop budgets. With max-min, they compute bottleneck capacity [250].

Datalog#

Reachability in Datalog is 𝑟𝑒𝑎𝑐ℎ(x,y)←𝑒𝑑𝑔𝑒(x,y).𝑟𝑒𝑎𝑐ℎ(x,z)←𝑟𝑒𝑎𝑐ℎ(x,y),𝑒𝑑𝑔𝑒(y,z). Bottom-up evaluation computes the least model. “Unreachable” needs negation, 𝑢𝑛𝑟𝑒𝑎𝑐ℎ𝑎𝑏𝑙𝑒(r)←𝑟𝑜𝑢𝑡𝑒(r),¬𝑟𝑒𝑎𝑐ℎ(𝑟𝑜𝑜𝑡,r). It is evaluated in a higher stratum, after 𝑟𝑒𝑎𝑐ℎ is complete [4].

Incrementality#

Inserting an edge (u,v) adds only pairs derived through it; semi-naive evaluation joins the delta, not the whole relation. Deletion is harder, because a pair may have other derivations. Z-sets (signed multisets) and DBSP’s integration and differentiation operators handle both directions uniformly, at a cost proportional to the change for linear operators [46].

Coordination#

Reachability is monotone: adding facts only adds conclusions, so the partitions of a graph can compute it without coordinating. “No path exists” is not monotone, and its answer is trustworthy only on a consistent cut [56, 167]. RG labels each traversal as one kind or the other (Proposition 8).

E.4 TLA+ from zero#

A TLA+ specification declares variables, an initial predicate Init and a next-state action Next, and combines them as Spec == Init /\ [][Next]_vars.

  • Actions. An action relates the current values of variables (unprimed) to their next values (primed). UNCHANGED lists the variables an action leaves alone.

  • Invariants. An invariant is a state predicate. TLC evaluates it in every reachable state of a bounded instance and returns a shortest counterexample when it fails [214].

  • Liveness. Properties of the form “eventually” need fairness conditions such as WF_vars(Reply).

Reading Listing 25#

Each action models one event:

  • Send: the client sends or retries;

  • Serve: the server applies the effect, or recognises its identity and does not apply it again;

  • DropRequest, DropReply and Duplicate: the network misbehaves;

  • Reply: the client learns the outcome;

  • GiveUp: the client stops after its retries.

The counterexample without deduplication has four steps: send, serve, retry, serve. The other counterexample serves the request, loses the reply, loses two retries and gives up. If the client then concludes “not applied”, it is wrong.

Refinement#

An abstract specification, “the effect is applied at most once and reported truthfully”, is refined by the protocol under a refinement mapping. Here the mapping sends the protocol’s applied and verdict to the abstract ones [1].

What checking proves#

Model checking proves a property for every behaviour within the bounds and nothing beyond them; proofs extend claims to all sizes [24, 85]. RG uses both: bounded checks for protocols, and proofs for the kernel’s metatheory (Section 15).

E.5 Machines and data-oriented design#

Table 37 gives orders of magnitude [86, 168]. Exact figures vary by hardware and region. The ratios are what matter for design.

Table 37. Orders of magnitude that shape placement and layout.
Operation Order of magnitude
Cache hit (first level) ∼1 ns
Main memory access ∼100 ns
Call across a native boundary (JNI, JSI, C ABI) 10 ns – 1 μs
Random read from solid-state storage ∼100 μs
Round trip within a datacenter or region ∼0.5–1 ms
Durable commit to a replicated store ∼1–10 ms
Round trip across continents ∼100 ms

Layout#

Consider scanning all ports of one family:

  • Array of structures. Ports stored as objects, each with an owner, a family and a role, sit wherever the allocator put them. The scan touches every object header and every field.

  • Structure of arrays. Stored as three integer arrays, the same scan reads one contiguous array of four-byte entries, sixteen per cache line, and lets the hardware prefetch [100, 130].

In compressed sparse row form, the incidences of hyperedge i are 𝑒𝑛𝑑𝑠[𝑜𝑓𝑓𝑠𝑒𝑡𝑠[i]..𝑜𝑓𝑓𝑠𝑒𝑡𝑠[i+1]). For three hyperedges with two, three and one participants, 𝑜𝑓𝑓𝑠𝑒𝑡𝑠=[0,2,5,6].

A worked example#

Count the cache lines that one scan of a million ports touches.

  • Objects. On the JVM, a port object with a header, an owner reference, a family, a role, a contract reference and padding takes about 48 bytes, and the objects may be scattered. Reading every port’s family touches up to a million cache lines of 64 bytes, and each miss to main memory costs about 100 ns (Table 37).

  • Columns. The family column holds one byte per port, so the same scan reads 15,625 consecutive cache lines, about a megabyte, which the hardware prefetches.

The second scan touches 64 times fewer lines and no pointers. The same arithmetic explains the kernel’s other choices (Section 11): hot columns apart from cold ones, integer codes instead of strings, pre-order intervals instead of parent walks, and one array instead of a map from ports to incidences.

Batches#

Data-oriented code processes many rows per call. A traversal pass applies one message function to a whole CSR segment, and a patch is applied table by table, not element by element. Batches amortise dispatch, keep loops free of virtual calls, and let compilers vectorise. The same holds across runtimes: one FFI call that hands over a column slice costs about as much as one that hands over a single value.

Handles#

A generational handle (slot, generation) detects reuse: freeing a slot increments its generation, so a stale handle no longer matches. In JavaScript engines, including Hermes, typed arrays give the same layout and avoid per-element objects and collection pauses.

Across runtimes#

Table 37 explains why placement dominates. Co-locating two components that exchange many small messages turns milliseconds into nanoseconds. Batching amortizes per-call costs. Chattiness across a boundary that the code made invisible is a classic performance defect of distributed systems, which is why Bind never crosses a place.

E.6 Distributed systems, from failure to fencing#

Failure model#

Processes crash and restart. Messages are delayed, lost, duplicated or reordered, and clocks drift [48]. A timeout cannot tell a slow peer from a dead one, so after a timeout the effect of a call is unknown; Outcome has UNKNOWN for exactly this reason.

Idempotency#

The caller chooses an effect identity. The authority that commits the effect records the identity in the same transaction, and answers a repeat with the stored outcome. Binding the identity to a digest of the request also catches a different request reusing the identity (Section 7) [166].

Leases and fencing#

Suppose process A holds a lease with epoch 7 and pauses, for instance for garbage collection. The lease expires and B acquires epoch 8. When A wakes it writes with epoch 7. Only the store can stop that write, by rejecting any epoch below the highest it has seen [199] (Figure 4). This is the counterexample of Table 9, and the reason atomic(store) checks epochs inside the store’s transaction.

Spanning services#

Write the effect and an outbox record in one local transaction; a relay publishes the record after commit; consumers deduplicate by identity. A multi-step business process is a saga: each step has a compensation, and isolation, where it is needed, comes from reservations rather than locks [140].

Convergence without coordination#

State whose merge is a join, such as grow-only sets, counters and last-writer-wins registers with logical timestamps, converges without coordination. These are CRDTs [310], and CALM says when an entire program can work this way.

Placement and data gravity#

Put computation near the data it touches most, and keyed state near the users who share the key. A solver can weigh these against cost and capacity. Its constraints are the hard requirements of Section 6.6, and its output is a patch that admission checks.