Run Apache Cassandra 5 in Docker, design a partition key, and practice CQL queries and clustering columns.
Cassandra is a distributed wide-column store built for high write throughput and multi-region availability. This lab starts a single node, creates a keyspace with a deliberate partition key, and shows how clustering columns shape the queries you can run efficiently.
docker compose up -d
docker compose cp examples/01_schema.cql cassandra:/tmp/01_schema.cql
docker compose cp examples/02_queries.cql cassandra:/tmp/02_queries.cql
docker compose exec cassandra cqlsh -f /tmp/01_schema.cql
docker compose exec cassandra cqlsh -f /tmp/02_queries.cql| Field | Value |
|---|---|
| Host | localhost |
| CQL port | 9042 |
| Keyspace | lab |
| User | cassandra |
| Password | cassandra (default; change it) |
| cqlsh | docker compose exec cassandra cqlsh |
| File | What it shows |
|---|---|
docker-compose.yml |
Engine, ports, and persistent volume. |
.github/workflows/compose-check.yml |
Validates the Compose file on every push. |
examples/01_schema.cql |
Keyspace and a table partitioned by day, clustered by time. |
examples/02_queries.cql |
Insert, query by partition, and inspect the schema. |
- Add a
metrics_by_devicetable partitioned bydeviceand query the latest reading. - Insert a row with a TTL and verify it disappears after expiry.
- Use
nodetool statusandnodetool tablestats lab.events_by_day. - Explain why
SELECT * FROM events_by_day WHERE device = 'sensor-1'needsALLOW FILTERING.
- The default
cassandrasuperuser password is used here. Change it before exposing the port. - A single node with
SimpleStrategyis only appropriate for a local lab; production usesNetworkTopologyStrategy. - Cassandra rewards query-first data modeling. The primary key in this lab is chosen for
WHERE day = ?queries. - First startup can take a minute; the healthcheck waits for CQL to become available.
This lab publishes its ports on 127.0.0.1 only. To use it from another country, do not open the database port to the internet. Pick one:
- VPS + private tunnel: run the lab on a small Ubuntu VPS, keep the port closed, and connect through WireGuard or
ssh -L. - Managed service: use a managed free tier for this engine and point the same examples at its connection string.
- HTTP UI only: if the engine has a web UI, put it behind Caddy with TLS and basic auth.
The shared checklist, provider map, and commands are in REMOTE-ACCESS.md.
docker compose down -v-v also removes the named volume, so the next start is a clean slate.
Part of the database-labs collection: 26 database engines, one index.
MIT (c) 2026 Arya Fatthurahman. See LICENSE.