Edge Computing Tutorial: Learn Distributed Computing from Scratch (2026)
After deploying compute at a wind farm 50 miles offshore, I became convinced that the cloud is not the answer to every problem. Edge computing pushes processing closer to where data is generated, reducing latency, bandwidth costs, and reliance on constant connectivity. This tutorial covers what happens when you move logic from a centralized data center to the literal edge of the network.
You will learn about edge architectures, deploy a simple inference pipeline on a Raspberry Pi, and understand when edge makes sense versus cloud or hybrid. The trade-offs are not technical alone — they include operational complexity, physical security, and update strategies.
Edge vs. Fog vs. Cloud
The cloud is a centralized data center with near-infinite resources and high latency. The edge is the device itself — a sensor, a camera, a Raspberry Pi. Fog computing sits in between: a local gateway or micro data center that aggregates several edge devices before sending data to the cloud. Each layer trades capability for proximity.
In practice, most architectures are hybrid. A temperature sensor (edge) sends raw readings to a local gateway (fog) which runs anomaly detection and forwards only outliers to the cloud. This cuts cloud bandwidth by orders of magnitude while keeping the heavy ML training where the GPUs live.
import time, json, random
def read_sensor():
return {'temp': 22.5 + random.gauss(0, 0.5), 'humidity': 60 + random.gauss(0, 2), 'ts': time.time()}
def is_anomalous(reading, baseline=22.5, threshold=5.0):
return abs(reading['temp'] - baseline) > threshold
def send_to_cloud(reading):
if is_anomalous(reading):
print(f'ALERT sending to cloud: {json.dumps(reading)}')
ML Inference on Edge Devices
Deep learning models designed for data center GPUs will not run on a 1 GHz ARM Cortex. The key optimization is quantization: reducing model weights from 32-bit floats to 8-bit integers. TensorFlow Lite, ONNX Runtime, and PyTorch Mobile all support post-training quantization that shrinks model size by 4x with negligible accuracy loss.
For vision models, also consider input resolution — 640x480 may be fine for a cloud API, but 224x224 often suffices for edge use cases. Pruning and knowledge distillation are advanced techniques worth exploring after baseline quantization.
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_types = [tf.float16]
tflite_model = converter.convert()
interpreter = tf.lite.Interpreter(model_content=tflite_model)
interpreter.allocate_tensors()
MQTT and Intermittent Connectivity
Edge devices frequently lose connectivity — think of a farm tractor in a valley or a shipping container in the middle of the ocean. Protocols must handle disconnection gracefully. MQTT is the de facto standard: a publish-subscribe protocol designed for unreliable networks with minimal bandwidth overhead (2-byte header minimum).
The broker caches messages for disconnected subscribers depending on QoS level. QoS 0 is fire-and-forget, QoS 1 guarantees at-least-once delivery, and QoS 2 guarantees exactly-once. For sensor data, QoS 0 or 1 is typically sufficient.
import paho.mqtt.client as mqtt
client = mqtt.Client(client_id='edge_sensor_01')
client.connect('fog-gateway.local', 1883, 60)
client.publish('sensors/temperature', payload='22.5', qos=1)
def on_message(client, userdata, msg):
print(f'Command received: {msg.topic} {msg.payload}')
client.on_message = on_message
client.subscribe('actuators/relay_01', qos=1)
Orchestration with K3s
Managing hundreds of edge devices by SSH is not viable. K3s is a lightweight Kubernetes distribution (binary under 100 MB) designed for resource-constrained devices. It replaces etcd with SQLite by default, removes legacy alpha features, and supports ARM64 natively — making it a perfect fit for Raspberry Pi clusters or industrial gateways.
Deploying workloads via GitOps (Argo CD or Flux) ensures that edge nodes self-heal: if a device is wiped and reimaged, it pulls the correct manifest from git and re-creates all containers.
apiVersion: apps/v1
kind: Deployment
metadata:
name: edge-inference
spec:
replicas: 1
selector:
matchLabels:
app: edge-inference
template:
metadata:
labels:
app: edge-inference
spec:
containers:
- name: inference
image: myregistry/edge-model:1.2
ports:
- containerPort: 8080
resources:
limits:
memory: "256Mi"
cpu: "500m"
Offline-First Data Sync
Edge devices cannot assume they are online. Offline-first means the device operates normally with local storage and syncs when connectivity returns. Conflict resolution is the hard part: if two devices modify the same record while disconnected, which version wins? Last-writer-wins using wall-clock timestamps is simplest but error-prone.
CRDTs (Conflict-free Replicated Data Types) provide automatic conflict resolution without a central coordinator. A simple counter CRDT uses max() to merge; a set CRDT uses union. For more complex state, CouchDB's multi-master replication is battle-tested.
import sqlite3, json, requests
local_db = sqlite3.connect('edge_store.db')
def process_locally(data):
local_db.execute('INSERT INTO readings VALUES (?, ?, ?)',
(data['ts'], data['temp'], data['humidity']))
local_db.commit()
queue_sync(data)
def sync_with_cloud():
pending = local_db.execute('SELECT * FROM sync_queue').fetchall()
for row in pending:
try:
resp = requests.post('https://cloud.example.com/ingest', json=row, timeout=5)
if resp.ok:
local_db.execute('DELETE FROM sync_queue WHERE id = ?', (row[0],))
local_db.commit()
except requests.ConnectionError:
break
Physical Security and Remote Mgmt
An edge device in a remote cabinet is physically accessible to anyone with a screwdriver. Full-disk encryption (LUKS on Linux, BitLocker on Windows) prevents data extraction from stolen storage. A TPM (Trusted Platform Module) binds the encryption key to the device's hardware, making it useless if removed.
Remote management via a VPN-less approach — Cloudflare Tunnel, Tailscale, or AWS IoT Device Defender — avoids opening inbound ports. Use hardware watchdog timers to automatically reboot hung devices.
# Enable LUKS encryption on Raspberry Pi
# sudo cryptsetup luksFormat /dev/mmcblk0p2
# sudo cryptsetup open /dev/mmcblk0p2 cryptroot
# Tailscale for management
# curl -fsSL https://tailscale.com/install.sh | sh
# sudo tailscale up --authkey=tskey-...
Frequently Asked Questions
How much compute do I need at the edge?
It depends entirely on the workload. A temperature sensor needs a microcontroller with KB of RAM. Real-time video inference needs a Jetson Nano or Google Coral (~4 GB RAM, ~1 TOPS). Start with the minimum that meets your latency requirement and iterate.
How do I update edge device software without breaking things?
Use A/B update partitions (e.g., Mender or balenaOS): one active partition runs while the other is updated. If the new update fails to boot, the device rolls back automatically. Combine with canary deployments.
What is the best way to connect edge devices to the cloud?
Use a bidirectional, encrypted, connection-oriented protocol. MQTT over TLS is ideal for telemetry, gRPC for streaming, and AWS IoT Core or Azure IoT Hub for managed fleets. Avoid polling-based HTTP from devices.
How do I handle device authentication?
Each device should have a unique X.509 certificate provisioned at manufacturing time. The certificate is used for TLS mutual authentication with the cloud gateway. Certificates can be revoked individually if a device is compromised.
Originally published on Ayodhyyya. Last updated June 1, 2026.