If you come to Apache Cassandra from relational databases, your instincts will lead you astray. There are no joins, very limited ad-hoc filtering and no normalization to lean on. Instead, Cassandra asks you to start from your queries and design one table for each of them.
How Cassandra stores data
Each table has a primary key made of two parts:
- the partition key, which is hashed to decide which nodes store the data, and
- optional clustering columns, which sort rows within a partition.
CREATE TABLE sensor_readings (
sensor_id uuid,
day date,
reading_ts timestamp,
temperature double,
PRIMARY KEY ((sensor_id, day), reading_ts)
) WITH CLUSTERING ORDER BY (reading_ts DESC);
Here (sensor_id, day) is the composite partition key and reading_ts is the clustering column. All readings for one sensor on one day live together on the same replicas, sorted newest first.
Rule 1: every query should hit one partition
Efficient reads specify the full partition key:
SELECT reading_ts, temperature
FROM sensor_readings
WHERE sensor_id = 5f1c0b8e-2b6a-4c5d-9d3e-2a1f4b6c7d8e
AND day = '2026-07-28'
LIMIT ;
