Edge synchronization and recovery
Design a queue before the WAN fails
An edge synchronization pipeline stores outgoing events locally, transmits them when the approved path is available, and removes them only after a trustworthy acknowledgment of durable acceptance. This store-and-forward pattern supports intermittent connectivity, not unlimited offline operation. Use explicit size, time and retention bounds, and a documented overflow policy.
For the fictional factory, the approved exporter creates 50 aggregate records per second, each 400 bytes including its envelope. Assume a constant rate and size for this calculation, no compression, and four hours of outage. Raw telemetry stays in a separate local store. You will calculate queue capacity and catch-up time, distinguish duplicates from conflicting events, and verify a local mock replay. This lesson uses only invented data; it does not control machinery or connect to a real device.
Calculate buffer capacity and recovery time
Ingress = 50 × 400 = 20,000 B/s. Four hours = 14,400 s, so queued data = 288,000,000 bytes = 288 MB (decimal). Add 25% capacity margin: 360 MB. This is a payload-envelope estimate; separately budget database indexes, journal, encryption, backups, filesystem reserve and variable record sizes. A 360 MB usable queue would hold 18,000 seconds (five hours) under these simplified assumptions. Reserve a separate volume budget so telemetry cannot fill the application disk.
After reconnection, suppose measured acknowledged throughput is 80,000 B/s while arrivals continue at 20,000 B/s. Net drain = 60,000 B/s; catch-up time = 288,000,000 / 60,000 = 4,800 s = 80 minutes. If throughput is at or below ingress, backlog cannot shrink. Link bit rate is not application throughput: 640,000 bit/s equals 80,000 B/s only before overhead. The 80,000 B/s assumption represents actual accepted payload throughput, not the contracted circuit rate.
For a burst of 100 records/s over four hours, backlog grows to 576 MB, exceeding the 360 MB budget. Specify what happens on exhaustion: reject new optional aggregate work with an alert, count dropped records, retain required records according to policy, and avoid silently overwriting unacknowledged data. If loss is prohibited, use sufficient durable capacity or an approved upstream backpressure plan. Never describe a finite queue as lossless under an unbounded outage.
Reconcile after reconnection
Use a stable event identity such as (site, stream epoch, sequence) so retries can reuse the same key even after a process restart. A sequence alone can collide across devices or resets. Store event time and ingestion time separately; timestamps can drift and must not be the sole deduplication key. Define schema versions, compatibility and units. Do not overwrite an existing record just because a conflicting payload arrived later.
| State | Action |
|---|---|
| New event accepted durably | Commit event and acknowledgment state atomically at the destination |
| Same key, same canonical payload | Acknowledge duplicate without repeating business effect |
| Same key, different payload | Quarantine or block; investigate conflict |
| Temporary failure or lost acknowledgment | Retain event; retry with capped backoff and jitter |
| Invalid schema or unauthorized destination | Hold/quarantine and alert; do not bypass the policy |
Sender deletion must follow acknowledgment of the destination commit, not a TCP connection or a successful send call. Use a transaction or equivalent durable idempotency design for deduplication and the destination effect. Preserve deduplication state for the supported replay horizon. If a sequence gap remains, request reconciliation or mark a window incomplete; late arrivals may require corrected aggregate versions. For bidirectional state, define ownership and conflict rules explicitly. This example uses one-way immutable events, not last-write-wins mutable state.
Run a local bounded replay model
This independent Python example stores at most three fixed-size illustrative aggregate records, in order of arrival. Each tuple contains a simulated event key and nonnegative integer count. The in-memory destination dictionary stands for a durable idempotent store; it is not actually durable. A lost acknowledgment is simulated after inserting a new value. The export path must be authorized before any transfer. A conflicting value stops the queue for operator review. No sockets, files, real devices, or credentials are used.
def enqueue(queue, event, capacity): if type(capacity) is not int or capacity < 1: raise ValueError("invalid capacity") if (not isinstance(event, tuple) or len(event) != 2 or not isinstance(event[0], str) or not event[0] or type(event[1]) is not int or event[1] < 0): raise ValueError("invalid aggregate") if len(queue) >= capacity: return "full" queue.append(event) return "queued"
def sync_one(queue, accepted, authorized=True, lose_ack=False): if not authorized: return "blocked" if not queue: return "empty" key, count = queue[0] duplicate = key in accepted if duplicate and accepted[key] != count: return "conflict" if not duplicate: accepted[key] = count if lose_ack: return "retry" queue.pop(0) return "duplicate" if duplicate else "accepted"
queue, accepted = [], {}for event in [("site-a:epoch1:1", 4), ("site-a:epoch1:2", 7)]: enqueue(queue, event, 3)print(sync_one(queue, accepted, authorized=False), len(queue))print(sync_one(queue, accepted, lose_ack=True), len(queue))print(sync_one(queue, accepted), len(queue))print(sync_one(queue, accepted), len(queue))print(sum(accepted.values()))Expected output:
blocked 2retry 2duplicate 1accepted 011The first event remains queued after the acknowledgment is lost. Replaying it finds the original key, removes it on acknowledgment and does not add another four to the total. The second event adds seven, giving 11. The model assumes prevalidated approved aggregate inputs, a single consumer, fixed record size and no crashes. The boolean authorization input is a teaching stand-in for actual identity and policy checks. A production system needs durable atomic updates, authenticated transport, authenticated acknowledgment, schema validation, bounded retry, persistent queue and audited quarantine. Python list operations here are suitable only for tiny examples.
Observe health without inventing success
Measure queue bytes and count, age of oldest pending event, disk free space, rejected and quarantined counts, accepted throughput, acknowledgment latency, duplicate count, sequence gaps and freshness of regional summaries. Alert locally if the WAN is unavailable; the regional monitor must distinguish silence from zero events. Keep operational logs free of sensitive raw data. Greengrass stream manager is one example of a provider component that supports local data streams and configurable export behavior; check its configured limits rather than assuming this Python model matches its protocol.
After recovery, reconcile source accepted-for-export count = acknowledged unique events + pending unique events + explicitly accounted rejected or quarantined unique events for the same cohort. Distinguish duplicate delivery attempts from distinct records. Validate the regional aggregate against the approved source records and record the time window, incomplete partitions and any corrected version. Confirm the local queue drains without exceeding capacity or exporting forbidden fields.
Practice: exhaust the queue and lose an acknowledgment
Run the example in a local Python interpreter. With capacity two, enqueue three distinct approved aggregate events; the third must return full and leave two pending. Simulate lost acknowledgment on the first, replay it, then drain the second. Try an existing key with a different count; the conflict must leave the pending record unchanged and preserve the original accepted value. Try an unauthorized export and verify that neither structure changes.
For a six-hour outage at the same rate, compute 432 MB backlog and 540 MB with 25% margin. If measured accepted throughput is 50,000 B/s, net drain is 30,000 B/s, so 432 MB needs 14,400 s (four hours) to catch up. Explain how retention, credential validity and spare disk capacity must cover both the outage and catch-up interval. Reset by discarding the local lists and dictionaries. No actual edge hardware or industrial commands are needed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Edge synchronization and recovery — knowledge check
Choose the best answer for each offline scenario.
At 20,000 B/s, how much data accumulates in four hours?
Ingress is 20,000 B/s and acknowledged throughput is 80,000 B/s. What is net drain?
When may the sender remove a pending event?
The same key arrives with a different payload. What should the example do?
What if accepted throughput equals incoming throughput?