OpenGXT homePlan a pilot line
Menu

Store and forward at the edge when the internet drops

The reader questionWhat happens to machine data when the plant loses its internet connection, and how should the edge buffer and backfill it?

A full wooden rain barrel under a downspout beside a green machine, a tiny worker opening its tap so the stored water flows down a channel toward a garden bed.

When a plant’s internet connection drops, machine data survives only if something on the plant side keeps it. MQTT sessions protect messages already in flight during short disconnects, a disk buffer on the edge gateway (store and forward proper) carries data through outages of hours or days, and history kept at the source (a PLC counter or an on-site historian) covers whatever the gateway itself missed. Size the disk buffer for the longest outage you plan for, replay it in order with the original timestamps, mark replayed values as historical, and prove the design by disconnecting the uplink on purpose.

Those three mechanisms are often described as one feature called “store and forward,” and that is where data goes missing. This article separates them, shows how to size and drain a buffer, explains what the MQTT and Sparkplug specifications do and do not define, and ends with a test plan you can run before go-live.

When the uplink drops, the machines keep running and the gateway keeps reading them; what changes is where each new value goes. Without a buffer that writes to disk, values read during the outage have nowhere to go and are lost, and the hosted application shows a gap in every chart and report that covers the period.

Follow one value through a hypothetical outage. The gateway reads the filler’s good count at 11:30:00 and publishes it to the broker in the cloud. At 11:30:04, a router upstream fails, but the gateway does not know that yet. TCP connections can stay apparently open for a while after the path has gone, and the gateway’s MQTT client discovers the loss only when a send fails or a keep-alive check goes unanswered.

MQTT 5.0 sets that check. If the server does not hear from a client “within one and a half times the Keep Alive time period,” it must close the connection. On the client side, if a ping goes unanswered “within a reasonable amount of time,” the client should close it. With a 60 second keep-alive, tens of seconds of messages can be written into a connection that no longer leads anywhere.

From then on, three different things can be in trouble, and each needs its own answer:

  • Messages already sent but not yet acknowledged. MQTT’s quality of service levels and session state handle these.
  • Values read after the gateway knows the link is down. Only a buffer on the gateway, ideally on disk, can hold these.
  • Values the gateway never read at all, because it was rebooting, powered off or itself the failed part. Only the source (a PLC counter, a device’s own log or an on-site historian) still has these.

Which part failed changes the answer

The failed part is not always the internet link. The broker, the hosted application or the gateway itself can each be the one that stops, and a good design says what happens in each case:

What stopped What the gateway sees What keeps the data
Plant internet link or router Connection lost, keep-alive unanswered Gateway disk buffer
Cloud broker Connection refused or dropped Gateway disk buffer
Hosted application or historian Broker still accepts messages Gateway buffer, if the gateway can tell the consumer is offline; otherwise only the broker’s queue for that subscriber, within its limits
Gateway (restart, power cut, hardware fault) Nothing, because it is not running Source-side history and counters
Link between gateway and machine Read timeouts Nothing to buffer: publish bad quality and rely on source counters

The network side of the design, with outbound-only connections from the plant, is covered in connecting plant equipment to the cloud with outbound-only links. This article is about data completeness.

Three mechanisms that vendor documents blur

Store and forward is not one feature but three mechanisms that cover different time spans and different failures. MQTT sessions cover seconds to minutes of in-flight messages, a gateway disk buffer covers hours to days of new data, and source-side history covers what the gateway never saw.

MQTT QoS and persistent sessionsGateway disk buffer (store and forward)Source-side history
What it protectsQoS 1 and 2 messages sent but not yet acknowledgedEvery value read while the uplink or the consumer is unavailableValues the gateway never read: counters, device logs, on-site historian records
Defined byThe MQTT standard (OASIS)The gateway software; no MQTT or Sparkplug rule defines itThe PLC program, device or historian (for example, OPC UA Historical Access)
Typical spanSeconds to minutesHours to days, set by disk sizeAs long as the source keeps it
Where data livesClient and server session state, often in memoryA file or database on the gateway's diskThe controller, device or historian
Survives a gateway rebootOnly if the client stores session state on diskYes, if written to disk before sendingYes, independent of the gateway
Main riskMistaken for a buffer for new dataUndersized, fills and drops data, or replays out of orderShort retention, or no timestamps on the stored values
How the three mechanisms divide the work. Sources: OASIS MQTT 5.0 and 3.1.1, section 4.1 (session state); Eclipse Sparkplug specification, chapters 5 and 6; OPC 10000-11. Typical spans are the article's characterization, not figures from the standards.

A design needs all three to be complete, because each covers a hole the others leave. A plant that relies on MQTT sessions alone loses an afternoon’s data during an afternoon’s outage. A plant that relies on a gateway buffer alone loses whatever happened while the gateway was rebooting. A plant that relies on source history alone usually has it for counters but not for states, temperatures or fault codes.

What MQTT sessions cover, and where they stop

MQTT’s quality of service and persistent sessions make delivery reliable across short disconnects, for messages that were already handed to the protocol. They do not define a queue for values a client creates while it is disconnected, so they are not a substitute for a disk buffer.

The three QoS levels

MQTT defines three levels. QoS 0 is “at most once”: “no response is sent by the receiver and no retry is performed by the sender.” QoS 1 is “at least once,” acknowledged by a PUBACK, so a message can arrive twice. QoS 2 is “exactly once,” with a two-step handshake. For telemetry, QoS 0 means that anything in transit when a link fails is gone; QoS 1 means it is retried, and the receiver must tolerate duplicates.

What session state holds

Section 4.1 of the standard lists what a session keeps. The session state in the client consists of “QoS 1 and QoS 2 messages which have been sent to the Server, but have not been completely acknowledged,” plus QoS 2 messages received but not completely acknowledged. That is the whole list. Values the gateway reads after the connection is gone are not in it.

The server side holds more: the client’s subscriptions, messages pending delivery to that client, and “OPTIONALLY QoS 0 messages.” That matters for subscribers such as a hosted application that briefly disconnects from the broker. It does not help a gateway that cannot reach the broker at all.

Clean Start and Session Expiry

In MQTT 5.0, a session lasts “as long as the latest Network Connection plus the Session Expiry Interval.” If the interval is 0 or absent, “the Session ends when the Network Connection is closed.” A gateway that wants its unacknowledged QoS 1 messages resent after a reconnect must connect with Clean Start set to 0 and a non-zero Session Expiry Interval. In MQTT 3.1.1, the same behavior comes from CleanSession set to 0.

Storage is the implementation’s problem

The standard is candid about limits. A non-normative comment says that “the storage capabilities of Client and Server implementations will of course have limits in terms of capacity,” that stored state can be discarded by administrator action, and that “hardware or software failures may result in loss or corruption of Session State.” Its own examples contrast an electricity meter reading application that might accept session data in volatile memory with a payment application that writes all data to non-volatile memory before transmitting.

Plant data usually sits closer to the payment case than its designers assume. If a shift report, an energy bill check or a quality record depends on the values, keep them on disk.

Client library queues

If the gateway’s MQTT client library offers an “offline queue” that accepts publishes while disconnected, treat it as a library feature, not part of the standard. Ask three questions of it: is it in memory or on disk, how large is it, and what does it drop when full. An in-memory queue disappears with the first power cut or software restart.

Message expiry

MQTT 5.0 also has a Message Expiry Interval: if it passes before the server starts delivery to a subscriber, the server “MUST delete the copy of the message for that subscriber.” Expiry suits commands and live alarms that are useless when stale. Leave it off for historical telemetry, or a long outage on the subscriber side can quietly delete backfill.

How a disk buffer on the gateway works

A gateway disk buffer writes every value to local storage before it tries to send it, and deletes it only after the broker acknowledges receipt. While the uplink is down the buffer grows; when the link returns, the gateway drains it in order alongside live data.

A buffer that does the job has six properties. Check each one in the gateway’s documentation or configuration:

  1. Write first, send second. Each value goes to disk with its original timestamp before the first send attempt. A buffer that only starts writing after the gateway detects an outage misses the seconds before detection.
  2. Delete on acknowledgment. A record leaves the buffer only after a QoS 1 PUBACK (or the equivalent for another protocol) confirms the broker has it. Deleting on send loses whatever was in flight when the link failed.
  3. Survive a reboot. The buffer is a file or an embedded database on persistent storage, and the gateway resumes from it after a power cut. Test this; do not assume it.
  4. Bounded size and a stated policy when full. The buffer has a configured maximum. When it fills, it either drops the oldest records or stops accepting new ones, and it raises an alarm either way. The choice belongs in the connection plan.
  5. Rate-limited drain. On reconnect, the backlog goes out at a set rate so it does not starve live data or saturate the plant’s uplink.
  6. Visible depth. The buffer’s size and the age of its oldest record are published as gateway health metrics, so someone can see an outage building before the buffer fills.

Live data during the drain

When the link returns, there are two streams: the backlog, oldest first, and new live values. If the gateway sends the backlog first and holds live data behind it, dashboards stay hours behind for the length of the drain. If it sends both at once, consumers receive old and new values interleaved.

A practical answer is to send live values on their normal topics as they arrive and send the backlog alongside them at a capped rate, with each replayed value marked as historical. Consumers that only want the current state can then ignore the backlog, and historians can store both.

A buffer on the gateway, or a broker in the plant

Some designs place an MQTT broker inside the plant and bridge it to a broker in the cloud. Local applications keep working during an outage, and the bridge’s outgoing queue becomes the buffer. Nothing changes in principle: the six properties above apply to that queue, and you need to know whether it is on disk, how large it is and what it drops when full. A plant broker adds a component to patch and monitor, so choose it for the local consumers it serves, not only for buffering.

Sometimes the uplink is fine but the hosted application or historian is not. The broker may accept messages that nobody stores. Sparkplug handles this with the Primary Host Application’s STATE message; plain MQTT needs a health signal from the consumer that the gateway can watch. Either way, a gateway that can see its consumer is offline should buffer rather than publish into a void.

How big the buffer needs to be

Size the buffer from the values per second the gateway produces, the bytes each buffered record takes, and the longest outage you intend to ride through, then add headroom. Then check the other side: how long the backlog takes to drain once the link is back.

The arithmetic is short:

Quantity Formula
Values per second Tags × (1 ÷ sample interval) × share kept after deadband
Buffer size Values per second × bytes per buffered record × outage seconds × headroom
Drain time Backlog values ÷ (forwarding rate − live values per second), or backlog ÷ the backlog’s own rate cap if live data travels separately

The first line is the same calculation the data volume estimator runs. Its default example, 400 tags sampled every second with 20% kept, produces 80 values per second and 110.6 MB per day before compression at 16 bytes per value. That is the floor for a buffer that stores compact records.

Bytes per record matter more than people expect

A buffer that queues whole MQTT messages stores far more than 16 bytes per value. Each record carries a topic name, a JSON payload with a value, unit, timestamp and quality, and the gateway’s own bookkeeping. Find the real figure by filling the buffer for an hour in a test and dividing its size by the number of values. It can easily be several times the compact figure.

Example (fictional). A fictional packaging plant’s gateway produces 80 values per second, as in the estimator’s default example. Each buffered record is a JSON MQTT message of about 150 bytes, measured during commissioning. The plant decides to ride through a 72-hour outage, because a link that fails on a Friday evening may not be repaired until Monday.

  • Per day: 80 × 86,400 × 150 bytes = 1,036.8 MB, about 1.04 GB.
  • For 72 hours: about 3.11 GB.
  • With headroom of two times, for growth and for records that compress poorly: about 6.2 GB allocated.
  • Backlog after 72 hours: 80 × 259,200 seconds = 20,736,000 values. Drained at a cap of 800 values per second (about 0.96 Mbit/s at 150 bytes each), alongside live data, it takes 25,920 seconds: 7.2 hours.

The drain time is the number people forget. For those 7.2 hours, the hosted reports for the outage period are incomplete, and anyone reading them needs to know that.

Uplink down for 72 hours Buffer allocated: 6.2 GB 3.1 GB at reconnect Drained in 7.2 h 0 2 4 6 8 GB 0 24 48 72 96 Hours
Fictional example: 80 values per second at about 150 bytes per buffered record, a 72-hour outage starting at hour 12, and a backlog drained at 800 values per second. Calculated for this article; the values-per-second input matches the data volume estimator's default example.

A small line needs a small buffer, but still a tested one

Not every gateway serves 400 tags. A single line with ten signals, most published on change, may produce two or three values per second, and a day of outage fits in a few tens of megabytes even as JSON messages. Size is rarely the problem at that scale. The weak points are the other properties: a buffer that lives in memory, a drain that blocks live data, or timestamps taken at send time. Small buffers fail the same tests large ones do, so run the same outage test regardless of size.

Choosing the outage to plan for

Pick the longest outage you are willing to ride through without losing data, not the average. Ask who repairs the link, and when: a fiber cut on a holiday weekend lasts longer than a router reboot. If the plant has a service-level target from its internet provider, the uptime SLA calculator shows what it allows; 99.9% over 30 days still permits 43.2 minutes of downtime. That figure is a monthly total, though, not a cap on a single outage, so do not size a buffer from it.

Storage the gateway can actually sustain

Check that the gateway’s storage is rated for sustained writes, and that the buffer cannot fill the partition the operating system needs. A buffer on the same small flash card as the logs and the operating system can turn a long outage into a gateway that stops entirely.

Replaying in order with the original timestamps

Every value should carry the time it was read at the source, set by a synchronized clock, and that timestamp, not the arrival time, decides where the value lands in history. Replay oldest first, and make the receiving side ignore duplicates.

Timestamp at acquisition

A value read at 11:31:15 and delivered at 19:02:40 must be stored at 11:31:15. That only works if the gateway attaches the timestamp when it reads the value and the receiving side stores that field. Sparkplug draws the same line: the payload timestamp “represents the time at which the message was published,” while each metric’s timestamp represents “the time at which the value of a metric was captured,” and both must be in UTC.

Keep the clock honest during the outage

Gateways usually keep time with the Network Time Protocol, specified in RFC 5905. If the gateway’s only time servers are on the internet, it loses its reference at the same moment it starts buffering, and its clock runs free for the whole outage. Give it a time source inside the plant, such as a local NTP server, and log the clock offset when the link returns, so any correction can be traced.

Ordering and duplicates

MQTT promises ordering within limits. A client that re-sends QoS 1 or 2 messages “MUST re-send them in the order in which the original PUBLISH packets were sent,” and by default a server treats every topic as an “Ordered Topic” when forwarding. The standard also gives an example of the limit: a publisher sends messages 1, 2, 3, 4 and, after a network disconnection, the subscriber may receive “1,2,3,2,3,4.”

So duplicates are normal after a reconnect, and the receiving side has to handle them. Store each value under a key of signal name plus source timestamp, and treat a second arrival with the same key as the same value. Setting Receive Maximum to 1 limits a connection to one message in flight and avoids that kind of reordering, but it also caps throughput, which hurts during a long drain.

Sequence numbers show what is missing

Timestamps say when a value was read; sequence numbers say whether anything is missing. Sparkplug puts a seq number from 0 to 255 in every NBIRTH, DBIRTH, NDATA and DDATA message, each one more than the last and wrapping to zero after 255. A host application that receives sequence numbers 1, 2 and 4 starts a “Reorder Timeout”; if 3 does not arrive in time, it should send a rebirth request so the edge node republishes its full state.

The specification leaves the rest to the application developer and notes that “a time series database may want to insert all data that arrives regardless of the message order.” That is the right default for a historian receiving backfill. In plain MQTT, a gateway can add its own per-topic or per-connection sequence field to the payload for the same purpose.

Counters instead of increments

Publish counters as absolute values (total good count, total kWh), never as increments since the last read. If a value is lost, duplicated or replayed late, the difference between any two absolute readings is still right. The same advice applies to the Modbus side of a gateway, as described in bridging Modbus devices to MQTT without losing meaning.

Marking backfilled values: Sparkplug is_historical and plain MQTT

A replayed value should say that it is historical, so consumers that act on current values (alarms, andon boards, live OEE) do not treat an eight-hour-old reading as news. Sparkplug 3.0 defines a flag for this; plain MQTT needs a convention you write down.

What Sparkplug 3.0 defines

The Eclipse Foundation released Sparkplug 3.0, dated October 21, 2022. Its payload chapter defines is_historical as “a Boolean flag which denotes whether this metric represents a historical value,” used when metrics are sent after they were acquired, “for batching, store and forward, or sending local backup data during network communication loses.” The flag “denotes that the message should not be considered a real time/current value.”

Sparkplug also defines when an edge node should hold data back. An edge node can be configured with a Primary Host Application and must check that host’s STATE message before publishing its birth certificates. The introduction describes the intended behavior: “an Edge Node may store data at the edge until a Primary Host Application comes back online,” then “flush any historical data that it may have stored while offline.”

What Sparkplug leaves to the implementation

The specification stops there. It says an edge node may store data, defines the flag that marks it, and requires metric values in each payload to stay in chronological order where is_historical is false. It does not define the buffer: its format, its size, its drain rate or what happens when it fills. Those are properties of the gateway software, and you should test them like any other.

One more detail matters for planning. Sparkplug requires NDATA and DDATA messages to be published at QoS 0, so MQTT retries do not protect them. Data completeness in Sparkplug comes from sequence numbers, birth and death certificates, and the edge node’s own store and forward, not from MQTT QoS. The trade-offs between Sparkplug and a plain JSON convention are compared in Sparkplug B or plain MQTT for plant data.

A plain MQTT convention

Without Sparkplug, pick one of two conventions and document it in the data dictionary:

  • A flag in the payload, such as "historical": true, on the same topic as live values. Simple, but every consumer must read the flag.
  • A separate topic branch, such as .../line-2/filler/good-count/backfill. Live subscribers never see the backlog, and a historian subscribes to both.

Either way, the consumer rules are the same. Live screens and alarms ignore historical values. The historian stores them under their source timestamps. Shift reports for the affected period are recalculated once the drain completes.

When the gateway itself is the gap: source-side history

A disk buffer cannot hold what the gateway never read. For the minutes when the gateway is rebooting, being replaced or powered off, the only copy is at the source, so decide in advance which values you can recover from there.

Counters make totals recoverable

A PLC counter that keeps counting while the gateway is down lets you recover the shift total, even though the minute-by-minute shape of that period is gone. The same holds for energy meters with cumulative kWh registers and run-hour counters. When you survey a line, note which important values exist as cumulative counters at the source; those are the ones a gap cannot corrupt.

Historians and OPC UA Historical Access

Where the plant already runs an on-site historian, the gateway or the hosted application can fill a gap from it. OPC UA Part 11, Historical Access (release 1.05.04, published October 15, 2024) defines how historical time series and events are represented and read. It also expects historians to receive data from other sources: data that “is typically provided in bulk and with SourceTimestamps that are in the past” can be inserted through a history update, without the historian creating a modification record for the initial insertion.

In practice, after an outage the gateway reads raw history for the gap window from the on-site historian and forwards it, marked historical, just like its own backlog.

What cannot be recovered

States, fault codes and temperatures that are only read live, and never logged at the source, are gone for the period the gateway was down. Say so in the data dictionary, and have the hosted application mark that period as “no data” rather than drawing a straight line across it.

What the hosted application must do with late data

A buffer only helps if the receiving side accepts late data correctly. The hosted application has to store values by source timestamp, drop duplicates, recalculate affected reports and show which periods are still incomplete.

Check these behaviors when you choose or build the cloud side, as part of cloud hosting or any other arrangement:

  • Insert by source timestamp. Late values land in the past, not at the arrival time.
  • Idempotent writes. Signal name plus source timestamp is a unique key; repeats are ignored.
  • Recalculation. Shift totals, OEE, downtime and energy per unit for the affected periods are recomputed when backfill arrives, and the report shows when it was last recalculated.
  • Completeness markers. A shift with buffered data still in transit shows as incomplete, rather than showing a low output figure that someone acts on.
  • Stale markers on live screens. When the gateway’s connection drops (in Sparkplug, its NDEATH message, sent as the MQTT Will), live screens grey out instead of freezing on the last value.

OpenGXT configures its gateways to store and forward: the gateway buffers data while the internet connection is down and sends it when the connection returns. The buffer settings and the test results go into the machine connectivity documentation for each line, so the plant can see what was configured and tested.

The only proof that store and forward works is an outage you cause yourself, with the line running, followed by a check that every value arrived once, in order, with its original timestamp. Run it before go-live and again after any gateway software update.

A test plan that covers all three mechanisms:

  1. Baseline. Record the source counters (good count, reject count, kWh) and the buffer depth at the start.
  2. Disconnect. Block the gateway’s uplink at the switch or firewall for a set time, during production, with the line’s supervisor informed.
  3. Watch. Confirm the hosted application marks the gateway offline and that buffer depth rises at the expected rate.
  4. Restart mid-outage. Power-cycle the gateway while it is buffering and confirm the buffer survives.
  5. Reconnect. Restore the uplink, time the drain, and confirm live values kept flowing during it.
  6. Reconcile. Compare source counters with the totals in the hosted application, check that each signal’s values arrived once each, and check that timestamps fall inside the outage window, not at the reconnect time.
  7. Fill. In a test configuration with a deliberately small buffer, let it fill and confirm the drop policy and the alarm.
  8. Consumer down. Stop the hosted consumer instead of the link and confirm the gateway buffers (with Sparkplug, through the Primary Host STATE message).
Check Pass when
Counters reconcile Hosted totals equal the source counters at the end of the test
No gaps Every signal has values across the outage window at its normal rate
No duplicates kept Each signal and timestamp appears once in storage
Timestamps Replayed values carry acquisition times inside the outage window
Reboot Buffered values from before the power cycle arrive after reconnect
Live during drain Live screens show current values within their normal delay during the drain
Drain time Measured drain time is within the value planned for the backlog size

Example (fictional). For a fictional beverage bottler’s Line 2, the pilot plan’s first outage test disconnected the uplink during a planned stop. A second test repeats it during production on the first shift: the uplink is blocked from 11:30 to 12:15 while the filler runs. At the line’s usual rate of about two values per second, the gateway buffers 5,400 values over the 45 minutes. At 11:50 the gateway is power-cycled and comes back with its buffer intact. When the uplink returns at 12:15, the backlog drains in 27 seconds at 200 values per second, each replayed metric flagged is_historical because the line publishes Sparkplug B, and the changeover to 1-liter bottles at 12:18 appears on the live board as it happens. At 14:00 the hosted shift report shows a total count of 41,212 and a good count of 40,580, matching the filler’s own counters, and the timeline shows no gap between 11:30 and 12:15. The results go into the test record.

What to look for in the results

The reconciliation step is where problems show up, and each kind of mismatch points to a different cause:

  • A gap of seconds to a minute at the start of the outage points to a buffer that starts writing only after the gateway detects the outage, or to QoS 0 messages lost before detection.
  • Values stamped at the reconnect time mean the receiving side is using arrival time instead of source timestamps.
  • Doubled counts or energy totals mean duplicates were stored, or the gateway publishes increments instead of absolute counters.
  • Everything before the power cycle missing means the buffer, or the client’s queue, lived in memory.
  • Live screens hours behind after reconnect mean the backlog is sent ahead of live data instead of alongside it.
  • A clock step at reconnect means the gateway lost its time reference during the outage.

The example project walks through the planned-stop version of this test in context, and the go-live readiness checklist includes restarting components on purpose before a line goes live.

A store-and-forward checklist before go-live

Before you trust a cloud-hosted plant application with shift reports, write down how each of the three mechanisms is configured and test them together. Use this list with your controls engineer and IT lead:

  • MQTT session: QoS 1 for telemetry that matters, Clean Start 0 with a non-zero Session Expiry Interval, and no message expiry on historical data.
  • Disk buffer: writes before sending, deletes on acknowledgment, survives a reboot, and has a stated size and full policy.
  • Size: values per second, measured bytes per record, the outage you plan to ride through, headroom, and the resulting drain time.
  • Timestamps: taken at acquisition in UTC, from a clock with a time source inside the plant.
  • Marking: is_historical in Sparkplug, or a documented flag or topic branch in plain MQTT.
  • Source history: the counters and historian tags that can fill a gap the gateway missed, and the values that cannot be recovered.
  • Receiving side: inserts by source timestamp, ignores duplicates, recalculates reports and shows incomplete periods.
  • Monitoring: buffer depth and oldest-record age published as gateway health metrics, with an alarm before the buffer fills.
  • Test: the eight-step outage test above, recorded, and repeated after gateway updates.

Start with the arithmetic: run your tag count and sample rate through the data volume estimator, then measure bytes per buffered record on your own gateway. If you are planning a first line and want buffering, timestamps and the outage test written into the pilot plan from the start, you can plan a pilot line with us.

Working on this at your plant?

If this article describes a problem on one of your lines, tell us about it. We start with one line, its signals and the question you ask after every shift.