{"id":26242018,"url":"https://github.com/webdevcaptain/cassandra-iot-sample","last_synced_at":"2026-05-17T17:35:21.225Z","repository":{"id":282025242,"uuid":"947207630","full_name":"WebDevCaptain/cassandra-iot-sample","owner":"WebDevCaptain","description":"IoT Data API using Cassandra 5","archived":false,"fork":false,"pushed_at":"2025-03-12T11:34:23.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T12:22:37.093Z","etag":null,"topics":["cassandra"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebDevCaptain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-12T10:20:36.000Z","updated_at":"2025-03-12T11:34:27.000Z","dependencies_parsed_at":"2025-03-12T12:22:39.443Z","dependency_job_id":"dfc666e1-259d-474d-a0d8-b4f906c20de3","html_url":"https://github.com/WebDevCaptain/cassandra-iot-sample","commit_stats":null,"previous_names":["webdevcaptain/cassandra-iot-sample"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebDevCaptain%2Fcassandra-iot-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebDevCaptain%2Fcassandra-iot-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebDevCaptain%2Fcassandra-iot-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebDevCaptain%2Fcassandra-iot-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebDevCaptain","download_url":"https://codeload.github.com/WebDevCaptain/cassandra-iot-sample/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243375103,"owners_count":20280809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cassandra"],"created_at":"2025-03-13T09:21:05.538Z","updated_at":"2026-05-17T17:35:21.194Z","avatar_url":"https://github.com/WebDevCaptain.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IOT Data API\n\nA Smart City IoT Data API that registers sensors and ingests time-stamped readings.\n\n## Data Model\n\n### Sensors Table\n\n- Stores the core info needed for each sensor.\n- **Fields:**\n  - `sensor_id` (PK): Unique id for each sensor\n  - `type`: Type of sensor (e.g. air_quality, temperature)\n  - `lat` and `lng`: Geographic coordinates of the sensor\n  - `description`: description of the sensor\n  - `created_at`: Timestamp when the sensor was registered. We use `toTimestamp(now())` to get the current timestamp while storing.\n\n### Sensor Readings Table\n\n- **Fields:**\n\n  - `sensor_id`: Id to link the reading to a sensor (kind of FK in RDBMS)\n  - `timestamp` (Clustering Key): When the reading was taken. Helps order the data (we use it for querying)\n  - `value`: The numeric reading (e.g. air quality value).\n  - `unit`: The unit of measurement (e.g PPM)\n  - `status`: The status of the reading (e.g. ok, warning).\n\n- **Notes --**\n  - **Time-Series Data:** Using `sensor_id` as partition key and `timestamp` as clustering key supports efficient time-range queries.\n  - **High Write Throughput:** Designed to handle a large number of writes from sensors.\n  - **TTL Support:** Can use Cassandra’s TTL to automatically remove old data. [TODO]\n\n---\n\n## API Endpoints\n\n- [Sensor Management Endpoints](./endpoints-test/sensors.http)\n\n- [Sensor Readings Endpoints](./endpoints-test/readings.http)\n\n---\n\n## Tech Used\n\n1. Apache Cassandra (v5.x)\n2. Node.js \u0026 Express with DataStax Cassandra Driver\n\n---\n\n## Why use Cassandra for this IoT system ????\n\n\u003e Compared to Traditional Databases (MySQL/Postgres) and MongoDB\n\n- **High Write Throughput:** Cassandra is designed to handle many writes per second (with very low latency), which is ideal for time-series sensor data. Can easily load balance across multiple nodes in a Cluster...\n\n- **Scalability:** It scales horizontally very easily; new nodes can be added without downtime (Mongo can also do this)\n\n- **Distributed Architecture:** There is no single point of failure. Data is automatically replicated across multiple nodes (No master/slave setup)\n\n- **Tunable Consistency** You can balance between consistency and performance by choosing the right consistency level\n\n- **Time-Series Support:** With its partition and clustering keys, Cassandra naturally supports time-series data models..\n\n- **Built-In TTL** Easily set expiration times on data, automatically cleaning up old sensor readings (caches like Valkey(Redis), Memcached do this often)\n\n---\n\n## Key Cassandra internals:-\n\n[Architecture](https://cassandra.apache.org/doc/latest/cassandra/architecture/index.html#architecture/snitch.adoc)\n\n![Cassandra Cluster](https://cassandra.apache.org/_/_images/diagrams/apache-cassandra-diagrams-01.jpg)\n\n1. **P2P Architecture:**\n\n- Every node in the Cassandra cluster is equal. There is no master node.\n\n2. **Partitioning:**\n\n- Data is divided across nodes using partition keys, ensuring balanced load\n\n3. **Replication:**\n\n- Data is replicated across multiple nodes. The replication factor is configurable\n\n4. **Consistency Levels:**\n\n- Cassandra lets user choose the consistency level for each operation, balancing performance and data accuracy.\n\n5. **Write Path:**\n\n- Writes are fast because data is first written to a commit log, and then stored in an in-memory table (SST, memtable) before being flushed to disk.\n\n6. **Read Path:**\n\n- Uses SSTables (Sorted String Table or SST) and bloom filters to quickly locate data on disk.\n\n7. **Compaction:**\n\n- Compaction is a process that merges SSTables to reduce disk usage and improve performance. It is automatically triggered when the number of SSTables exceeds a certain threshold (as a batch process)\n\n8. **Tombstone:**\n\n- A tombstone is a special marker in Cassandra that indicates that a row has been deleted. It is used to optimize read performance by skipping deleted rows.\n\n---\n\n## License\n\nThis repo is released under the [MIT License](LICENSE) and can be used for any purpose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdevcaptain%2Fcassandra-iot-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebdevcaptain%2Fcassandra-iot-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdevcaptain%2Fcassandra-iot-sample/lists"}