We would settle two things before the first Cassandra audit trail write performance test. The first is a partition key that pairs the subject an auditor asks about with a time bucket, sized so no partition grows past about 100 MB. The second is a TimeWindowCompactionStrategy (TWCS) window sized so the data’s life in the table spans roughly 20 to 30 windows. Ingest is the easier half, because Cassandra’s log-structured storage engine keeps read lookups off the write path. The harder half is the auditor’s query. For that, the numbers to watch are how many SSTables each read touches and the read latency under load, not events per second.
The table’s contents (actor, action, outcome, timestamp, integrity marker) and the reasons auditors read it first are covered in what an audit trail must capture in a regulated AI workflow. What follows is about the store underneath it.
Appends on One Side, Auditor Lookups on the Other
An audit trail needs both high-throughput ingestion and fast individual record queries. Writes are time-ordered and append-only. When an auditor asks “show me all access to patient record X in the last 90 days”, the answer is expected in seconds rather than hours. Cassandra’s design favours the first demand: updates go into memory and are written to disk sequentially, so writes are very fast and reads have to merge data from several places.
The data model has to settle this conflict, because in Cassandra the model is built around specific queries and each query is best served by a single table. Ingest wants writes spread evenly across the cluster. The auditor’s per-subject query is fastest when that subject’s events share a partition, sorted by time. A model built only for ingest satisfies the first wish and quietly gives up the second.
How Do I Make “every access to this record, ordered by time” a Single-Partition Read?
Put the subject in the partition key and the time in the clustering key. Then the auditor’s question maps to one partition, or a handful, read in order. Apache’s documentation says it directly: the fewer partitions a query touches, the faster it responds, because partitions on different nodes make the coordinator send a request to each of them. The stated design goal is a query that reads one partition, or failing that, as few as possible.
One reference schema for audit events partitions by year-month or tenant-month, clusters by a descending TIMEUUID and uses TWCS with one-day windows. That layout suits period queries such as “everything that happened in March”. For “everything that happened to resource R” it falls short, because a query without the partition key falls back to index-based or filtered access with significant performance costs, or to a full cluster scan. Cassandra has no JOINs, so a by-resource query needs its own table, such as PRIMARY KEY ((resource_id, bucket), event_id). That table has a cost. Every extra denormalised table adds one more write per event and opens the question of what happens when one of those writes fails.
We would build one table per known auditor question (by subject, by actor, by period), accepting the write cost from the start. An auditor’s question the model cannot answer costs far more than an extra write.
Worked Example: Sizing the Time Bucket
Apache’s sizing formula is partition_size = Nv × (Ck + Cs + average_column_sizes) + Nstatic × static_column_sizes, and the usual target is 10 MB to 100 MB per partition. To keep the arithmetic sourced, take the volume from a published retention example: 500,000 audit events a day at about 500 bytes each.
| Partition layout | Events per partition | Approximate size (500 bytes × events, before key and cell overhead) |
|---|---|---|
| Tenant per day | 500,000 | ~250 MB, over the ceiling |
| Tenant per hour | 500,000 ÷ 24 ≈ 20,800 | ~10.4 MB, at the low end of the target and already above the 10 MB P99 warning line |
| One subject, any bucket | up to 100 MB ÷ 500 bytes = 200,000 | ceiling on events per subject per bucket |
The formula adds clustering-key and per-cell terms to these figures, and the 500-byte event is that example’s assumption rather than a property of Cassandra. A subject logging well under 200,000 events a month can use a monthly bucket. The 90-day query then issues one query per bucket, in parallel through the driver’s async calls, spreading the work across the cluster. The application computes the bucket itself, for an hourly bucket as event_time - (event_time % 3600000).
When One Actor Floods a Partition
A hot partition is a skew in the access pattern that shows up as a performance problem: one partition key takes a disproportionate share of traffic, and the replicas owning its token range saturate. Writing too fast to one partition also creates hot spots that limit scale-out, and oversized partitions cause trouble for repair, streaming and reads.
The fix is to append a deterministic hash or sub-bucket shard to the partition key, which turns one logical stream into several physical partitions. The cost falls on reads, which have to query every shard and merge the results client-side. A scatter-gather read carries much higher overhead than a single-partition read, so the shard count should balance write spread against read complexity. A sharding column also needs extra application logic.
We would shard only the tables or subject types that need it. The shard function must be deterministic, so the reader always knows which partitions to fetch for a given subject and bucket.
Two details make hot partitions worse than they look. Under saturation, speculative retry turns a bottleneck on one replica into CPU and I/O pressure on several, because the coordinator fires parallel requests at more replicas. Because Discord read and wrote at quorum, it reported that every query to the nodes serving a hot partition suffered higher latency. To check partition size, run nodetool tablehistograms on the table. A P99 or maximum partition size above 10 MB, or any partition above 100 MB, means the partition is oversized as well as hot.
Cassandra Audit Trail Write Performance: Consistency and Commit Log Choices
This section covers three choices: the write consistency level, the commit log sync mode and how ordering is recorded.
Higher consistency levels add write latency because the coordinator waits for more acknowledgements. At replication factor 3, QUORUM writes and reads give 2 + 2 > 3, so reads see the latest writes under normal operation. LOCAL_QUORUM gives the same guarantee within each datacentre. AxonOps’ reference recommends QUORUM for a single datacentre and LOCAL_QUORUM for several. We would not write audit events at ONE: if the acknowledged replica fails before the data reaches the others, nothing replicated the event, and on an audit trail the event is the whole point.
The commit log sync mode decides when an acknowledged write is actually on disk. In the default periodic mode, writes are acknowledged straight away and the log is synced every 10,000 ms, so after an unexpected shutdown a node can lose up to that period, or more if the sync is delayed. Batch mode acknowledges only after an fsync. Group mode makes writes wait for a shared sync, every 1,000 ms by default. Under periodic mode, a named loss scenario for acknowledged writes is simultaneous OS or hardware crashes on several replicas within the sync period. The YCSB authors described the same trade in general terms: deferring the disk sync improves write latency and throughput at the risk of losing unsynced updates. With RF 3 and quorum writes, we would accept periodic mode as the default. Group mode is the choice when policy says an acknowledged audit event must be on disk somewhere, and its latency cost should be measured under realistic load before you commit to it.
For ordering, TIMEUUID clustering keeps events in time order and keeps each event unique. We would also store the source’s own event time as a separate column, because the moment the store receives a late inference callback is not the moment the event happened.
Writing one event to two denormalised tables raises the batch question. Logged batches give atomicity through the batch log but run slower than individual writes. For an audit trail we would pay that overhead, since a by-subject table that is missing an event the by-period table holds is an inconsistency an auditor will find.
Tamper evidence comes from application-level controls. SSTables are immutable files, and an append-only schema with hash chaining provides the evidence that nothing was altered. The reasoning for why a regulated trail needs it sits with what an audit trail must capture in a regulated AI workflow.
Choosing Between TWCS, STCS, LCS and UCS for an Append-Mostly Trail
TWCS groups SSTables into time windows. It behaves like size-tiered compaction inside the current window, collapses each window into one SSTable once it closes, and then never rewrites it, so write amplification stays close to its floor.
| Strategy | Fit for an audit trail | Main cost |
|---|---|---|
| SizeTieredCompactionStrategy (STCS) | Suits write-heavy loads | Large temporary disk spikes; needs about 50% free space |
| LeveledCompactionStrategy (LCS) | Fewer SSTables per read, better for read-heavy loads | More frequent, I/O-intensive compaction |
| TWCS | Built for TTL’d, mostly immutable time series | Breaks down with out-of-window writes and non-TTL deletes |
| Unified Compaction Strategy (UCS) | Recommended default for new Cassandra 5.0+ deployments; keeps time order and supports whole-SSTable expiration | Tiered settings trade read amplification for write amplification |
Window Sizing Follows Retention
The guidance is roughly 20 to 30 windows over the data’s lifetime, or compaction_window_size ≈ TTL / 25. A 90-day TTL therefore points to 3-day windows. Windows must also match query granularity. A six-year healthcare requirement divided by 25 gives windows of about 88 days (6 × 365 ÷ 25), far coarser than the query granularity the windows should mirror. We would hold the hot and warm part of the trail in Cassandra on a TTL matching that tier, with older years in an archive. One TWCS table should not span the full statutory period.
TTL or Explicit Deletion: The Sources Disagree
One audit reference recommends no TTL on the audit table, managing retention through explicit deletion instead. The compaction sources argue against pairing that with TWCS. Windows are never compacted together, so a tombstone and the data it shadows sit in different SSTables and the disk space is never reclaimed. We weigh the compaction sources higher here, since they describe the storage mechanism and the audit reference a retention policy. The resolution we would use keeps both concerns: a TTL matched to the hot tier, and an archival job that copies events out before they expire, so legal holds apply to the archive copy rather than to an expiring row.
Late Writes, Timestamps and Repair
Any write whose timestamp lands in a closed window (late data, a backfill, client clock skew) forces cold data back into a sealed bucket. Apache’s TWCS guide says to avoid setting timestamps with CQL USING TIMESTAMP and to run frequent repairs. Hints, read repair and anti-entropy repair can also carry old data into new windows. When that happens, some tombstones wait for the newer SSTable to expire, and reads on repaired partitions can hit more SSTables. The Last Pickle advises disabling read repair on TWCS tables. Keep gc_grace_seconds at or below one window when you rely on whole-SSTable expiration, but never below your repair cadence, or deleted data can come back.
On Cassandra 5.0, one experienced practitioner argues that UCS with a multi-table layout can replace TWCS for time series. The UCS design record itself expects TWCS to stay in use because it may still have advantages in some scenarios. We would treat UCS as the default to test on 5.0 and keep TWCS where an existing cluster already runs it well.
Why an Ingest Benchmark Cannot Tell You Whether the Audit Query Is Fast
A write-throughput test measures the half of the workload Cassandra is optimised for. The original YCSB study found Cassandra with lower update latency and higher read latency than read-optimised systems, and the read penalty appeared mainly near disk saturation. That last finding is the trap. A storage benchmark run below saturation, or with no reads, will not show the read behaviour an auditor meets on a busy cluster. BenchANT’s YCSB 0.17.0 runs found Cassandra’s throughput lowest at a 50/50 read-write mix, with peaks more than 30% above that minimum.
Even a well-designed stress test needs observation over time, covering traffic spikes and background operations, not just a final throughput number. Discord reported compaction trouble on its own Cassandra cluster. Compaction fell behind, reads grew more expensive, and latency cascaded while nodes tried to catch up.
Read-Side Checklist for an Audit-Trail Table
- Run the real auditor queries (by subject, by actor, by period) during sustained ingest, not on an idle cluster.
- Check SSTablesPerReadHistogram in
nodetool tablehistograms: with correctly sized TWCS, a typical read touches one or two SSTables. - Track local read latency alongside SSTables per read; Apache’s documentation notes the two correlate closely.
- Check partition size distribution: a P99 above 10 MB or any partition above 100 MB marks the partition as oversized.
- Use
nodetool tpstatsto see whether read threads, write threads or compaction is the resource running short. - Watch whether compaction keeps up, and tune
concurrent_compactorsorcompaction_throughputif it does not.
Setting the latency targets those reads must meet is a broader question, covered in our piece on latency, saturation and reliability SLOs for Cassandra in production AI. How we support teams that run these clusters is described on our AI infrastructure and production SaaS page.
Keeping Storage, Read Amplification and Node Cost Bounded over Years of Retention
Retention requirements range from 90 days for internal policy to seven years or more under SOX and HIPAA, and PCI DSS requires three months to be immediately available. Audit data has a clear access pattern: recent events are queried often, and older events mostly during audits or investigations. Tiered storage exploits that pattern. Hot means full indexing and sub-second queries for about 90 days, warm means compressed and queryable in seconds up to a year, and cold means immutable compressed files in object storage that take minutes to hours to restore. In AuditKit’s worked example, tiering cost under $40 a month for seven years of data, against $150 to $300 a month for keeping everything in one hot database, which is 4 to 8 times more. That example uses PostgreSQL for the hot tier, so its figures do not transfer to Cassandra, though the reasoning does: every year kept on the cluster adds SSTables, compaction work and disk that no recent query needs.
On the cluster itself, keep 30% or more free disk for compaction headroom. Under TWCS, maximum compaction overhead on disk is 50% of the newest bucket. Dense TWCS nodes work while the topology is static, but adding nodes hits the slow streaming path, which is a real risk for a trail that grows with the business.
Retention should also be per tenant, so that one healthcare customer’s six-year requirement does not raise costs for everyone else. Deletion should be automated and checked against legal holds, rehearsed in a dry-run mode, and logged as audit events of its own, which creates a meta-audit trail.
When Is Postgres the Better Store for an Audit Trail than Cassandra?
We know of no neutral, measured comparison of Cassandra and Postgres for audit-trail workloads, so what follows is judgement. In the original YCSB study’s read-heavy workload, sharded MySQL and PNUTS gave lower read latencies than Cassandra, while Cassandra stayed better for writes. That study tested sharded MySQL and PNUTS rather than Postgres, so treat it as a direction, not a verdict.
Postgres is usually the better store when ingest volume is moderate, when auditors ask questions nobody predicted, or when the trail must be updated in the same transaction as the business record. Cassandra has no JOINs, so data a query needs from several entities must sit in one table. At the 500,000 events a day in AuditKit’s example, the 90-day hot tier is about 22 GB, held in PostgreSQL. Cassandra earns its operational cost when ingest stays high or when the trail spans datacentres, where LOCAL_QUORUM and asynchronous wide-area replication keep writes fast.
The store is also only one part of what makes an AI workflow fit for regulated use, a point developed in what makes an AI or video workflow HIPAA- or GxP-ready. Validation evidence stores have their own page: Cassandra performance for GxP AI validation evidence stores. Whichever store you pick, the decision that matters most comes before any tuning: write down the questions auditors will ask, and check that each one maps to a bounded number of partitions or an index, before the first event is stored.
FAQ
Is Cassandra a Column-Based Database?
Cassandra stores data in declared column families, each physically stored apart. Within a table, rows sharing a partition key are stored together and sorted by clustering columns.