Distributed Wide-Column Storage

Cassandra & ScyllaDB

Architect linearly scalable, masterless distributed storage for billions of AI agent conversation messages. Learn LSM-Tree write mechanics, partition key modeling, tunable consistency, and ScyllaDB's C++ asynchronous engine.

1 Core Architectural Concepts

Masterless Ring Topology

Every node in the cluster is identical. There is no single point of failure (no primary/secondary). Any node can accept read and write requests and coordinate them with replica nodes via Gossip protocol.

LSM-Tree Write Path

Writes append sequentially to an on-disk CommitLog (durability) and write to memory Memtable before returning success in <1ms. In-memory data flushes to immutable SSTables asynchronously.

Tunable Consistency

Balance speed vs. consistency on every query: ONE (fastest, AP mode), QUORUM (strict consistency, CP mode where R + W > N), or LOCAL_QUORUM for multi-datacenter isolation.

ScyllaDB Advantage

C++ rewrite of Cassandra using the Seastar asynchronous framework. Replaces JVM garbage collection pauses with thread-per-core NUMA architecture, delivering 10× higher throughput and deterministic p99 sub-millisecond latencies.

2 CQL Schema: Agent Chat Thread Storage

Optimized Partition & Clustering Keys

The Partition Key determines node assignment; the Clustering Column sorts messages chronologically on disk for O(1) sequential reads:

-- CQL Table Definition
CREATE KEYSPACE agent_store
WITH replication = {'class': 'NetworkTopologyStrategy', 'us-east': 3};
CREATE TABLE agent_store.session_messages (
tenant_id uuid,
session_id uuid,
message_id timeuuid,
role text, -- 'user', 'assistant', 'system'
content text,
tokens_consumed int,
PRIMARY KEY ((tenant_id, session_id), message_id)
) WITH CLUSTERING ORDER BY (message_id DESC);

3 FAQ

Why should partition sizes be kept under 100MB? →
In Cassandra/ScyllaDB, an entire partition must be read and compacted as a unit. If a partition exceeds 100MB (e.g. an agent session with 100,000 unbounded messages), compacting and repairing that partition causes massive JVM heap spikes, prolonged GC pauses, and node timeouts. Bucketing by date or session segment keeps partitions bounded.