Consensus - ljcom/operadb GitHub Wiki

🧭 Consensus in OperaDB

OperaDB uses an event-driven architecture, and in its current form, runs as a single-node system. However, for multi-node or distributed deployments, a lightweight consensus mechanism becomes important to ensure consistency and trust across nodes.


🧠 Philosophy of Consensus in OperaDB

OperaDB treats events as the source of truth. All state is derived by replaying events using deterministic reducers. Therefore, the key requirement for consensus is:

  • Ensuring event order and content are identical across all nodes.
  • Ensuring all reducers compute the same state from the same ordered events.

⚙️ Proposed Consensus Workflow

✅ Event-Hash Agreement

  1. Each node receives an event and computes:

    eventHash = hash(prevEventHash + currentEvent)
    
  2. Nodes broadcast their computed hash to peers.

  3. If 2/3 of nodes agree on the hash:

    • The event is committed to the chain
    • Reducers run and state is updated
  4. If disagreement occurs:

    • Event is rejected or delayed
    • Nodes may re-sync or trigger rollback

🌀 Alternative: Epoch-Based Quorum (Optional)

OperaDB may implement an epoch + voting system in the future:

  • Events are grouped into batches (epochs)
  • Nodes vote to commit or reject batches
  • Majority (e.g., 2/3) required to reach consensus

🔐 Key Principles

Concept Description
Deterministic Reducers All nodes must produce the same output from the same input
Event Hashing Events are linked via cryptographic hashes
No Global Clock Consensus uses event ordering, not timestamps
Quorum Agreement Decisions are based on 2/3 agreement

📌 Comparison vs. Blockchain Consensus

Feature OperaDB Blockchain (e.g., Ethereum)
Consensus Type Lightweight hash-voting Proof of Work / Stake
Target Use Case Business workflow DB Trustless global ledger
Reducer Output Deterministic state Irreversible block state
Performance High (single writer) Lower (due to mining/fees)

🚧 Current Status

Feature Status
Single-node replay ✅ Implemented
Multi-node replay ⚠️ Planned
Hash-based voting 🔄 Experimental
Byzantine Tolerance ❌ Not supported

OperaDB aims to remain lightweight but optionally support distributed consensus in clustered or decentralized environments.