Skip to content
Edge Computing Architecture — Fog vs Edge, AWS Greengrass, Azure IoT Edge, ML at Edge

Edge Computing Architecture — Fog vs Edge, AWS Greengrass, Azure IoT Edge, ML at Edge

DodaTech Updated Jun 20, 2026 5 min read

Edge computing processes data near its source — on a gateway, industrial PC, or capable microcontroller — instead of sending everything to the cloud. This tutorial covers the architecture patterns, cloud platforms, and ML deployment strategies that make edge computing work in production.

In this tutorial, you’ll learn the edge gateway pattern, how AWS Greengrass and Azure IoT Edge deploy cloud services locally, running ML inference on edge hardware, handling offline operation gracefully, and filtering data to reduce cloud costs. This architecture powers autonomous vehicles, smart factories, and oil rig monitoring where latency and bandwidth are critical.

A factory with 10,000 vibration sensors produces 864 million readings per day. Sending all data to the cloud costs $50,000/month in bandwidth. Edge gateways process 99% of data locally, triggering real-time alerts and sending only aggregated insights — cutting cloud costs by 90% while reducing alert latency from seconds to milliseconds.

Edge vs Fog vs Cloud

    graph TD
    subgraph "Cloud Layer"
        Cloud[AWS / Azure] --> Storage[Data Lake]
        Cloud --> Training[ML Training]
        Cloud --> Dashboard[Global Dashboard]
    end
    subgraph "Fog Layer"
        GW1[Edge Gateway] --> Cloud
        GW2[Edge Gateway] --> Cloud
    end
    subgraph "Edge Layer"
        S1[Sensor Array] --> GW1
        S2[Sensor Array] --> GW2
        S3[Camera] --> GW2
    end
    style Cloud fill:#3498db,color:#fff
    style GW1 fill:#e67e22,color:#fff
    style GW2 fill:#e67e22,color:#fff
    style S1 fill:#27ae60,color:#fff
  
LayerLocationLatencyComputeExample hardware
EdgeOn device<10msVery constrainedESP32, Raspberry Pi Pico
FogLocal network<50msModerateNVIDIA Jetson, industrial PC
CloudData center>100msUnlimitedAWS, Azure, GCP

AWS Greengrass — Lambda at the Edge

AWS Greengrass extends AWS Lambda, device shadows, and MQTT to edge devices. Lambda functions run locally and sync to AWS IoT Core when connectivity is available.

# greengrass_predictive_maintenance.py
import json

THRESHOLD_VIBRATION = 5.0

def lambda_handler(event, context):
    reading = json.loads(event)
    risk = reading['vibration'] / THRESHOLD_VIBRATION
    if risk > 0.7:
        return {'action': 'ALERT', 'severity': 'critical',
                'message': 'Immediate shutdown required'}
    elif risk > 0.4:
        return {'action': 'WARNING', 'message': 'Schedule inspection'}
    return {'action': 'OK', 'message': 'Normal operation'}

Greengrass synchronises device shadows — the edge device’s state in the cloud — even when the device is offline. When connectivity returns, changes sync automatically.

Azure IoT Edge — Modules and Offline Operation

Azure IoT Edge deploys Docker modules to edge devices. Each module runs in a container, communicating via the IoT Edge hub.

# edge_vibration_filter.py — Azure IoT Edge module
import json
import iothub_client

class VibrationModule:
    def __init__(self):
        self.buffer = []

    def process(self, message):
        data = json.loads(message)
        self.buffer.append(data['vibration'])
        if len(self.buffer) >= 10:
            avg = sum(self.buffer) / len(self.buffer)
            self.buffer = []
            return {'average_vibration': avg, 'samples': 10}
        return None  # buffer until we have enough data

Offline Data Flow

class OfflineCache:
    def __init__(self):
        self.queue = []

    def store_offline(self, data):
        self.queue.append(data)
        if len(self.queue) > 10000:
            self.queue.pop(0)  # drop oldest if full

    def sync_on_reconnect(self):
        for data in self.queue:
            self.send_to_cloud(data)
        self.queue.clear()

ML Inference at the Edge

Running ML models on edge hardware requires optimisation. Use quantised models (TensorFlow Lite) and hardware accelerators (GPU, TPU, NPU).

# tflite_edge_inference.py
import tflite_runtime.interpreter as tflite
import numpy as np

interpreter = tflite.Interpreter(model_path="model_quantized.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

def predict(sensor_data: np.ndarray) -> float:
    interpreter.set_tensor(input_details[0]['index'],
                           sensor_data.astype(np.float32))
    interpreter.invoke()
    return interpreter.get_tensor(output_details[0]['index'])[0][0]

# Test with simulated sensor data
data = np.array([[0.5, 0.3, 0.8, 0.1]])
result = predict(data)
print(f"Edge inference result: {result:.3f}")

Expected output:

Edge inference result: 0.872

Common Mistakes

  1. Processing everything at the edge: Filter locally but send raw data periodically for model retraining and auditing.
  2. No offline fallback: Edge devices lose connectivity. Cache data locally and implement a sync-on-reconnect pattern.
  3. Running heavy ML on underpowered hardware: A quantised TFLite model runs on Raspberry Pi 4 at 10fps. The same model on ESP32 takes 30 seconds. Match model size to hardware.
  4. Ignoring model drift: Edge ML models become stale as equipment ages. Implement OTA model updates with A/B testing.
  5. Security blind spot: Edge devices are physically accessible. Encrypt local storage, use secure boot, and disable debug UART in production.

Practice Questions

  1. What’s the difference between edge and fog computing? Edge processes on the device itself (microseconds latency). Fog processes on the local network gateway (milliseconds). Fog spans edge and cloud.

  2. How does AWS Greengrass handle offline operation? Lambda functions run locally, device shadows cache state changes, and synchronisation resumes when connectivity returns.

  3. What data should be filtered at the edge? Filter routine data (normal readings, heartbeats). Send alerts, anomalies, aggregated statistics, and periodic raw samples.

  4. How does model quantisation help edge ML? Quantisation reduces model size from 32-bit floats to 8-bit integers, shrinking models 4x and accelerating inference by 2-3x on edge hardware.

  5. What is the edge gateway pattern? A gateway device sits between sensors and the cloud, translating protocols, filtering data, running local logic, and buffering offline.

Challenge

Build an edge anomaly detector using z-score: collect 100 sensor readings, calculate running mean and standard deviation, flag values with |z| > 3, and send only flagged values to the cloud.

FAQ

Is edge computing just IoT?
No. Edge computing applies to any scenario where local processing matters — autonomous vehicles, CDNs, retail, gaming. IoT is one use case.
Can edge devices run Kubernetes?
Yes. K3s (lightweight K8s) runs on Raspberry Pi 4 and industrial gateways. Azure IoT Edge uses similar container orchestration.
How do you update ML models on edge devices?
OTA model updates — download the new .tflite file, validate its checksum, swap the model file, and reload the interpreter.
What’s the typical power budget for edge AI?
NVIDIA Jetson Nano: 5-10W. Raspberry Pi 4: 3-7W. Intel NUC: 15-28W. Always consider power in edge deployments.
Does edge computing replace the cloud?
No. Edge handles real-time decisions. Cloud handles training, storage, cross-device analytics, and dashboards.

Cross-References

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro