Three-Tier Edge Design Exercise
Three-Tier Edge Design Exercise
animation
edge
analytics-ml
Try It Yourself
TipThree-Tier Edge Design Exercise
Scenario: A pharmaceutical cold chain monitoring system tracks 50 refrigerated trucks, each with 20 temperature sensors sampling at 1 Hz.
Your Task: Design the architecture for Levels 1-4:
Level 1 (Devices): What sensors are needed? What’s the data format?
Level 2 (Connectivity): Which protocol (Bluetooth, LoRaWAN, cellular)? Why?
Level 3 (Edge Gateway): Apply the five functions:
- Evaluation: What threshold values trigger alerts?
- Formatting: Design the standardized data schema
- Distillation: Calculate data reduction ratio (1 Hz raw to what summary?)
- Assessment: What local actions (alarms, door locks)?
- level 4 (Storage): What retention policy (hot/warm/cold tiers)?
What to Observe:
- Compare bandwidth costs: raw 1 Hz data vs edge-processed summaries
- Calculate alert latency: edge detection vs cloud detection
- Consider offline operation: what happens during cellular dead zones?
Starter Code (Python simulation):
import time
import statistics
class ColdChainEdgeGateway:
def __init__(self, truck_id, num_sensors=20):
self.truck_id = truck_id
self.buffer = []
self.alert_threshold_max = 8.0 # degrees C
def evaluate(self, reading):
"""Level 3: Evaluation - check data quality"""
return 2.0 <= reading <= 10.0 # Valid range
def format(self, sensor_id, temp_c):
"""Level 3: Formatting - standardize schema"""
return {
"truck_id": self.truck_id,
"sensor_id": sensor_id,
"temp_celsius": round(temp_c, 1),
"timestamp_utc": time.time()
}
def distill(self, readings_1min):
"""Level 3: Distillation - 60 readings to 4 summary values"""
return {
"min": min(readings_1min),
"max": max(readings_1min),
"avg": statistics.mean(readings_1min),
"stddev": statistics.stdev(readings_1min)
}
def assess(self, temp_c):
"""Level 3: Assessment - trigger local alarm"""
if temp_c > self.alert_threshold_max:
print(f"ALERT: Truck {self.truck_id} temp {temp_c} C exceeds 8 C")
return True
return False
# Test the gateway
gateway = ColdChainEdgeGateway("TRUCK-042")
readings = [5.2, 5.3, 5.1, 8.5, 8.9, 9.2] # Temperature excursion!
for i, temp in enumerate(readings):
if gateway.evaluate(temp):
formatted = gateway.format(sensor_id=1, temp_c=temp)
gateway.assess(temp)
gateway.buffer.append(temp)
summary = gateway.distill(gateway.buffer)
print(f"1-minute summary: {summary}")
print(f"Data reduction: {len(gateway.buffer)} readings to 4 values")Extension Challenge: Add Level 4 storage with tiered retention (last hour = raw data, last week = hourly summaries, beyond = daily aggregates).