5. Edge Computing & Buffering

Summary: when connectivity is flaky or bandwidth is tight, the edge (meter or gateway) must keep proof moving. That means build windows locally, canonicalize to JSON, sign the bytes, and store-and-forward through a durable queue until ingestion succeeds—without ever creating overlapping windows or replaying data.

What the edge must guarantee

Edge software (on the meter or a site gateway) is responsible for four things:

  1. Window assembly — aggregate raw samples into a single window with start_ts, end_ts, quantity_wh and a unique batch_id per device.

  2. Canonicalization — emit the exact canonical JSON (sorted, minified, fixed units) used to compute evidenceHash.

  3. Signing — sign the canonical JSON bytes (or their SHA-256) with the device key; attach signature in headers.

  4. Durable queue — persist the canonical payload and headers; retry with backoff until the server acknowledges, ensuring idempotency on batch_id.

If any of those fail, do not send. Fix locally, then continue.

Window building

A window is valid when the tuple (device_id, start_ts, end_ts) is strictly increasing and quantity_wh is non-negative. Do not produce overlapping windows. If samples are missing, close the window with what you have, set samples count, and include source_file_hash if you aggregated from exports.

To avoid accidental overlaps, keep the last committed end_ts on disk and start the next window at exactly that value.

Store-and-forward (how buffering works)

When online, send immediately. When offline, write the canonical JSON plus headers to a disk queue. On retry, send the same bytes and the same batch_id. This guarantees idempotency: the server will accept a duplicate only if the bytes are identical.

For time skew handling during outages, include both X-Timestamp (current ms) and X-Orig-Timestamp (ms when the window first closed). The server can apply standard skew to X-Timestamp and relaxed policy to X-Orig-Timestamp.

Security at the edge

Encrypt the local queue at rest. Bind a device certificate to device_id at commissioning. Sign every submission with that key; rotate keys under policy and revoke compromised ones. Keep a tamper-evident log (monotonic counter with hash chain) so you can prove the order of queued windows.

Backoff and backpressure

Use exponential backoff with jitter. Respect a maximum retry period. If the queue grows beyond a threshold (for example, more than N windows or oldest older than T minutes), switch to reduced sampling or shorter windows to lower loss risk, but never violate canonical rules or overlap constraints.

Pseudocode (TypeScript): durable, idempotent queue

This keeps the canonical JSON and batch_id stable (idempotent), updates only X-Timestamp on retry, and never mutates content that would change evidenceHash.

Minimal fields to persist per queued window

Store at least: canonical_json, batch_id, device_id, start_ts, end_ts, quantity_wh, nonce, x_orig_timestamp, signature, and a seq_no (monotonic). With those, you can prove what was produced and in which order.

Health signals to expose

Export simple counters: queue depth, oldest age, send success rate, average retries, overlap rejects, signature failures, and end-to-end latency (window close to server accept). These let you alert before data loss.

Conformance

Assemble windows without overlap; write canonical JSON; compute evidenceHash locally; sign canonical bytes; persist to an encrypted queue; retry with backoff and idempotency on batch_id; send both X-Timestamp and X-Orig-Timestamp; never mutate canonical bytes after enqueue; if the queue grows too large, degrade sampling but keep all rules intact.

Drawing

Last updated