Lab 01 — Cassandra Data Modeler & Serving Calculator

Phase: 11 — Serving: Cassandra & DynamoDB | Difficulty: ⭐⭐⭐⭐☆ | Time: 5–6 hours

A serving store answers one query shape in single-digit milliseconds — and punishes you for modeling it like a relational DB. This lab builds the arithmetic that keeps a Cassandra table healthy: consistency/durability (R+W>N), partition health (large partitions are the #1 footgun), hot-partition detection, tombstone thresholds, compaction-strategy selection, and time-series bucketing.

What you build

  • quorum / consistency_is_strong / level_nodes / tolerated_failures — tunable consistency as P01's quorum math (R+W>RF; what each level survives)
  • partition_cells / partition_health — cells & bytes vs the limits → ok/warn/danger
  • hot_partition_factor — skew detection (the serving costume of P01's hot key)
  • tombstone_scan_ok — the delete/TTL-heavy read that blows the 100k tombstone limit
  • choose_compaction_strategy — STCS (write) / LCS (read) / TWCS (time-series/TTL)
  • bucket_key — time-series bucketing so a per-entity series doesn't grow unbounded

Key concepts

ConceptWhat to understand
R + W > RFtunable strong consistency; ONE/QUORUM/ALL trade latency vs durability
Large partitionsGC pressure, slow reads, repair pain — model before shipping
Hot partitiona celebrity key melts one replica set; fix the partition key
Tombstonesdeletes/TTL create them; too many per read = failed query
CompactionSTCS/LCS/TWCS match write/read/time-series workloads
Bucketingbound partition growth for time series

Run

pip install -r requirements.txt
pytest test_lab.py -v
LAB_MODULE=solution pytest test_lab.py -v

Success criteria

  • All 14 tests pass.
  • You can explain why "model around the query, not the entities" is Cassandra's first rule.
  • You can explain why a TTL-heavy queue table is a tombstone disaster and what compaction strategy fixes it.
  • You can pick a partition key that avoids both large and hot partitions.

Extensions

  • Add a DynamoDB capacity model: RCU/WCU (or on-demand) sizing for a read/write rate, plus the hot-partition / adaptive-capacity caveat and a GSI cost.
  • Add streaming upserts from Flink (P04 idempotent sink) + a Spark backfill rate limiter (don't overwhelm the cluster) — the JD's Problem 4.
  • Model multi-region (NetworkTopologyStrategy, LOCAL_QUORUM) and the consistency/latency tradeoff across regions (P14/P15).