Importer backpressure: why a faster producer can make the system worse

Bound accepted work by downstream capacity and check cursor persistence and rollback with MySQL 8.4/InnoDB.

A controlled flow needs a boundary and a way to resume.
A controlled flow needs a boundary and a way to resume.

An importer learns to read its source quickly and offers four jobs per logical tick. The consumer can finish only one in that time. The producer appears to finish its part quickly, but accepted work accumulates, the oldest job waits longer, and recovery begins with a large debt. Faster reading alone does not mean a faster completed import.

A queue absorbs short bursts and separates the speeds of adjacent stages. Trouble starts when admission has no bound and downstream cannot keep up. The difference becomes debt in storage and waiting time. Backpressure carries information about available capacity back to the producer.

What is bounded?

A rate limit bounds event frequency over time. An in-flight limit bounds work started but not completed. The outstanding limit here includes all accepted but unfinished jobs, both waiting and in flight. They are different limits: two workers do not stop a producer putting a million jobs in a queue. A per-minute rate limit alone does not bound accumulated work during a long consumer outage.

Let ready mean accepted jobs waiting to start and inflight jobs started but unfinished. Then outstanding = ready + inflight. Admission accepts another row only when this budget has room. The decision and insertion must agree with the source cursor: advancing the cursor without recording the job loses work; recording the job without advancing it requires a duplicate rule on replay. In the lab, a MySQL 8.4/InnoDB transaction through native PDO MySQL ties these changes together; it does not automatically cover an external effect. Run the checks with the shared guarded disposable MySQL fixture: App\Infrastructure\MysqlLab supplies the test schema, and a separate migrator explicitly prepares it before business transactions. Runtime access performs DML only, without CREATE, ALTER or DROP. MySQL DDL can cause an implicit commit, so this preparation is neither an atomic schema upgrade nor an automatic copy of data from the old SQLite database.

Symfony Rate Limiter documents frequency limits and window and token-bucket policies. Messenger can hand messages to a transport for later handling. Neither fact proves a general bound on accepted backlog. A transport rate limiter can block the entire worker, so isolation from other queues needs separate design. InnoDB error-handling documentation explains the distinction between rolling back a statement and rolling back a whole transaction. In this example, the transaction owner rolls back its entire operation on failure and propagates the error; that is not proof about a distributed queue.

A model to check

The prepared teaching protocol uses ten stable IDs, 1 through 10. The producer offers at most four per tick. Outstanding is capped at three, in-flight at two, and completion at one per tick. The order is fixed: complete, dispatch from ready, then offer new jobs. A newly accepted job cannot complete in the same tick. This is a sequential logical-clock model, not a measurement of parallel throughput.

Expected values were frozen before execution; the table shows selected states in the sequence. The cursor identifies the next ID not yet accepted. PHP checks against actual MySQL 8.4 compare persisted state with this protocol: outstanding stays at or below three, in-flight at or below two, and the cursor reaches 11 after all ten jobs complete. These are invariant checks for a sequential teaching model, not throughput measurements or proof of concurrent admission.

Tick Condition Accepted Ready In-flight Completed total Cursor
1 normal 1, 2, 3 3 0 0 4
2 no capacity — 1 2 0 4
3 producer paused — 0 2 1 4
4 producer paused — 0 1 2 4
5 resumed 4, 5, 6 3 0 3 7
6–7 downstream unavailable — 3 0 3 7
8 available again — 1 2 3 7
15 drained — 0 0 10 11

On tick one the fourth offer remains behind the cursor. On tick two moving ready work into flight frees no outstanding capacity because it is not completed. During the producer pause admission stops while the available consumer drains. During downstream unavailability the model neither dispatches nor completes. When availability returns it resumes the same order without raising the cap.

The oldest outstanding age is the current tick minus its admission tick. This is logical waiting in the model, not seconds or measured production lag. At tick 7 the age is two: jobs 4–6 entered at tick 5. Also track the oldest job still outside admission: a local cap protects the queue but does not eliminate waiting at the source.

Refusal without losing intent

Deferral differs from accepting and losing work. Here the source retains unaccepted offers and the next scan starts at the cursor. That works only if the source really supports replay and retains the records long enough. An API with short retention, unstable pagination or push without redelivery needs another durable inbox, an explicit refusal signal or a retry contract. The word backpressure guarantees none of these.

Each ID has a payload fingerprint. Repeating an ID with the same payload creates no new accepted effect; the same ID with different bytes is a conflict, not a silent overwrite. A real domain needs its own canonical serialization and a rule for whether changed payload means a new version or an error. A hash detects a difference but does not define business identity.

After tick 5, the MySQL connection is closed and reopened against the same schema: the cursor remains at 7. State is checked through a separate native PDO connection; an exact duplicate and a changed-payload conflict leave the records unchanged. A separate check interrupts the cursor update using a trigger created beforehand by the migrator, with MySQL SIGNAL SQLSTATE '45000'. The error propagates, and the transaction owner rolls back: no new jobs remain, and the cursor and tick retain their initial values. These checks cover reconnection and local atomicity, not a server restart, competing dispatchers or recovery of a distributed system.

An unbounded control

A separate negative control accepts all four offers per tick while completing at most one. By design, outstanding exceeds three on the first tick and grows until the source is exhausted. This is a constructed violation of the chosen bound, not an observed outage. Once a finite source stops, its queue can drain; sustained arrival faster than completion creates growing debt.

A practical bound needs a budget: how much work can be stored, what age is acceptable, how much downstream can handle at once, and how long the source retains unaccepted data. Observe ready, in-flight, completed, deferred offers, cursor and oldest age separately. Decide who owns the stop signal, how it reaches the producer, and what happens when the source cannot slow down.

Three is a teaching parameter, not a recommended setting. One dispatcher and sequential ticks cannot test several processes racing for the last slot. That requires separate concurrency tests, atomic reservation, crash checks across the boundary and real observations. Start by asking where the unaccepted intent lives when downstream says “not now.” A verifiable answer after restart is a foundation for controlled recovery.

If capacity is reduced below existing outstanding work, it cannot instantly meet the new limit without deleting or cancelling accepted work. A safer policy is to admit nothing new until the work drains below the new budget, and report the excess. On recovery, continue at the cursor and admit only as capacity is actually released. A health check is not a throughput guarantee: an available service can still be slow. Completion rate, age and refusals complement availability.

A pause needs an owner and reason: operator action, a full budget or an unavailable dependency. Define an exit condition for each so the system avoids an endless pause or a hot loop of repeated offers. Agree the policy before enabling it if the source cannot replay: a refusal without retained intent can lose data.

The shared MySQL fixture and its files are introduced in the transaction chapter. Run commands from the single article_demo root; do not create a separate Symfony application for each article.

Check the current example against an owned disposable MySQL schema:

bash fixtures/mysql_labs/run.sh php vendor/bin/phpunit tests/BackpressureLab
  1. Platform Engineering Who should retry a failed operation: one retry owner
  2. Platform Engineering A long task stopped: checkpoints and safe resumption
  3. Weather When to defer an import: CPU, memory and time budgets alongside a live website

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article