docs/Docs/CockroachDB
Database Layer

CockroachDB Features

Bastion uses CockroachDB as its distributed SQL backbone. Every memory operation — store, search, audit, time-travel — runs against CockroachDB with SERIALIZABLE isolation.

Why CockroachDB?

SERIALIZABLE Isolation
CockroachDB uses SERIALIZABLE by default — the strictest isolation level. No phantom reads, no write-write conflicts between concurrent agents. This is critical when multiple agents write to the same memory store.
AS OF SYSTEM TIME
Point-in-time queries via MVCC. Query exactly what an agent knew at any timestamp without maintaining separate snapshots. Zero-copy reads.
C-SPANN Vector Index
Distributed vector similarity search for memory embeddings. Sub-linear query time at scale. Used by memory_search and multi_signal_search.
PostgreSQL Wire Protocol
100% compatible with psycopg2, pg drivers, and ORMs. No vendor lock-in — switch to any Postgres-compatible database.
CDC Changefeeds
Change data capture for real-time event streaming. Powers the dashboard's live event feed and A2A push notifications.
Multi-Region Ready
Schema uses REGIONAL BY ROW locality. Deploy to multiple regions with automatic failover when ready.

Query Examples

sql
-- Time-travel query
SELECT * FROM agent_memory
AS OF SYSTEM TIME '2026-01-15T12:00:00Z'
WHERE agent_id = $1;

-- Vector similarity search
SELECT content, embedding cosine_distance(embedding, $1) AS dist
FROM agent_memory
ORDER BY dist ASC LIMIT 10;

-- Hash chain verification
SELECT memory_id, cryptographic_hash
FROM agent_audit
WHERE action = 'memory_store'
ORDER BY recorded_at DESC;