title: CloudSlash - BadgerDB Time Layer Reference description: 10 million cloud resources don't fit in RAM. BadgerDB keeps hot nodes there and spills history to disk: without breaking time-travel queries. Relational mode...
BadgerDB Time Layer¶
10 million cloud resources don't fit in RAM. BadgerDB keeps hot nodes there and spills history to disk: without breaking time-travel queries.
LSM Tree Limitations¶
Relational models fail at scale for real-time edge traversal across \(10^7\) interconnected resources. Pure-memory Go instances (map[string]*Node) trigger GC latency spikes exceeding 4.2 seconds on amd64 architectures when mapping 50 million pointers.
We use a memory-mapped sparse graph structure. Hot pointers actively in use stay in RAM. Cold historical state persists to an embedded BadgerDB store using Log-Structured Merge (LSM) trees with Value Log acceleration.
Temporal Radix Indexing¶
To establish historical provenance without duplicating Node structs, we build an incremental time-series key that concatenates the CRN with a big-endian uint64 timestamp:
// pkg/graph/store.go
func encodeTemporalKey(crn string, timestamp uint64) []byte {
buf := make([]byte, len(crn)+8)
copy(buf, crn)
binary.BigEndian.PutUint64(buf[len(crn):], math.MaxUint64 - timestamp)
return buf
}
Subtracting timestamp from math.MaxUint64 means an LSM sequential scan (Seek) natively returns the most recent state first, minimizing disk I/O for time-travel queries.
DSU Resolution¶
Disjoint Set Union
Calculating cluster connectivity with standard BFS degrades to O(V+E). We run an inverse-Ackermann O(ɑ(n)) Disjoint Set Union structure on top of the BadgerDB iterator:
type DSU struct {
parent []int32
size []int32
}
func (d *DSU) Find(i int32) int32 {
if d.parent[i] == i {
return i
}
// Path compression
d.parent[i] = d.Find(d.parent[i])
return d.parent[i]
}
This guarantees that checking connection validity between two cross-cloud vertices runs in functionally constant time, regardless of graph size.