Skip to content

About

Run Apache Cassandra 5 in Docker, design a partition key, and practice CQL queries and clustering columns.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Arya Fatthurahman

Cassandra Lab

Run Apache Cassandra 5 in Docker, design a partition key, and practice CQL queries and clustering columns.

Database: Apache Cassandra Category: Wide-column / NoSQL Runs in Docker License: MIT compose-check

What this lab is

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.

Quickstart

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

Connection details

Field Value
Host localhost
CQL port 9042
Keyspace lab
User cassandra
Password cassandra (default; change it)
cqlsh docker compose exec cassandra cqlsh

Examples

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.

Exercises

  1. Add a metrics_by_device table partitioned by device and query the latest reading.
  2. Insert a row with a TTL and verify it disappears after expiry.
  3. Use nodetool status and nodetool tablestats lab.events_by_day.
  4. Explain why SELECT * FROM events_by_day WHERE device = 'sensor-1' needs ALLOW FILTERING.

Notes and limits

  • The default cassandra superuser password is used here. Change it before exposing the port.
  • A single node with SimpleStrategy is only appropriate for a local lab; production uses NetworkTopologyStrategy.
  • 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.

Run it from anywhere

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.

Cleanup

docker compose down -v

-v also removes the named volume, so the next start is a clean slate.

References


Part of the database-labs collection: 26 database engines, one index.

License

MIT (c) 2026 Arya Fatthurahman. See LICENSE.

About

Run Apache Cassandra 5 in Docker, design a partition key, and practice CQL queries and clustering columns.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors