Skip to content
LinkState
Go back

Leases, quorums, and fencing for source of truth

Introduction to Source-of-Truth Designs

Source-of-truth (SoT) designs are essential for network automation systems that cannot tolerate stale reads turning into overlapping writes. Three primary approaches—single‑writer, lease‑based, and quorum‑backed—provide different trade‑offs in consistency, availability, and complexity.

Preventing stale reads (reading outdated data) and overlapping writes (concurrent conflicting updates) is critical; failures can cause inconsistent configurations, incorrect automation decisions, network downtime, or security breaches.


Single‑Writer Source‑of‑Truth Design

Architecture

Advantages & Disadvantages

AdvantagesDisadvantages
Simple to understand and implementSingle point of failure
Low overhead (no coordination protocol)Primary node can become a bottleneck
Easy to reason about consistencyLimited horizontal scalability

Implementation Example (Python)

import threading

class SingleWriterSoT:
    def __init__(self):
        self._data = {}
        self._lock = threading.Lock()

    def write(self, key, value):
        with self._lock:
            self._data[key] = value

    def read(self, key):
        with self._lock:
            return self._data.get(key)

# Primary node instance
primary = SingleWriterSoT()

def secondary_read(key):
    return primary.read(key)

Common Issues & Troubleshooting


Lease‑Based Source‑of‑Truth Design

Lease Mechanism

A node acquires a lease granting it exclusive write rights for a limited time. The lease must be renewed before expiry; otherwise, another node may seize the lease and become the writer.

Advantages & Disadvantages

AdvantagesDisadvantages
Better availability – writer can migrate on failureAdded complexity for lease management
More scalable than a single writerRisk of lease expiration collisions if clocks drift
No single point of failure (as long as lease service is reliable)Requires reliable lease service (e.g., etcd, Consul)

Example CLI Commands

# Acquire a lease for key "my_key" lasting 30 seconds
lease acquire --key my_key --duration 30s

# Renew the lease before it expires
lease renew --key my_key

# Release the lease explicitly (optional)
lease release --key my_key

Scaling Limitations & Bottlenecks


Quorum‑Backed Source‑of‑Truth Design

Distributed Consensus & Quorum

Consensus algorithms (Raft, Paxos) ensure that a majority (quorum) of nodes agree on each state transition. A write is committed only after a quorum persists the entry; reads can be served from any node that has the latest committed entry (or via read‑index for linearizable reads).

Advantages & Disadvantages

AdvantagesDisadvantages
High availability – tolerates up to ⌊(N‑1)/2⌋ node failuresIncreased algorithmic complexity
Strong consistency – all nodes see the same committed orderHigher latency due to round‑trip quorum communication
Automatic leader election and failure recoveryOperational overhead (monitoring, log management)

Implementation Example (Go, using HashiCorp Raft)

package main

import (
    "github.com/hashicorp/raft"
    "github.com/hashicorp/raft-boltdb"
)

func main() {
    config := raft.DefaultConfig()
    config.LocalID = raft.ServerID("node1")

    // Storage layer (boltdb for logs & stable store)
    logStore := raftboltdb.NewBoltStore("raft-log.db")
    stableStore := raftboltdb.NewBoltStore("raft-stable.db")
    snapshotStore, _ := raft.NewFileSnapshotStore("snapshots", 2, nil)

    // Transport (TCP)
    transport, _ := raft.NewTCPTransport("127.0.0.1:8081", nil, 3, 10*time.Second, os.Stderr)

    ra, err := raft.NewRaft(config, (*fsm)(nil), logStore, stableStore, snapshotStore, transport)
    if err != nil {
        panic(err)
    }

    // Bootstrap cluster (single node for demo)
    configuration := raft.Configuration{
        Servers: []raft.Server{
            {ID: config.LocalID, Address: transport.LocalAddr()},
        },
    }
    ra.BootstrapCluster(configuration)

    // ... apply commands via ra.Apply(...) ...
}

Handling Quorum Failures & Network Partitions


Comparison of Source‑of‑Truth Designs

AspectSingle‑WriterLease‑BasedQuorum‑Backed
PerformanceLow latency (single node)Moderate (lease service overhead)Higher latency (quorum round‑trip)
ScalabilityLimited by primaryBetter; scales with lease serviceScales with cluster size, but network cost grows
Fault ToleranceSingle point of failureTolerates writer failure via lease migrationTolerates up to ⌊(N‑1)/2⌋ failures
ConsistencyStrong (if sync is reliable)Strong while lease holder is validStrong (linearizable)
Operational ComplexityLowMedium (lease management)High (consensus ops, monitoring)

Fault Tolerance & Availability

Operational Complexity & Management Overhead


Troubleshooting & Debugging Techniques

Identifying & Resolving Stale Reads

Detecting & Preventing Overlapping Writes

Tools & Methodologies


Scaling & Performance Optimization

Horizontal Scaling & Load Balancing

Caching & Data Locality

Optimizing Network Communication & Latency


Security Considerations & Best Practices

Authentication, Authorization, & Access Control

Data Encryption & Integrity Protection

Secure Deployment & Management


Real‑World Use Cases & Case Studies

Network Automation Systems

Lessons Learned & Best Practices


End of document.


Share this post on:

Previous Post
AI-assisted triage for partial EVPN inconsistency
Next Post
Headless services, StatefulSets, and SANs that no longer match