Skip to main content

CDC Is Slow: What Can SeaTunnel's Row Trace Actually Prove?

· 10 min read

A common CDC scenario: an order in MySQL changes from unpaid to paid, SeaTunnel syncs the change downstream, the job is still running, and the application still shows it as unpaid. Separate two questions first: where does a record spend time inside the engine, and has the new value become visible in the target? SeaTunnel's data dyeing module StainTrace can help with the first question; for the second, query the database or follow the read path the application actually uses.

First, be clear about what it is: StainTrace is SeaTunnel's built-in end-to-end performance tracing module. It attaches a traveling marker to sampled records, records stage timestamps at the boundaries of Source, queue, Transform, and Sink, and finally writes a span. It is a sampled latency slice inside the engine, not a full audit log, and not proof that the data has been delivered.

Six Stages, and What They Do Not Cover​

In the SeaTunnel 3.1.0 stage reference, only six basic stages are actually instrumented. Subtracting adjacent timestamps gives the time for that section of the pipeline, not the database commit time.

Stage (code)Instrumentation pointWhat the adjacent difference answers
SOURCE_EMIT (1)Source emits a recordTiming start
QUEUE_IN (2)Record enters the queueFrom emission to enqueue
QUEUE_OUT (3)Record leaves the queueQUEUE_OUT - QUEUE_IN is time waiting in the queue
TRANSFORM_IN (4) / TRANSFORM_OUT (5)Transform receives / outputs a recordThe difference is total time for the whole Transform chain
SINK_WRITE_DONE (6)After writer.write() returnsThe difference from the previous stage is Sink-side time; not commit completion

Stage order depends on topology: when Transform is fused with Source, it is SOURCE_EMIT → TRANSFORM_IN → TRANSFORM_OUT → QUEUE_IN → QUEUE_OUT → SINK_WRITE_DONE; when fused with Sink, the two Transform events move after QUEUE_OUT. Do not treat one topology's event order as universal.

SINK_COMMIT_END (110), SINK_WRITE_START/END (108/109), network serialization (217–220), and more than forty other stage codes are defined in the enum but have no production instrumentation in 3.1.0 and will not appear in trace files. If a span stops at SINK_WRITE_DONE, all you can say is that the engine observed the write call return; you cannot say the transaction committed, still less that the application can read the value.

Reproduce the Trace Output with Six Rows​

I ran Apache SeaTunnel 3.1.0 locally in Zeta mode with JDK 11 and a single worker, running a one-off FakeSource → Console job. There is no database, Transform, or second worker in this test. If you want to try it yourself, just use a separate SeaTunnel installation; FakeSource and Console are connectors bundled with SeaTunnel.

Both switches must be on: the engine-level switch is the master gate, and the job-level switch decides whether this job is sampled. With only one enabled, no file is written.

Add these settings under the existing seatunnel.engine section in config/seatunnel.yaml. Use an empty writable directory for traces. An interval of 1 tries to sample every record in this tiny run; do not copy that setting into a production job.

seatunnel:
engine:
stain-trace-enabled: true
stain-trace-sample-interval: 1
stain-trace-file-base-path: /tmp/seatunnel-article-traces
stain-trace-file-flush-interval-seconds: 1

The canonical name in the configuration reference is stain-trace-sample-rate; stain-trace-sample-interval remains as a backward-compatible alias, and the job-level sample_interval can override the engine level. Each worker produces at most 50 traces per second under a separate budget: even with an interval of 1, a slightly larger job will miss samples because of that budget.

Save this job as stain-trace.conf in the SeaTunnel installation directory.

env {
job.mode = "BATCH"
parallelism = 1
stain_trace {
enabled = true
sample_interval = 1
}
}
source {
FakeSource {
row.num = 6
schema {
fields {
probe = "string"
}
}
}
}
sink {
Console {}
}

Run it from that directory:

bin/seatunnel.sh -DJvmOption='-Xms256m -Xmx768m' -m local -c stain-trace.conf

When the job finishes, inspect the new JSON Lines file under the configured path. It lives at {base}/traces/traces/{job_id}/{yyyy-MM-dd}/traces-*.jsonl; there is another traces directory under the configured path. I counted the stage events inside the span, not the number of log lines the job printed. The local result:

trace files: 1
spans: 6
SOURCE_EMIT: 6
QUEUE_IN: 6
QUEUE_OUT: 6
SINK_WRITE_DONE: 6
SINK_COMMIT_END: 0

The retained per-span record shows that all six spans have the event order SOURCE_EMIT > QUEUE_IN > QUEUE_OUT > SINK_WRITE_DONE, with no Transform events. This rerun retained timestamps: all adjacent-stage differences across the six samples fall between 0 and 2 ms, a scale specific to Console and an in-memory queue that cannot be extrapolated to JDBC writes or production loads.

What Is in a Trace Line, and What Is Not​

Each line is an OTLP ExportTraceServiceRequest, with one span per sampled record. The following is a simplified illustration based on the official structure, keeping only the events this job produces; real lines also have outer fields such as resourceSpans and scopeSpans:

{
"traceId": "000000000000000000000000000000c8",
"spanId": "00000000000000c8",
"startTimeUnixNano": "1708000000000000000",
"endTimeUnixNano": "1708000001000000000",
"events": [
{"name": "SOURCE_EMIT", "timeUnixNano": "1708000000000000000"},
{"name": "QUEUE_IN", "timeUnixNano": "1708000000020000000"},
{"name": "QUEUE_OUT", "timeUnixNano": "1708000000080000000"},
{"name": "SINK_WRITE_DONE", "timeUnixNano": "1708000001000000000"}
]
}
  • traceId / spanId are zero-padded from internal 64-bit IDs; they have no mapping to business keys, and the span contains no order ID or probe field. To find "this order", you cannot search traces by order ID.
  • startTimeUnixNano / endTimeUnixNano are the first and last stage times, and events[].timeUnixNano holds each stage time, all as string-formatted nanoseconds. Timestamps are collected at millisecond resolution and the nanosecond tail is usually zero, so do not read it as nanosecond precision.
  • events[].attributes also carries seatunnel.stage_code and seatunnel.task_id. On multi-worker jobs, group by task before discussing stage durations.

Turning Spans into Comparable Numbers​

First expand each span into adjacent-stage durations in milliseconds, then aggregate. Replace the path with your own job ID and date:

jq -r '
.resourceSpans[].scopeSpans[].spans[]
| ([.events[] | {stage: .name, ts: (.timeUnixNano | tonumber)}] | sort_by(.ts)) as $e
| range(1; ($e | length)) as $i
| [.traceId, $e[$i-1].stage, $e[$i].stage, (($e[$i].ts - $e[$i-1].ts) / 10000 | round / 100)] | @tsv
' /tmp/seatunnel-article-traces/traces/traces/*/*/traces-*.jsonl

Look at the distribution per stage; this is only meaningful with enough samples:

jq -s -r '
[ .[]
| .resourceSpans[].scopeSpans[].spans[]
| ([.events[] | {stage: .name, ts: (.timeUnixNano | tonumber)}] | sort_by(.ts)) as $e
| range(1; ($e | length)) as $i
| {seg: ($e[$i-1].stage + " -> " + $e[$i].stage), ms: (($e[$i].ts - $e[$i-1].ts) / 10000 | round / 100)}
]
| group_by(.seg)[]
| (map(.ms) | sort) as $xs
| "\(.[0].seg)\tn=\($xs | length)\tp50=\($xs[((($xs | length) * 0.50) | floor)])\tp95=\($xs[((($xs | length) * 0.95) | floor)])"
' /tmp/seatunnel-article-traces/traces/traces/*/*/traces-*.jsonl

Six samples are enough to see stage order but not to compute P95. If QUEUE_IN → QUEUE_OUT is consistently the longest segment across samples from the same worker, check queue depth, backpressure, and whether downstream operators keep up; if time concentrates in QUEUE_OUT → SINK_WRITE_DONE, inspect connector buffering and target-database waits before blaming storage. That difference still includes Sink-side formatting, batch aggregation, and I/O, and those fine-grained stages are not instrumented in 3.1.0, so it cannot be split further.

If you would rather not write jq, use the official analysis tool: put analyze-traces.sh and seatunnel-trace-analyzer-*-jar-with-dependencies.jar together and run ./analyze-traces.sh /tmp/seatunnel-article-traces report.html to get an HTML report. The figure below shows one of the trace views.

trace view

Four Things Most Easily Misjudged in Production Triage​

No trace does not mean no data. Sampling takes the record sequence modulo the rate at the Source (seq % rate == 0, see the implementation note), not by business key; each worker also has a 50-traces-per-second budget. If a business key is absent from traces, it either was not sampled or did not pass the budget, so you cannot conclude the row was lost.

A 1-to-N Transform traces only the first output by default. When one record expands into several, only the first inherits the payload; filtered-out branches have no later stages at all. To cover every branch, set stain-trace-propagate-to-all-splits: true. Before asking "where did a row go", check whether the topology contains such an expansion.

Defined does not mean instrumented. SINK_COMMIT_END is in the stage-code table but never appears in a trace; the same goes for SOURCE_READ_END, network serialization, and flow-control audits. Writing "no such event" as "this step took no time" is wrong.

Overhead and files depend on the sampling rate. The official figures are below 2% at 1/100000, below 5% at 1/1000, and below 10% at 1/100; use a low rate and a short window in production, then raise it temporarily during triage. Keep the trace path under the same storage root as checkpoint state so the two do not end up with different permissions; flush defaults to 10 seconds, so a short job may leave an empty file, which is safe to delete. If no file appears, check both switches and directory permissions first.

From Order ID to Conclusion​

SymptomNext evidence to collectLayer
The target primary has the expected new value by business key, but the application still shows the old oneThe endpoint, replica, isolation level, and cache the application actually reads; see article 03 in this seriesRead path
The primary has no value, and the trace has SINK_WRITE_DONE with the task mapped to the correct SinkConnector buffering, target transaction, and wait eventsTarget
Samples consistently stop between QUEUE_IN and QUEUE_OUTQueue depth, backpressure, downstream consumptionEngine
No trace for this business keySampling rate, budget, and whether a 1-to-N expansion was hit; then confirm with source offsets or a probe whether the record entered the jobUndetermined

Across workers or nodes, network serialization stages are not instrumented, so a blank stretch in a span is not network time. Production triage must also separate failed and replayed execution attempts; this Console test covers neither.

Keep two pieces of evidence separate in the incident record: the writer call returned is engine-side evidence; the application read the paid order is a separate observation. Neither implies the other, and the latter cannot tell you when the former happened.

Three Sentences You Can Take Away​

  • StainTrace is sampled, stage-sliced in-engine latency evidence, not an end-to-end consistency proof.
  • Stage differences can only locate which segment the time falls in; commit and visibility need separate evidence from the target database and the read path.
  • Low sampling in production, high sampling in short triage windows; no trace does not mean no data, and no COMMIT event does not mean no commit.