Apache Cassandra
Cassandra
A distributed NoSQL database that keeps copies of data on multiple servers. It is designed to handle sustained writes and can keep serving requests when some servers fail.
What it is
Apache Cassandra is a distributed wide-column database. It is a good fit when an application writes a steady stream of data and already knows how it will look that data up. A device dashboard, for example, might need the latest readings for one sensor rather than a report that scans every sensor. Despite the name, a wide-column database is not the same as a columnar analytics engine such as ClickHouse.
How a request reaches the data
Cassandra hashes the partition key to determine which nodes hold a partition. Within that partition, clustering columns set the order of the rows. There is no fixed primary node: whichever node accepts a request acts as its coordinator and contacts the relevant replicas.
The replication factor is the number of copies Cassandra is configured to keep. The consistency level determines how many replicas must respond before an operation can succeed. With a replication factor of three, QUORUM needs two responses, while ONE needs only one. ONE can keep a request serviceable when only one replica is reachable, but a read at that level may see an older value if the responding replica hasn't received the latest write.
On the write path, a replica records a mutation in its commit log and updates an in-memory structure called a memtable. The memtable is eventually flushed to an immutable disk file called an SSTable. Background compaction merges these files so reads don't have to check an ever-growing set of files.
Example: fetch a sensor's latest readings
CREATE TABLE readings_by_day (
device_id text,
day date,
measured_at timestamp,
value double,
PRIMARY KEY ((device_id, day), measured_at)
) WITH CLUSTERING ORDER BY (measured_at DESC);
SELECT measured_at, value FROM readings_by_day
WHERE device_id = 'sensor-42' AND day = '2025-03-08'
LIMIT 10;
The device and day together identify one partition. Since readings are ordered newest first within it, the query can return up to ten rows without scanning other sensors or dates. This schema assumes a device never records two distinct readings with the same timestamp on the same day; otherwise those writes target the same row.
When to use it
Telemetry, activity feeds, and event histories often have the write volume and predictable access patterns that suit Cassandra. Its query language, CQL, looks like SQL, but there are no joins. A new lookup pattern often means creating another table and writing the same data in a different layout. If the application depends on ad hoc filters, joins, or transactions across multiple entities, a relational database is usually a simpler choice.
How it comes up in interviews
Expect to design a table around a specific query and explain what happens if traffic is uneven. A daily bucket keeps a device's entire history from piling into one partition, but it may still be too large for a busy device. Shorter buckets can limit partition size, at the cost of querying more partitions for a long time range. They don't necessarily fix a hot partition: if all current writes still land on one bucket, the same replicas still handle that traffic.