- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
16m ago
A Stream Connect Reconciliation Playbook
This is the third post in a three-part series on Apache Kafka and ServiceNow Stream Connect. Post 1, Kafka Fundamentals Through a Stream Connect Lens, covered at-least-once delivery and duplicate handling. Post 2, What Actually Goes Inside a Kafka Message?, covered message design patterns. This post covers the question that keeps you up at night: did everything actually make it to the consumer?
A few terms
- Stream Connect: the ServiceNow capability that connects your instance to Apache Kafka.
- Hermes: ServiceNow's internal messaging service. Messages from your instance land here first.
- Producer: whatever sends messages out of ServiceNow. This post covers the Producer step, the ProducerV2 API and the Stream Producer.
- Stream Producer: a configuration-based producer that uses change data capture (CDC) to publish inserts, updates and deletes from a table, with no flow or script.
- CDC queue: the table where a Stream Producer stages captured changes until its job sends them.
- MID Server: the ServiceNow application that runs inside your network. Here it copies (replicates) messages from Hermes to your own Kafka cluster.
- Consumer lag: how far a consumer is behind the newest message on a topic.
Why streaming reconciliation is harder than batch
Batch jobs are neat. They have a start time, an end time and a row count, and you compare that count to the destination.
Streaming is messier. The producer and consumer run continuously, independent of each other, with independent failure modes. Messages flow at-least-once, so duplicates are possible. Failures can happen at any layer, from the producer to the messaging backbone to the consumer, and each layer tracks what happened differently. So "did everything arrive?" has no single obvious answer.
That is why streaming reconciliation is not one count. It is a chain of observations across independent systems, and this playbook walks you through each one.
Three integration patterns
Outbound (ServiceNow to external Kafka). Your Producer step or ProducerV2 API call sends messages to Hermes. Those messages are published to your external Kafka cluster, where a consumer on your side (or at a partner) reads them.
Stream Producer (change data capture). A Stream Producer watches a source table and publishes inserts, updates and deletes to a Kafka topic. Each change is first written to a CDC queue, and a scheduled Stream Producer job drains that queue and sends the messages. Because there is a queue between the change and the broker, a Stream Producer has its own statistics and its own "how far behind is it?" signal.
Message replication (Hermes to external Kafka via MID Server). A MID Server bridges messages from a Hermes topic to a customer-managed Kafka cluster on a replication channel.
All three follow the same logical chain: ServiceNow, then Hermes, then the broker, then the consumer. The observability tools differ, but the reconciliation pattern stays the same.
The four observability layers
Think of the data flowing left to right through a pipeline. At each stage, a different system can answer a different question.
|
Source table Layer 1: record count |
→ |
Hermes Layer 2: producer statistics (Stream Producer: via CDC queue) |
→ |
MID Server or external broker Layer 3: replication statistics or offset delta |
→ |
Consumer system Layer 4: consumer lag and final count |
Layer 1: Source table count
Count the records in your source table for the time window you exported. Apply the same filters your producer uses (active records only, excluded statuses, date ranges, whatever the business logic specifies). This is your baseline: how many records ServiceNow thinks should have moved.
Layer 2: Producer statistics
This is the ServiceNow-side count: how many messages the producer actually sent to Hermes for your topic over the time window. Which table you read depends on the kind of producer.
Layer 2A: Producer step and ProducerV2 API. In Stream Connect Home, open Producers. The sys_kafka_producer_statistics table (requires the kafka_admin role) holds one record per producer per hour, with produced message and byte counts. The sys_kafka_producer table holds the producer definition: type, source table and destination topic.
Layer 2B: Stream Producer. A Stream Producer records its own statistics in the Stream Producer CDC Statistics table, sys_sc_cdc_statistics. To see them for one producer, go to All > Integration Hub > Stream Connect > Stream Producers, open the producer and scroll to the Stream Producer CDC Statistics related list. The ServiceNow documentation describes the table as tracking, per producer, the messages and bytes produced, the processing time and the CDC depth, aggregated per job run.
These are the fields to use for reconciliation:
| Field | What it tells you |
|---|---|
produced_messages |
Messages produced to the topic in that run. Sum it over your window for the producer-side count. |
produced_bytes |
Bytes produced in that run. |
cdc_depth |
The producer's queue backlog: changes captured but not yet produced. |
total_processing_time |
Time the run spent processing, in milliseconds. Useful for throughput questions, not for counting. |
The queue itself is the Stream Connect CDC Change Queues table, cdc_queue_stream_connect. Each Stream Producer has a label, and the job polls the queue for entries carrying that label. You normally do not query the queue for reconciliation, but it explains what cdc_depth is counting.
The Stream Producer job runs every minute for up to two minutes per run, so a Stream Producer typically runs slightly behind the source table. A small gap that closes on its own is normal. A gap that keeps growing is the signal to investigate.
If the source count and the producer count do not match, check the producer type first. For the Producer step or ProducerV2, processing may have been bypassed due to upstream configuration bypassing flow/Business Rule execution. For a Stream Producer, first check whether it is still draining:
cdc_depthabove zero and falling means it is catching up, not losing data.
One more cause of a permanent gap on a Stream Producer: a change record larger than the target Kafka environment's maximum message size is not sent. It is logged as a RecordTooLargeException, skipped, and processing continues with the next change. Stream Producer does not chunk large payloads, so an oversized record shows up as source count minus produced count with no retry.
Layer 3A: Replication statistics (MID Server replication)
For message replication, the sys_sc_channel_replication_metric table records one entry every 60 seconds. Find it under Topic Replications > Message Replication Statistics. This layer confirms how many messages were replicated from Hermes to your external Kafka cluster.
It also tracks lag messages: the count of messages still waiting to be processed at the source. If this number grows instead of shrinking, your MID Server is not keeping up.
Compare the producer statistics count to the replication statistics count for the same window. A gap here points to MID Server connectivity, configuration or performance.
Layer 3B: Broker offset delta (direct external Kafka)
For the outbound pattern (ServiceNow to external Kafka), use the Kafka command line or your broker's native tools to read the offset delta: the end offset of each partition at the end of your window minus the end offset at the start. Summed across partitions, that is the number of messages produced to the topic in the window, which you can compare to the source count.
Hermes retains messages for only 36 hours, so any offset-based replay or count taken from Hermes works only inside that window. On your own Kafka cluster, your cluster's retention settings apply instead. Once the data has aged out, the consumer's own count is your only remaining signal.
Layer 4: Consumer lag
Consumer lag is the most direct real-time signal of whether the consumer is keeping pace with the producer. It is the end offset (the highest message position on the broker) minus the current offset (the highest position the consumer has processed), summed across all partitions.
How to read it:
- Lag is 0 and stable. The consumer is caught up.
- Lag is above 0 but decreasing. The consumer is behind but processing. Watch the trend.
- Lag is above 0 and growing. The consumer cannot keep up with the production rate. Look for an undersized, misconfigured or slow consumer.
- Sudden spike from zero. A burst of upstream activity such as a batch import or backfill. Wait for recovery and watch the trend.
- Lag persists after a consumer restart. Something structural is wrong: an offset reset, a partition reassignment, data skew or a logic error in the consumer.
Find consumer lag in your Kafka monitoring or consumer group tooling. The exact location depends on your broker, but the concept is the same everywhere.
Early signal: undelivered messages
Before assuming a downstream problem, check the sys_kafka_undelivered_messages table (requires the kafka_admin role). Messages that fail to reach Hermes, for example because of credential, network or payload problems, are held here for inspection, and a scheduled job retries them periodically.
If this table is growing instead of shrinking, or has entries for your export window, you have a producer-side problem before you even reach the broker.
This table covers the Producer step and ProducerV2 paths. For a Stream Producer, the equivalent early signals are the queue and its statistics: a cdc_depth that keeps rising, or a producer that stops writing new rows to the Stream Producer CDC Statistics related list.
Your reconciliation sequence
Every integration's consumer is different, so a generic script will not fit. Instead, build a count chain once and reuse it. Each step narrows down where a problem lives, and each uses data from a different system, so you are not counting the same thing twice.
- Check the early signals. Confirm the undelivered-messages table has no entries for your topic and window. For a Stream Producer, confirm it is still writing statistics rows.
- Count records in your source table for the export window, using your producer's filter logic.
- Sum the produced-message count from producer statistics for the same window and topic. Use
sys_kafka_producer_statisticsfor the Producer step or ProducerV2, andsys_sc_cdc_statistics(produced_messages) for a Stream Producer. If it does not equal step 2, messages are not making it to Hermes. For a Stream Producer, first letcdc_depthreach zero, or pause writes to the source table, otherwise the gap is just backlog. - If you use MID Server replication, compare producer statistics to replication statistics for the same window. A gap points to the MID Server.
- If you use external Kafka directly, compare the broker's offset delta (see Layer 3B) to the count from step 2. A mismatch means messages were dropped or duplicated between Hermes and the broker.
- Wait for consumer lag to reach zero, then query the destination system directly (see Zero Copy Connectors below) and compare its count to the source count.
- For high-stakes migrations, spot-check a sample of individual record IDs against the destination.
If every step passes, you can be confident the data arrived.
Zero Copy Connectors: closing the loop
Zero Copy Connectors let you query an external data source directly from ServiceNow without importing the data. Check the ServiceNow documentation for the sources your release supports. That makes them useful for reconciliation, because a flow or script can, in principle:
- Count the records in your ServiceNow source table.
- Count the matching records at the destination through the Zero Copy Connector.
- Compare them and flag a task if the difference exceeds a threshold.
You can schedule such a flow to run daily or hourly. The exact flow actions and scripting options depend on your connector and release, so test the approach on a small table first.
Two caveats:
- Wait for lag to reach zero first. If the consumer is still catching up, the destination count looks artificially low and you get false alarms.
- A matching count confirms volume, not correctness. If the counts match but a field value is wrong or a transformation failed, you will not catch it. Spot-check individual records, especially on critical migrations.
Where to go next
- ServiceNow documentation: Stream Producer, covering the CDC queue, the statistics table, limitations and roles.
- ServiceNow documentation: Monitor and optimize Stream Producer performance, covering the Stream Producer CDC Statistics related list.
- ServiceNow documentation: Producer statistics and Message replication statistics.
- Earlier in this series: Kafka Fundamentals Through a Stream Connect Lens and What Actually Goes Inside a Kafka Message?.
- Apache Kafka and Confluent documentation, for general (non-ServiceNow) consumer group and lag monitoring concepts.
Together, the three posts give you a complete mental model: how messages move, what goes in them, and how to verify they arrived. Good luck with your integration.