You end with a table that answers "newest messages in a room" in one read, and an error that shows what it refuses.
In a relational database you design tables around the data, and then write any query you like. In Cassandra you design the table around the query. The reason is how the data is stored. Cassandra splits a table into partitions. All rows of a partition live together, on the same machines. A partition key decides which partition a row goes to, and a clustering key decides the order of the rows inside it. A query that names one partition is a quick read from one place. A query that does not is a scan of everything.
The partition key picks the box. The clustering key orders what is inside.
Step 1.1: A keyspace (about 15 minutes)
A keyspace is the container for tables, like a database in other systems. It also says how many copies of the data to keep. We have one container, so one copy:
CREATE KEYSPACE IF NOTEXISTS chat
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
DESCRIBE KEYSPACE chat;
Step 1.2: The room table (about 30 minutes)
The question we want to answer is: give me the messages of one room, newest first. So the room is the partition key, and the message time is the clustering key, sorted from newest to oldest. The double parentheses mean "this is the partition key". The timeuuid type is a unique id that contains a time, which also keeps two messages sent in the same millisecond apart:
CREATE TABLE IF NOTEXISTS chat.messages_by_room (
room_id text,
msg_id timeuuid,
author text,
body text,
PRIMARY KEY ((room_id), msg_id)
) WITH CLUSTERING ORDERBY (msg_id DESC);
DESCRIBETABLE chat.messages_by_room;
Step 1.3: Five messages (about 20 minutes)
minTimeuuid('...') builds a timeuuid for a given moment. We use it so that the ids, and so the order, are the same on every run:
INSERT INTO chat.messages_by_room (room_id, msg_id, author, body)
VALUES ('general', minTimeuuid('2026-11-01 09:00:00+0000'), 'asha', 'Good morning');
INSERT INTO chat.messages_by_room (room_id, msg_id, author, body)
VALUES ('general', minTimeuuid('2026-11-01 09:05:00+0000'), 'ben', 'Morning! Standup in five?');
INSERT INTO chat.messages_by_room (room_id, msg_id, author, body)
VALUES ('general', minTimeuuid('2026-11-01 09:30:00+0000'), 'asha', 'Notes are in the doc');
INSERT INTO chat.messages_by_room (room_id, msg_id, author, body)
VALUES ('general', minTimeuuid('2026-11-01 10:00:00+0000'), 'chitra', 'Lunch at one?');
INSERT INTO chat.messages_by_room (room_id, msg_id, author, body)
VALUES ('random', minTimeuuid('2026-11-01 09:15:00+0000'), 'ben', 'Anyone seen the match?');
SELECTcount(*) FROM chat.messages_by_room;
The count should be 5. The general room has four messages and random has one.
Step 1.4: Read a room (about 25 minutes)
The query names the partition key and nothing else, and the rows come back in the order we declared, newest first. toTimestamp turns a timeuuid into a readable time:
SELECT toTimestamp(msg_id) AS sent_at, author, body
FROM chat.messages_by_room
WHERE room_id ='general';
SELECT toTimestamp(msg_id) AS sent_at, author, body
FROM chat.messages_by_room
WHERE room_id ='general'
LIMIT 2;
You should see the 10:00 message first and the 09:00 message last. Cassandra did not sort anything for you at query time. The rows were already stored in that order, so reading them is reading a stretch of a file.
Step 1.5: A question the table refuses (about 20 minutes)
Now ask for all messages by asha, without naming a room:
SELECT*FROM chat.messages_by_room WHERE author ='asha';
Cassandra answers with an error that mentions ALLOW FILTERING. It is telling us this query cannot use the layout of the table, and would have to read every partition on every machine to find the matches. A relational database lets you ask anyway and quietly does a full scan. Cassandra makes you notice. We will fix it properly in Phase 2, and we will see what ALLOW FILTERING costs in Phase 3.
No partition in the query means a visit to every partition.
Step 1.6: A time range inside a room (about 25 minutes)
Within one partition we can also ask for a range of the clustering key. The pattern for time ranges with timeuuids is to start after the largest id of the start time and end before the smallest id of the end time:
SELECT toTimestamp(msg_id) AS sent_at, author, body
FROM chat.messages_by_room
WHERE room_id ='general'AND msg_id > maxTimeuuid('2026-11-01 09:10:00+0000')
AND msg_id < minTimeuuid('2026-11-01 09:45:00+0000');
Only the 09:30 message should come back.
Step 1.7: There is no update, only write (about 25 minutes)
In Cassandra, an INSERT for a key that already exists replaces it. There is no error. This is called an upsert. We rewrite Ben's 09:05 message:
INSERT INTO chat.messages_by_room (room_id, msg_id, author, body)
VALUES ('general', minTimeuuid('2026-11-01 09:05:00+0000'), 'ben', 'Morning! Standup at 09:10?');
SELECTcount(*) FROM chat.messages_by_room WHERE room_id ='general';
SELECT toTimestamp(msg_id) AS sent_at, author, body
FROM chat.messages_by_room
WHERE room_id ='general'AND msg_id = minTimeuuid('2026-11-01 09:05:00+0000');
The count of general is still 4, and the row now has the new text. A write does not first read to see whether the row exists, which is one reason writes in Cassandra are so cheap.
Pitfall: because writes never check, a typo in a key does not fail. It silently creates a new row, in a new place.
Phase 1 done
You designed one table around one question, read it in order with no sorting, and met the rule: every query names its partition. Now we meet the second question.