The result
Writes continued during the recorded single-node-loss test. Reads could fall back from two replicas to one.
Weather queries through a tested node failure
Academic project
Kept writes available during the tested loss of one Cassandra node, with read-consistency fallback in a three-node NOAA weather-data service.
From the repository
A fault-tolerant weather data ingestion and analysis system built on Apache Cassandra. Features configurable consistency levels for read/write availability tradeoffs, automatic failover mechanisms, and real-time temperature analytics from NOAA weather stations across Wisconsin.
This system processes weather data from the National Oceanic and Atmospheric Administration (NOAA), storing temperature readings from weather stations in a distributed Cassandra cluster. It demonstrates advanced distributed database concepts including tunable consistency, prepared statements, and graceful degradation under node failures.

The system consists of:
CREATE KEYSPACE weather WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 3
};
CREATE TYPE weather.station_record (
tmin int, -- tenths of degrees Celsius
tmax int -- tenths of degrees Celsius
);
CREATE TABLE weather.stations (
id text, -- Partition key: Station ID
date date, -- Clustering key: Measurement date
name text static, -- Static: Station name
record station_record, -- UDT: Temperature readings
PRIMARY KEY (id, date)
) WITH CLUSTERING ORDER BY (date ASC);
Design Rationale:
id): Groups all data for a station togetherdate): Enables efficient time-range queriesname): Avoids redundant storage across datesstation_record): Bundles related temperature fieldspython3 ClientStationSchema.py
Returns the Cassandra table definition with all configuration details.
python3 ClientStationName.py USW00014837
Output: MADISON DANE CO RGNL AP
Retrieves station name using partition key query.
python3 ClientRecordTemps.py
Ingests weather data from Parquet files into Cassandra with W=1 consistency.
Sample Output:
Inserted USW00014837 on 2022-01-01 with tmin=-99 and tmax=-32
Inserted USW00014837 on 2022-01-02 with tmin=-166 and tmax=-82
...
python3 ClientStationMax.py USR0000WDDG
Output: 344 (34.4°C)
Returns the highest temperature ever recorded at a station.
ONE (W=1)TWO (R=2)ONE (R=1)Initial State - All nodes healthy:
$ docker exec p6-db-1 nodetool status
UN 172.27.0.4 70.28 KiB 16 64.1% rack1
UN 172.27.0.3 70.26 KiB 16 65.9% rack1
UN 172.27.0.2 70.28 KiB 16 70.0% rack1
Failure Injection:
docker kill p6-db-2
After Failure:
$ docker exec p6-db-1 nodetool status
UN 172.27.0.4 70.28 KiB 16 64.1% rack1
DN 172.27.0.3 70.26 KiB 16 65.9% rack1 # DOWN
UN 172.27.0.2 70.28 KiB 16 70.0% rack1
Writes (W=1): ✅ Continue normally
$ python3 ClientRecordTemps.py
Inserted USW00014837 on 2022-01-01 with tmin=-99 and tmax=-32
# Success - at least one replica available
Reads - Strong (R=2): ⚠️ Cannot achieve quorum
Reads - Available (R=1): ✅ Continue with fallback
$ python3 ClientStationMax.py USR0000WDDG
344 (fallback_to_available)
# Success using degraded consistency
Prepared once in __init__, used many times:
class StationService:
def __init__(self):
# Strong consistency read
self.max_query_strong = self.session.prepare(
"SELECT MAX(record.tmax) FROM weather.stations WHERE id = ?"
)
self.max_query_strong.consistency_level = ConsistencyLevel.TWO
# Available fallback read
self.max_query_available = self.session.prepare(
"SELECT MAX(record.tmax) FROM weather.stations WHERE id = ?"
)
self.max_query_available.consistency_level = ConsistencyLevel.ONE
# High-availability write
self.insert_temp = self.session.prepare(
"INSERT INTO weather.stations (id, date, record) VALUES (?, ?, ?)"
)
self.insert_temp.consistency_level = ConsistencyLevel.ONE
def StationMax(self, request, context):
try:
# Try strong consistency first
result = self.session.execute(
self.max_query_strong,
[request.station]
)
return StationMaxReply(tmax=result[0].max_tmax, error="")
except (Unavailable, NoHostAvailable):
# Fall back to available profile
try:
result = self.session.execute(
self.max_query_available,
[request.station]
)
return StationMaxReply(
tmax=result[0].max_tmax,
error="fallback_to_available"
)
except (Unavailable, NoHostAvailable):
return StationMaxReply(tmax=0, error="unavailable")
# Parse fixed-width station metadata file
stations_df = spark.read.text("ghcnd-stations.txt") \
.selectExpr(
"SUBSTRING(value, 1, 11) AS id",
"SUBSTRING(value, 39, 2) AS state",
"SUBSTRING(value, 42, 30) AS name"
) \
.filter("state = 'WI'")
# Bulk insert into Cassandra
for row in stations_df.collect():
session.execute(
"INSERT INTO weather.stations (id, name) VALUES (?, ?)",
[row.id.strip(), row.name.strip()]
)
docker build -t weather-cassandra .
export PROJECT=weather
docker compose up -d
docker exec weather-db-1 nodetool status
# Wait until all nodes show UN (Up/Normal)
docker exec -w /src weather-db-1 sh -c \
"python3 -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. station.proto"
docker exec -it -w /src weather-db-1 python3 server.py
| Consistency | Healthy Cluster | 1 Node Down | 2 Nodes Down |
|---|---|---|---|
| ONE (R=1) | ~2ms | ~2ms | ~2ms |
| TWO (R=2) | ~4ms | ~4ms | UNAVAILABLE |
| THREE (R=3) | ~6ms | UNAVAILABLE | UNAVAILABLE |
| Consistency | Healthy Cluster | 1 Node Down | 2 Nodes Down |
|---|---|---|---|
| ONE (W=1) | 100% | 100% | 100% |
| TWO (W=2) | 100% | 100% | UNAVAILABLE |
A production-ready demonstration of distributed database design with tunable consistency and fault tolerance.
Continue exploring · 34 projects

Fullstack

ML & AI

ML & AI

ML & AI
Distributed Systems

Fullstack

ML & AI
Distributed SystemsViewing

Distributed Systems
Distributed Systems
Distributed Systems

Data Engineering
Data Engineering

Data Engineering

Data Engineering

Data Engineering

ML & AI
ML & AI
Data Engineering

Fullstack

Fullstack
Fullstack

Fullstack

Fullstack
Data Engineering
Computing Foundations

Fullstack

Fullstack
ML & AI
ML & AI

ML & AI
ML & AI
ML & AI
ML & AI