Skip to main content

Capstone Project: Building a Real-Time Analytics Platform

Project Duration: 20-30 hours Learning Style: Hands-On Implementation + Architecture Design + Production Deployment Outcome: A complete, production-ready Cassandra application demonstrating mastery of all concepts

Project Overview

You will design and implement SensorMetrics, a real-time IoT analytics platform that:
  • Ingests millions of sensor readings per second from 100,000+ devices
  • Stores time-series data with automatic TTL-based expiration
  • Provides real-time dashboards with low-latency queries (< 10ms p95)
  • Supports multi-datacenter deployment for geographic distribution
  • Handles device failures gracefully (late data, out-of-order events)
  • Operates 24/7 with 99.9% uptime and automated recovery
This capstone synthesizes concepts from all previous modules:
  • Architecture (consistent hashing, replication, vnodes)
  • Data Modeling (partition keys, clustering columns, time-series patterns)
  • Read/Write Internals (CommitLog, MemTable, SSTable, compaction)
  • Cluster Operations (gossip, failure detection, repair, multi-DC)
  • Performance (JVM tuning, monitoring, capacity planning)

Part 1: Requirements Analysis

Functional Requirements

1. Data Ingestion:
  • 100,000 sensors sending metrics every 10 seconds
  • Throughput: 10,000 writes/second sustained, 50,000 writes/second peak
  • Metrics: temperature, humidity, pressure, battery level
  • Late arrivals: Up to 5 minutes delayed data must be accepted
  • Deduplication: Same reading shouldn’t be stored twice
2. Data Retention:
  • Hot data: Last 7 days (low-latency queries)
  • Warm data: 8-30 days (moderate latency acceptable)
  • Cold data: 31-365 days (high latency acceptable, compressed)
  • Ancient data: > 365 days deleted automatically (TTL)
3. Query Patterns: Pattern 1: Recent metrics for a single sensor
  • Frequency: Very high (1000s/sec)
  • Latency requirement: < 10ms p95
Pattern 2: Aggregate metrics for a sensor
  • Frequency: Moderate (100s/sec)
  • Latency requirement: < 50ms p95
Pattern 3: All sensors in a building
  • Frequency: Low (10s/sec)
  • Latency requirement: < 100ms p95
Pattern 4: Anomaly alerts
  • Frequency: Low (monitoring system)
  • Latency requirement: < 1s

Non-Functional Requirements

Availability:
  • 99.9% uptime (< 9 hours downtime/year)
  • No single point of failure
  • Graceful degradation during node failures
Scalability:
  • Horizontal scaling to 1M+ sensors
  • Linear performance scaling with nodes
  • Automatic rebalancing on node addition
Performance:
  • Write latency: < 5ms p95
  • Read latency: < 10ms p95 (hot data)
  • Throughput: 50,000 writes/sec peak
Durability:
  • No data loss for acknowledged writes
  • Automatic replication (RF=3)
  • Regular backups with 7-day retention
Geographic Distribution:
  • Multi-datacenter deployment (US-East, EU-West)
  • Local reads/writes (< 50ms latency)
  • Eventual consistency across DCs (< 10 seconds)

Part 2: Architecture Design

High-Level Architecture

Cassandra Cluster Design

Cluster Configuration:
Capacity Planning:

Part 3: Data Model Design

Schema Design Process

Step 1: Identify Queries (done in Part 1) Step 2: Design Tables (one table per query pattern)

Table 1: Raw Sensor Metrics (Query Pattern 1)

Query:
Schema:
Design Decisions:
  1. Partition Key = sensor_id:
    • Queries are always for a specific sensor
    • Ensures even distribution (100K sensors)
    • Partition size: ~200 bytes/reading × 8,640 readings/day = 1.7 MB/day (acceptable)
  2. Clustering Key = timestamp DESC:
    • Time-series data sorted newest-first
    • Efficient range queries (WHERE timestamp > ?)
    • Descending order for “latest N readings” queries
  3. TWCS Compaction:
    • Time-bucketed data (1-day windows)
    • Entire SSTable dropped when TTL expires (ultra-fast)
    • Minimal compaction overhead
  4. TTL = 365 days:
    • Automatic deletion (no manual cleanup)
    • Aligns with retention policy
Partition Size Validation:

Table 2: Daily Aggregates (Query Pattern 2)

Query:
Schema:
Design Decisions:
  1. Partition Key = sensor_id:
    • Matches query pattern
    • Small partitions (1 row/day = 365 rows/year)
  2. Clustering Key = date:
    • Enables efficient range queries
    • Sorted descending (recent aggregates first)
  3. LCS Compaction:
    • Aggregates updated daily (read-modify-write)
    • LCS handles updates efficiently
  4. Longer TTL (3 years):
    • Aggregates more valuable than raw data
    • Smaller storage footprint (365 rows/sensor vs 3M+ raw readings)

Table 3: Sensors by Building (Query Pattern 3)

Query:
Schema:
Design Decisions:
  1. Partition Key = building_id:
    • Query retrieves all sensors in a building
    • Partition size: ~100 sensors/building × 200 bytes = 20 KB (tiny!)
  2. Clustering Key = sensor_id:
    • Sorted by sensor_id for easy lookup
    • Enables WHERE building_id = ? AND sensor_id = ? queries
  3. Denormalization:
    • Stores latest values (redundant with sensor_metrics)
    • Avoids scatter-gather query across all sensors
    • Updated on every sensor reading (write amplification accepted)
  4. No TTL:
    • Metadata table (doesn’t expire)
    • Updated in-place as new readings arrive

Table 4: Anomaly Events (Query Pattern 4)

Query:
Schema:
Design Decisions:
  1. Composite Clustering Key:
    • event_time for time-series ordering
    • event_type to allow multiple anomalies at same timestamp
  2. TWCS with 7-day windows:
    • Anomalies are time-series data
    • Fast TTL-based expiration
  3. Shorter TTL (90 days):
    • Anomalies less valuable after resolution
    • Reduces storage

Complete Keyspace Definition


Part 4: Implementation

Phase 1: Ingestion API

Technology: Python FastAPI (async I/O for high throughput) File: ingestion_api.py
Key Design Decisions:
  1. Batching: Client sends 100-1000 readings per request (reduces network overhead)
  2. Prepared Statements: Pre-compiled queries (10x performance improvement)
  3. Deduplication: Bloom filter prevents duplicate writes
  4. Validation: Pydantic models ensure data quality
  5. LOCAL_QUORUM: Fast writes to local DC, async replication to remote DC
  6. Denormalization: Update sensors_by_building in same batch (eventual consistency)

Phase 2: Background Aggregation

Technology: Python (scheduled job or Spark for larger scale) File: daily_aggregator.py
Production Optimization: Use Apache Spark for parallel aggregation:

Phase 3: Dashboard API

File: dashboard_api.py

Part 5: Deployment and Operations

Cassandra Configuration

cassandra.yaml (production settings):
cassandra-rackdc.properties (us-east nodes):
JVM Configuration (jvm11-server.options):

Monitoring Setup

Prometheus Configuration (prometheus.yml):
Alert Rules (alerts.yml):

Backup Strategy

Automated Snapshot Script (backup.sh):
Cron Schedule:

Repair Schedule

Automated Repair with Cassandra Reaper:
Alternative: Manual Repair Script:

Part 6: Testing and Validation

Load Testing

cassandra-stress Configuration:
Run Load Test:
Expected Results:

Failure Testing

Test 1: Node Failure
Test 2: Network Partition
Test 3: Overload (DDoS Simulation)

Part 7: Advanced Challenges (Optional)

Challenge 1: Hot Partition Mitigation

Problem: One sensor (sensor-99999) sends 10x more data than others, creating a hot partition. Task:
  1. Detect hot partition (use nodetool toppartitions)
  2. Redesign data model to shard hot partition:
  3. Modify ingestion API to compute shard: shard = hash(timestamp) % 10
  4. Modify dashboard API to query all shards and merge results

Challenge 2: Cross-DC Latency Optimization

Problem: Reads from eu-west to us-east data take 150ms (cross-Atlantic latency). Task:
  1. Implement read-from-local-DC-first logic:
  2. Measure latency improvement
  3. Consider trade-offs (stale data vs latency)

Challenge 3: Materialized Views (Advanced)

Task: Create a materialized view for “sensors by latest temperature”:
Use Case: Quickly find hottest/coldest sensors in a building Warning: Materialized views have performance implications (write amplification)

Part 8: Deliverables and Evaluation

Project Deliverables

  1. Architecture Diagram (draw.io or similar)
    • Cassandra cluster topology
    • Application components
    • Data flow
  2. Data Model Documentation
    • CQL schema definitions
    • Query pattern → table mapping
    • Design decision rationale
  3. Implementation Code
    • Ingestion API (ingestion_api.py)
    • Dashboard API (dashboard_api.py)
    • Background jobs (daily_aggregator.py)
  4. Configuration Files
    • cassandra.yaml
    • jvm11-server.options
    • prometheus.yml, alerts.yml
  5. Operational Runbook
    • Deployment procedure
    • Backup/restore steps
    • Common troubleshooting scenarios
  6. Load Test Results
    • cassandra-stress logs
    • Latency percentiles
    • Throughput measurements
  7. Presentation (10-15 slides)
    • Problem statement
    • Architecture overview
    • Data model design
    • Performance results
    • Lessons learned

Evaluation Criteria

Mastery Checklist

  • Data Modeling
    • Query-driven design (1 query = 1 table)
    • Appropriate partition keys (even distribution)
    • Time-series clustering keys
    • Denormalization for performance
    • TTL for automatic expiration
  • Write Path
    • Batch inserts (100+ per batch)
    • Prepared statements
    • Appropriate consistency level (LOCAL_QUORUM)
    • Deduplication logic
  • Read Path
    • Efficient partition key queries (no ALLOW FILTERING)
    • Caching (Redis or application-level)
    • Pagination for large results
  • Compaction
    • TWCS for time-series data
    • LCS for frequently updated data
    • Appropriate window sizes
  • Multi-DC
    • NetworkTopologyStrategy (RF per DC)
    • LOCAL consistency levels
    • Per-DC repair
  • JVM Tuning
    • Heap ≤ 8GB
    • G1GC with 200ms pause target
    • GC logging enabled
  • Monitoring
    • Prometheus + Grafana setup
    • Critical alerts (dropped mutations, GC, node down)
    • Dashboard for key metrics
  • Backup/Repair
    • Automated daily snapshots
    • Weekly repair schedule
    • Tested restore procedure

Part 9: Real-World Extensions

Extending the Project

1. Stream Processing Integration:
  • Add Kafka for event streaming
  • Use Kafka Connect Cassandra Sink for ingestion
  • Implement Kafka Streams for real-time anomaly detection
2. Machine Learning:
  • Train ML model to predict sensor failures (battery level, read patterns)
  • Use Spark MLlib or TensorFlow
  • Store predictions in Cassandra for dashboard
3. Multi-Tenancy:
  • Support multiple customers (tenant isolation)
  • Redesign schema with tenant_id in partition key
  • Implement tenant-level quotas
4. Advanced Analytics:
  • Time-series forecasting (predict future temperature)
  • Correlation analysis (temperature vs humidity patterns)
  • Spatial queries (sensors within 1km radius)

Production Considerations

Security:
High Availability:
  • Deploy across 3+ availability zones per DC
  • Use Kubernetes for API layer (auto-scaling, self-healing)
  • Implement circuit breakers and retries in clients
Cost Optimization:
  • Use tiered storage (hot=SSD, cold=HDD)
  • Implement data lifecycle (move old data to S3 for archival)
  • Right-size nodes (monitor CPU, memory, disk usage)

Summary

You’ve designed and implemented a production-ready, scalable IoT analytics platform using Apache Cassandra. This capstone demonstrated: Data Modeling: Query-driven design with proper partitioning ✅ Write Optimization: Batching, prepared statements, TWCS compaction ✅ Read Optimization: Caching, denormalization, efficient queries ✅ Multi-DC: Geographic distribution with LOCAL consistency ✅ Performance Tuning: JVM, OS, Cassandra configuration ✅ Operations: Monitoring, backups, repair, troubleshooting ✅ Production Deployment: Complete stack from ingestion to visualization Congratulations on completing the Cassandra mastery course! 🎉 You now have the skills to:
  • Design schemas for any query pattern
  • Operate Cassandra clusters at scale
  • Troubleshoot performance issues
  • Deploy production-ready systems

What’s Next?

Neo4j Graph Database Course

Learn graph databases, Cypher queries, and property graph modeling

Apache Spark Course

Master distributed data processing with RDDs, DataFrames, and Structured Streaming

Apache Kafka Course

Build real-time streaming pipelines with Kafka, Kafka Streams, and KSQL

Advanced Cassandra Topics

Explore change data capture, materialized views, and advanced operations