Distributed DB
Distributed Transactions Head to Head: Raft State Machine Replication vs. Spanner TrueTime
A deep dive into the core algorithms modern distributed relational databases such as Google Spanner, TiDB and CockroachDB use for multi-region, multi-replica transactions, comparing what Raft lease reads, Multi-Paxos and the TrueTime API each pay in clock-wait cost to guarantee external consistency (linearizability).
#ACID
#Distributed Database
#Go
hybrid_logical_clock.gogo
package consensus
import (
"sync"
"time"
)
// Hybrid logical clock: physical time combined with Lamport causal ordering
type HybridLogicalClock struct {
mu sync.Mutex
l int64 // Physical time, high bits (milliseconds)
c int32 // Logical counter
}
func (h *HybridLogicalClock) Now() (physical int64, logical int32) {
h.mu.Lock()
defer h.mu.Unlock()
pt := time.Now().UnixMilli()
if pt >