Skip to content

Mutation

Mutations insert, update, and delete edges. The process ensures consistency, durability, and write-time optimization.

See Core Concepts for background.

flowchart TD
    Request([Mutation Request
with Event, Operation]) --> WAL[Write WAL] WAL --> Lock[Acquire Lock] Lock --> Read[Read State
from storage] Read --> Modify{State exists?} Modify -->|Yes| ApplyEvent[Apply Event] Modify -->|No| InitialState[Initial State] InitialState --> ApplyEvent ApplyEvent --> ComputeAdditionalInfo[Compute Index, Count
based on changed States] ComputeAdditionalInfo --> Write[Write State with AdditionalInfo
to storage] Write --> Release[Release Lock] Release --> CDC[Write CDC] CDC --> Response([Response])

A mutation request contains:

  • Event: The data change (e.g., new property values, edge creation)
  • Operation: Insert, Update, or Delete

Mutation is written to WAL before changes are made. Enables recovery and replay.

In production, Kafka is used as WAL backend.

Prevents concurrent modifications:

  • Unique edges: Lock on (source, target)
  • Multi edges: Lock on edge ID

Read current state from storage—properties, timestamps, metadata.

Transition state based on operation and client timestamp. See State Transitions for details.

Based on changed state:

  • Indexes: Delete old, create new
  • Counters: Increment or decrement

State, indexes, and counters written atomically.

Lock released after write.

Mutation recorded in CDC (Kafka in production). Resulting state available for downstream systems.

Edges transition between states based on operations (INSERT, DELETE). Each event carries a client timestamp, and Actionbase uses these timestamps to compute the correct final state—even for out-of-order arrivals and duplicate requests (idempotent).

See State.transit for implementation.

flowchart LR
    INITIAL[["INITIAL: No Edge"]]
    ACTIVE(["ACTIVE: Edge Exists"])
    INACTIVE["INACTIVE: Edge Deleted"]

    INITIAL -->|"INSERT / +1"| ACTIVE
    INACTIVE -->|"INSERT / +1"| ACTIVE
    ACTIVE -->|"DELETE / -1"| INACTIVE
Full state transition diagram

Full State Transition Diagram

Edit on PlantUML

Alice’s actions: like(t=100) → unlike(t=200) → like(t=300)

Events arrive out of order: like(t=100) → like(t=300) → unlike(t=200)

#Event ArrivesStateCount ChangeTotal
1like (t=100)INITIAL → ACTIVE+11
2like (t=300)ACTIVE → ACTIVE01
3unlike (t=200)ACTIVE → ACTIVE01

Final state: ACTIVE, count: 1 — same result regardless of arrival order.

During mutations, Actionbase pre-computes:

StructurePurposeQuery Type
EdgeStateCurrent edge stateGET
EdgeIndexSorted entriesSCAN
EdgeCounterAggregated countsCOUNT

Reads use simple GET, COUNT, SCAN without query-time computation.

MechanismGuarantee
LockingPrevents concurrent modifications
Atomic WritesState and indexes written together
WALDurability and recovery
Read-Modify-WriteMutations based on latest state
State TransitionsCorrect final state despite event arrival
IdempotencyReplay produces same result