IMD SolutionComputing LibraryShop main store

Explainer

Store-and-forward SQL buffering during MES outages

Edge computing and IIoT Published 7 min read

Short answer

Treat the MES requirement as a durable store-and-forward buffer, not a database mirror. Capture every record locally with its acquisition timestamp — a file for event-level data, a queue table or a local time-series store for measurement streams — and replay only what the remote SQL database has actually committed. Size the buffer from record rate, record size and outage duration; at the worked rates a 256 MB partition carries a 72-hour outage.

On this page
  1. Decide first: mirror or store-and-forward
  2. Capture locally with two timestamps
  3. Where the buffer lives: file, queue table or time-series store
  4. Replay on the database commit, not on a ping
  5. Example: sizing the buffer for a 72-hour MES outage
  6. Prove the buffer before you trust it
  7. Questions asked

When the MES SQL database drops off the network, the edge controller's job is not to mirror the MES but to keep writing: capture every record locally with its acquisition timestamp, and replay only what the remote database has actually committed. That store-and-forward decision settles the three questions an outage raises — where the buffer lives, which timestamp survives it, and what signal starts the replay. Work through those decisions and the sizing arithmetic below, and a weekend outage becomes a backlog to drain instead of a gap nobody can explain.

Decide first: mirror or store-and-forward #

A requirement that reads "local mirroring of the SQL database" can describe three different designs, and only one is what machine data usually needs. A mirror keeps a live copy of remote tables on the controller; a store-and-forward buffer keeps the controller's own records until the MES accepts them. Decide from the direction of the data:

What the requirement has to preserve What to build The catch
Records the machine produces for the MES Store-and-forward buffer on the edge controller Delete only after the remote commit, or records are lost or duplicated
Recipes or orders the machine reads while the MES is down Buffer plus a local read cache with a stated staleness limit Stale orders must be detectable, never silently trusted
Records both sides can edit Ownership and conflict rules agreed before any code Retry logic alone duplicates or overwrites rows

For a line that only reports upward, commit to the buffer: an outgoing queue on the edge controller, replayed in acquisition order, with records marked or deleted only after the remote database commits them. A hosted database engine that mirrors remote tables brings packaging, maintenance and recovery work with it, and it solves a problem the machine rarely has. Reading during an outage is the one case that adds a real component — a local read cache of the recipes or orders the machine runs on, with a staleness limit stated in operating terms (for example, stop rather than run on order data older than one shift) so the decision is not left to whoever debugs the cell at night. The buffering itself is the same pattern that keeps PLC data logging alive through SCADA outages.

Capture locally with two timestamps #

Every buffered record carries two times. The acquisition timestamp is set where the value is measured, at capture, and it travels inside the record through the buffer and back out on replay. The delivery timestamp is set by the receiving database at insert. Keep both columns at the destination and an outage stays readable: plotted against acquisition time the data is continuous, and the received-time column shows the catch-up burst when the link returns. Drop the acquisition timestamp and an overnight outage repaints itself as a flat line of current-looking values.

Durability decides whether the buffer is real. Controllers in cabinets lose power without a clean shutdown, so the store must commit each record — or each flush interval — to non-volatile media before the flow moves on. The flush window is the data you have chosen to lose at power failure: a one-second flush is one second of records, and a buffer that lives only in memory is not a buffer.

Where the buffer lives: file, queue table or time-series store #

The record rate picks the store more than any preference does.

A flat file stays right while records are events — one JSON line per part, batch or shift, appended as captured. Keep a separate delivery checkpoint instead of trusting the file's extent, never delete on send, and delete only below the acknowledged checkpoint. Settle the crash case in advance: a final line that fails to parse after power loss was never a committed record, so discard it and log the discard. At tens of records per hour this is a few dozen lines of flow logic and nothing to administer.

Once records arrive every few seconds or faster, replay paging, per-record acknowledgement and pruning become queries, and a queue table earns its keep. SQLite fits naturally from Node-RED — the node-red-node-sqlite palette writes it — with a sequence column and a delivered flag. Community flows for exactly this pattern buffer into SQLite, watch the connection state and prune after a retention window; 30 days in one published example is a reasonable default for a buffer that should drain far sooner.

For continuous measurement streams, keep the samples in a local time-series database such as InfluxDB and let the delivery flow transform them into the fields and types the remote SQL database expects. The local store is not a SQL mirror and should not pretend to be one; it is the durable stage in front of the mapping, which is where schema differences belong.

Whichever store you pick lives on the controller that already polls the line, so a record is durable before it crosses a hop. If that machine is being specified now rather than inherited, this is the role for a fanless mini PC with the buffer's partition reserved from the start. The queue shape is not SQL-specific either: it is the same one that protects Node-RED MQTT data through cloud outages.

Replay on the database commit, not on a ping #

A ping, an HTTP probe or an internet time-server check proves one thing: that the probed service answered once. The MES database can still refuse every insert — service stopped, credentials expired, a schema rule violated — and an internet probe can fail while the MES link is perfectly healthy. So do not gate the flow on a probe. Attempt the write and let the write's own result route the record: success advances the checkpoint, any failure feeds the buffer.

The commit signal is the success message of the database client that talks to the MES — the palette matching the engine, such as node-red-node-mysql or node-red-contrib-mssql-plus, returns one per statement or per transaction. Match the deletion to that scope: ten records sent in one transaction are safe only when that transaction commits, and exactly then all ten are marked or removed. A write that dies with the link must die loudly — work from Node-RED InfluxDB write errors after a network outage rather than inferring an outage from a connection that went quiet.

Replay oldest first, in acquisition or sequence order; it is the same ordered backfill an MQTT store and forward backfill after a connection outage has to perform. And hold the line on what delivered means: when store-and-forward data counts as stored in the historian works through that definition in detail.

Example: sizing the buffer for a 72-hour MES outage #

Case: a packaging line reports four process tags every 500 ms plus intermittent events, so the capture flow writes 2 records/s, and each record — tag names, values, both timestamps — lands near 120 B.

Payload rate: 2 records/s × 120 B = 240 B/s, and 240 B/s × 3,600 s/h = 864,000 B/h, about 0.86 MB/h.

Outage load: a 72-hour weekend outage accumulates 0.86 MB/h × 72 h ≈ 62 MB of raw records.

Reserve: double once for page, index and write-ahead overhead, about 125 MB, and double again so replay catch-up and pruning never brush the limit, about 250 MB.

Decision: reserve a 256 MB partition for the buffer. It carries the 72-hour requirement with both margins inside — the engineering rate is about 3.5 MB/h, and 256 MB ÷ 3.5 MB/h ≈ 73 h. If the line doubles its record rate, the same partition covers half the outage window; rerun the arithmetic when capture changes, not after the first long outage. Keep that partition off the volume hosting the operating system and any runtime, so a filled buffer costs data collection, not the controller.

Prove the buffer before you trust it #

Five tests, run on the bench and repeated at commissioning:

  • Break the WAN while the line runs: records keep landing with acquisition timestamps, and the pending count and oldest-record age start climbing.
  • Leave the network up and stop the MES database service instead: buffering starts anyway, which proves the flow keys off the commit result, not connectivity.
  • Restore the link during a replay: the backlog drains oldest first and the destination row count matches the buffered count with no duplicates.
  • Pull power mid-capture and restart: no partial final record survives, and the loss is bounded by the flush window chosen in the design.
  • Trend pending count and oldest-record age after go-live: a backlog that grows while capture succeeds points at delivery, and local records that vanish point at capture or persistence.

Questions asked

How do I keep replayed records from appearing twice in the MES database?

Add a destination-side guard as well as the local checkpoint: a unique record id, or a composite key of acquisition timestamp and tag, enforced by a unique constraint or an upsert at the remote database. A replay that overlaps an already committed record then updates one row instead of inserting a second. The checkpoint decides what goes out; the constraint makes an accidental double send harmless.

How long can the edge controller buffer before records have to be dropped?

Capacity sets the limit, not a fixed number of hours: divide the reserved capacity by the engineering rate, which the example puts near 3.5 MB per hour, for roughly three days on that partition. Past that, choose an explicit policy — stop capturing and alarm, prune the oldest records, or enlarge the partition. Silent pruning is the option to avoid, because missing windows surface months later as unexplained gaps.

Should the buffer live on the same controller as the capture flow?

Yes, in most cases: the controller that already polls the machine keeps the records, so each one is durable before it crosses any network hop. A separate buffering box adds a hop that can fail in the same disturbance and lose the records it exists to protect. The exception is a shared controller whose storage is already committed to other duties — there, a small dedicated buffering host is easier to defend than a partition argument.

What order should buffered records be replayed in?

Oldest first, by the acquisition timestamp or a monotonic sequence assigned at capture. Order matters when the MES counts parts, derives states or computes rates from consecutive records: out-of-order delivery turns those calculations into manual corrections. If the destination stores plain samples the order matters less, but keeping it costs nothing once the queue carries a sequence column.

Keep reading

  • Troubleshooting

    Fix Node-RED InfluxDB write errors after a network outage

    When InfluxDB output nodes throw ECONNRESET after a network outage, Node-RED is usually still holding dead TCP client sessions. Confirm the database is reachable from the Node-RED host, then use the Deploy menu's flow-restart option to rebuild every connection while the runtime stays up.

    Edge computing and IIoT

  • Troubleshooting

    Historian stores zero after an MQTT edge node reconnects

    A 0 stored just before the true value at every MQTT edge reconnect is a reported pattern on Ignition 8.1.5 through 8.1.15 with the MQTT Transmission and Engine modules 4.0.6 through 4.0.10. Confirm it by querying stored records around each reconnect, exclude those zeros from process data, and remove them with a timestamped rule instead of a blanket zero filter.

    Edge computing and IIoT

  • How-to

    Replaying buffered InfluxDB records to Azure IoT Hub over MQTT

    Yes — but not with the TICK stack alone. Telegraf's MQTT output forwards the live stream, not database history, and Kapacitor aggregates; run a small replay worker that queries InfluxDB after a durable (time, name) cursor and publishes each raw record to Azure IoT Hub at QoS 1, advancing the cursor only on acknowledgment. At 1 record/s arriving, publish at 5 records/s so a full 7-day buffer of 604,800 records clears in 42 hours.

    Edge computing and IIoT