IMD SolutionComputing LibraryShop main store

Explainer

Why Sparkplug B sends DBIRTH once and DDATA only on change

Edge computing and IIoT Published 9 min read

Short answer

A Sparkplug B publisher sends the complete metric set once, in DBIRTH, when the session starts, then publishes only the metrics that change in each DDATA. That is the design, not a fault: consumers must cache birth state and apply deltas. If an application needs periodic snapshots or self-contained per-topic values, publish a separate plain MQTT feed instead of forcing Sparkplug to repeat itself.

On this page
  1. Why does Sparkplug B send DBIRTH once and only DDATA changes after?
  2. Why do values go missing when you listen only to DDATA?
  3. Can you make a Sparkplug B publisher send all data periodically?
  4. Do retained MQTT messages replace the Sparkplug birth cache?
  5. What does the Sparkplug primary host ID control?
  6. How do you rebuild device state after a restart or reconnect?
  7. When is plain MQTT the better choice than Sparkplug B?
  8. How do you verify a Sparkplug consumer handles birth, data and death correctly?
  9. Should you fix the consumer or publish a plain MQTT feed instead?
  10. Questions asked

A Sparkplug B publisher sends the entire metric set once per session, in a DBIRTH message, and every message after it is a DDATA carrying only the metrics that changed. That asymmetry is the specification working as designed, not a fault you can tune away, so values going missing on a generic subscriber are a consumer-side state problem. Cache the birth as the device's complete record, apply each DDATA as a delta, and treat DDEATH as the signal that everything cached is stale. When an application truly needs periodic snapshots or topics that each carry a self-contained current value, build a separate plain MQTT feed next to Sparkplug rather than forcing the birth to repeat. This article gives the numbers behind that design, the failure modes, and the decision for each case.

Why does Sparkplug B send DBIRTH once and only DDATA changes after? #

Because the specification defines DBIRTH as the session's birth certificate: it is published once, when the node or device becomes available, and it carries the complete metric set. Every DDATA after it is a delta, containing only the metrics whose values or properties changed.

Sparkplug B layers a versioned topic namespace, a Protobuf payload encoding and birth/death certificates on top of plain MQTT, and it defines nine message types across that namespace. At the device level the lifecycle rests on three: DBIRTH declares the metric definitions and their initial values at session start; DDATA follows on change only, packaging just the metrics whose value, quality or timestamp moved; DDEATH ends the session, and the publisher registers it as the connection's will so the broker emits it automatically if the client disappears without a clean disconnect.

Every birth is also a reset. A consumer replaces its cached record with the birth's contents, because the birth is the authority on definitions, types and initial values; between births, DDATA assumes every consumer already holds the full picture. That contract is what lets an edge node report thousands of metrics without resending the ones that never move.

Why do values go missing when you listen only to DDATA? #

A DDATA payload is a partial snapshot: it contains only the metrics that changed in that interval, so a consumer that joined late, restarted, or dropped the lifecycle messages has no stored value for every metric that was absent.

A subscriber that joins mid-session has missed the birth, so its cache is empty and its first DDATA fills in one metric out of possibly hundreds. The same gap appears when a script restarts and loses its memory, when a flow subscribes to a topic branch that carries only data messages, or when the consumer treats each DDATA payload as the whole device image and overwrites intact values with unknowns.

Sparkplug-aware consumers rebuild state for you; a raw MQTT subscription does not. If your collector shows births arriving but data values never landing, the two message types' consumer-side handling is exactly the subject of why an MQTT collector logs DBIRTH but ignores DDATA.

Can you make a Sparkplug B publisher send all data periodically? #

No. There is no interval setting in the Sparkplug model that turns a birth into a repeating snapshot; a publisher that resent the full set every few seconds would reset every consumer's session state each time it fired, so treat periodic publishing as out of scope for the protocol.

To see why the specification refuses it, price the traffic. Worked example, with illustrative numbers, not a measured result: a device exposes 200 metrics in its DBIRTH, and in steady operation 5 of them change per 10-second scan cycle. A repeating full snapshot every cycle would carry 200 × 6 = 1,200 metric updates per minute, or 72,000 per hour. Under Sparkplug semantics the same device sends one DBIRTH of 200 updates per session, then DDATA carrying 5 × 6 = 30 updates per minute, or 1,800 per hour — a steady-state reduction of (72,000 − 1,800) ÷ 72,000 = 97.5%. The gap widens as the dataset grows, because a snapshot's cost scales with the whole metric set while DDATA scales with the change rate alone.

The one sanctioned replay is a rebirth: a command message, defined by the specification, that asks the publisher to send its birth certificates again. Use it when a consumer's state is suspect — after a restart, a redeploy or a broker maintenance window — never as a heartbeat. A rebirth repairs state once; it does not make any DDATA richer.

Do retained MQTT messages replace the Sparkplug birth cache? #

No. A retained flag makes the broker store the last retained publication per topic and hand it to new subscribers; it keeps one payload per topic, has no notion of a session, and cannot reconstruct a device record from a stream of delta messages.

Retaining a DDATA payload is worse than retaining nothing: a late subscriber receives the last changed subset with no way to know it is partial, and mistakes a fragment for the device's state. Sparkplug deliberately replaces retention with the birth/data/death contract — completeness comes from the birth, currency from the data messages, validity from the death. Keep the retained flag off the payload topics, and treat any design that leans on retention as a plain MQTT design, which is the case in the section below.

What does the Sparkplug primary host ID control? #

The primary host ID tells the edge node which central consumer to wait for: the host announces itself online with a STATE publication, and nodes configured with that ID hold their births until they see it; without it configured, the node births as soon as it connects.

Sparkplug inverts the usual announcement direction. The central consumer is the primary host, and its STATE message is what starts the edge side's session. In node-red-contrib-mqtt-sparkplug-plus the setting appears as the Primary Host ID field, labelled Destination, and it governs whether the node births at all.

That handshake explains a Node-RED Sparkplug node that sits idle after a broker or host change: it is waiting for a STATE publication that never comes, because the host application is down or configured with a different host ID. Match the host ID on both ends before you go hunting for a publish problem.

How do you rebuild device state after a restart or reconnect? #

You never rebuild it from DDATA: mark the cached values stale on DDEATH, drop or flag them, and wait for the next DBIRTH, which the publisher replays in full when its session restarts — or request one with the specification's rebirth command.

  1. On DDEATH, or on losing the connection, mark every cached value for that node and its devices stale immediately; do not keep feeding them to your application as live measurements.
  2. On the next DBIRTH, replace the cached record in one operation — definitions, types and initial values together. Never merge a new birth into state left over from the previous session.
  3. On each DDATA, update exactly the metrics it carries and leave the rest of the birth cache untouched.
  4. After your own consumer restarts, subscribe first, then wait for a birth or issue a rebirth request; never accept a DDATA as the start of state.

Edge buffering changes the reconnect math: deltas stored during the outage belong to the old session, and hosts can reject them on replay. That failure and its fix are covered in why buffered Sparkplug B data is rejected after reconnect.

When is plain MQTT the better choice than Sparkplug B? #

Choose a plain, non-Sparkplug MQTT feed when the consumer cannot maintain a cache, when each topic must carry its own self-contained current value, or when you control both ends and need publish-on-trigger logic; keep Sparkplug when consumers are Sparkplug-aware and you want birth-based state.

A plain feed is a contract you define: one topic per metric or per device slice, a JSON payload that carries value, timestamp and quality together, and retention or an interval you choose. Publishing PLC tags as separate MQTT topics is exactly that design, and the topic-layout decisions are walked through in how to publish PLC tags as separate MQTT topics. Where the trigger matters — one publication per event rather than one per change — a PLC-side publisher configured around a trigger or publisher-enable bit gives you that control, as in publishing MQTT values on a trigger from a PLC.

One safety note: a broker carrying Sparkplug traffic also carries command messages that write to devices, so keep it inside the OT boundary, require authenticated TLS on every client, and scope each client's topic permissions; do not bridge the plain feed and the Sparkplug namespace onto an internet-facing listener.

How do you verify a Sparkplug consumer handles birth, data and death correctly? #

Test the three lifecycle events in order, not just a value change: confirm the consumer builds a complete cache from DBIRTH, updates exactly the changed metrics on DDATA without touching the rest, and marks the record stale on DDEATH before the next birth rebuilds it.

  1. Subscribe before the session starts, using a device with a known birth set — for example five metrics with values you have written down — and confirm the first payload processed is the DBIRTH and the cache holds all five.
  2. Change one source value and confirm the next DDATA carries only that metric, while the other four keep their birth values.
  3. Restart the consumer mid-session and confirm it flags its state incomplete, then recovers through a birth or a rebirth instead of treating the next DDATA as complete.
  4. Drop and restore the publisher's connection and confirm DDEATH marks the record stale and the following DBIRTH rebuilds it.

Capture the traffic once with a broker-side log or a test subscriber and keep it: the expected sequence across one session — host STATE if a primary host is configured, then the node birth, then each device birth, then DDATA on change and DDEATH at the end — is the reference every future deployment gets compared against.

Should you fix the consumer or publish a plain MQTT feed instead? #

Fix the consumer when your consumers are Sparkplug-aware: cache DBIRTH, apply DDATA deltas, mark values stale on DDEATH, and request rebirth after restarts. Build a separate plain MQTT feed when an application needs periodic snapshots or per-topic current values; never change the publisher's birth behavior.

Map the choice to what the consumer can do. A Sparkplug-aware host, or a Node-RED flow built on a Sparkplug node — node-red-contrib-sparkplug and node-red-contrib-mqtt-sparkplug-plus both implement the lifecycle — needs the cache discipline above, and the problem closes there. If the consumer cannot hold state, the plain feed from the previous section is the answer. And if the real requirement underneath the question is periodic records for a historian, that is an edge collection problem, not a publishing-protocol one; the trade-offs are compared in choosing an edge data path for periodic records.

One rule holds in every case: the birth is a once-per-session event, and a design that needs it more often than that is a design for a different transport.

Questions asked

Does a Sparkplug B broker store historical data?

No. The broker is transport only: it holds subscriptions and queues messages for live sessions, and it keeps no history. Once a client disconnects, its unretained messages are gone. Anything you need across outages — buffered deltas, periodic records, history — must be stored at the edge or in a historian, not in the broker.

What is the difference between NBIRTH and DBIRTH?

NBIRTH is the birth certificate of the edge node itself and covers its top-level metrics; DBIRTH is the birth certificate of a device attached to that node. A node with no devices publishes only NBIRTH. Both carry the complete initial metric set for their scope, both mark a session start, and both are replayed by a rebirth.

What does a rebirth request actually do?

A rebirth request is a command message addressed to the node's command topic. On receiving it, the publisher replays its birth certificates in full, exactly as at session start. Consumers must treat the replay the same way: replace the cached record rather than merge it. It is a state-repair tool, not a periodic heartbeat.

Can I set the MQTT retained flag on DDATA topics so late subscribers get values?

You can set the flag, but it works against the model: the broker would hand a late subscriber only the last DDATA's changed subset, which looks like complete device state but is not. Keep the retained flag off birth, data and death topics and let late subscribers wait for a birth or request a rebirth.

Keep reading

  • Comparison

    OPC UA vs MQTT Sparkplug from a controller to SCADA

    Pick OPC UA when the controller and the SCADA host share one plant LAN you control: the host subscribes inbound to the controller's browsable server. Pick MQTT Sparkplug B when the controller sits behind NAT, on cellular or at a remote site, or when several consumers need the same tags: outbound-only connections plus birth and death certificates give automatic tag discovery and stale detection.

    Edge computing and IIoT

  • How-to

    Sending Sparkplug B device commands from Node-RED

    Build each Sparkplug B DCMD in Node-RED from the alias map in the device's latest DBIRTH, one metrics entry per value, and never hard-code an alias. Keep the sequence counter on its documented progression, zero through 255 with wrap-around, unless a captured command proves the receiver accepts the minus-one convention.

    Edge computing and IIoT

  • Troubleshooting

    Sparkplug B sends data but receives no SCADA commands

    Sparkplug B telemetry that reaches SCADA while SCADA writes never arrive is usually a direction-of-function fault: the open-source IEC SparkplugB library V1.0.0.0 implements only sending controller data to SCADA. Verify the broker path, session and authorization, watch the 30-minute demo window of the MQTT Client SL dependency, and choose a documented receive-capable implementation when writes are required.

    Edge computing and IIoT