Kafka Lag Is Rising. Is Flink Slow or Is PostgreSQL the Bottleneck?

The first graph to moveConsumer lag rises at 14:03. At 14:02 database lock waits jumped; moments later sink throughput fell. An upstream tas

profile_img

The first graph to move

Consumer lag rises at 14:03. At 14:02 database lock waits jumped; moments later sink throughput fell. An upstream task now reports backpressure. That order is the useful evidence: the queue is growing in Kafka, but its cause may be downstream.

Kafka lag climbs while the Flink job remains RUNNING. The natural response is to add workers. But if PostgreSQL is waiting on a row lock, more writers may lengthen the queue rather than drain it.

The turning point

Read the timeline backwards from the sink. Compare database commit latency and lock waits with sink throughput, upstream backpressure and Kafka lag. A checkpoint delay may be a consequence of congestion rather than its cause.

Measure arrival and drain rates using the same interval. If input is 2,000 records/s and the sink sustains 1,500, backlog grows by 500 each second. Once the sink reaches 2,500, it still takes ten minutes to clear 300,000 queued events if new input stays constant.

What actually happens to one record?

 Illustrative event or assumption Expected consequence
Baseline 2,000 in / 2,000 outStable event age
Lock fixture row, writes dropCommit waits rise, then backlog grows
Release lock, 2,500 outCatch-up margin 500/s
Verify rows after catch-upID set and totals match input

Lag identifies a queue, not its cause

If one subtask is hot while the others are idle, inspect key distribution before scaling. If all sink subtasks slow together and PostgreSQL waits rise first, look at the database. Metrics from clocks or aggregation windows that do not line up can tell a misleading story.

Distinguish hot keys from slow sinks. If a single subtask is busy while peers are idle, sample keys and partition assignment. If most writers stall simultaneously, inspect the target database and shared network before repartitioning the stream.

The architecture behind the decision

Operating architecture

Figure 1. Data travels across the top; the management plane observes and governs changes separately.

Use a disposable target table and stable event IDs. Baseline input rate, consumer lag, record age, per-subtask backpressure, checkpoint duration, database write latency and lock waits on one time axis.

The design trade-off

Recovery is not the moment lag stops rising. It is when event age returns to normal, the processing rate exceeds arrival rate long enough to drain the backlog, and output rows reconcile with the input.

Size connection pools against the database concurrency budget, not the number of available Flink slots. Bigger batches can improve throughput while increasing transaction time and retry cost. Change one control at a time and retain comparable traces.

What OSS Manager changes, and what it does not

The DBA checks locks, commit latency and connections. Streaming operations checks subtask-level flow and checkpoint alignment. The incident lead records when each signal moved on the same clock.

In a lab only, hold a transaction locking a test row, submit a bounded fixture, then release the transaction. Compare the onset and recovery of each signal. Repeat with a skewed key to see a different bottleneck.

Use the reviewed service configuration to identify endpoints and operating roles. The business rule belongs to the job and its downstream contract, not to a green infrastructure status.

The failure modes worth rehearsing

 Exercise Observable pass condition
Introduce the test lockSink writes stall before backlog drains
Release it without adding slotsThroughput recovers if locking was causal
Reconcile after catch-upEvery expected ID appears once in the target

Use a disposable table for lock injection, with bounded input and an automatic timeout. Release the lock and restore baseline concurrency before considering a restart. If the target remains unhealthy, pause the test writer rather than replaying into it repeatedly.

A human operating model

Base alerts on sustained age plus rate of change rather than a static lag count alone. Retain the Grafana interval and the matching database wait sample with the incident record.

Where this pattern earns its place

Payments: delayed reconciliation. Inventory: a regional sink lags despite healthy ingestion. Metering: delayed billing indicators need a freshness alert, not merely a process-status alert.

Companion technical solution: Diagnosing Backpressure from Kafka through Flink to PostgreSQL.

Technical reference and scope

Apache Flink documentation:

https://nightlies.apache.org/flink/flink-docs-stable/docs/ops/monitoring/back_pressure/

The timelines are illustrative, not customer measurements. Confirm connectors, state compatibility, metrics and available OSS Manager actions against the release selected for the pilot.