Skip to content

FEATURE: Bounded catch-ups via limit parameter - #13

Merged
bwaidelich merged 4 commits into
mainfrom
feature/bounded-catch-ups
Nov 3, 2026
Merged

bwaidelich merged 4 commits into
mainfrom
feature/bounded-catch-ups

Conversation

@bwaidelich

@bwaidelich bwaidelich commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

catchUpActive() and boot() get an optional limit. A bounded call reads at most that number of events, persists positions and commits, so workers can take turns between calls.

do {
    $result = $subscriptionEngine->catchUpActive($criteria, limit: 500);
} while ($result->hasPendingEvents);
 catchUpSubscriptions(criteria, status, limit)
   beginTransaction
   findByCriteriaForUpdate
-  read(start)
+  read(start, limit + 1)
+    if limit events were processed
+      hasPendingEvents = true
+      stop                        # the extra event stays unprocessed
     handle event per subscription
+  hasPendingEvents &&= a subscription remains
   per subscription
-    update(ACTIVE, position)
+    if hasPendingEvents
+      update(position)            # status unchanged, BOOTING stays BOOTING
+    else
+      update(ACTIVE, position)
   commit
  • Without limit, behavior is unchanged: one transaction, read to the end of the event log
  • limit counts events read, including skipped ones
  • ProcessedResult and CatchUpFinished gain hasPendingEvents
  • Breaking: EventStoreAdapter::read(Position $startPosition, int|null $limit = null)
  • main gets the branch alias 2.x-dev, so packages using composer-studio resolve the local core against ^1 || ^2
  • Separate fix: a catch-up that found only detached subscriptions no longer makes the next one fail

The reasoning, known consequences and open points are in docs/decisions.md.

Related: bwaidelich/subscription-engine-dcb-adapter#3, bwaidelich/subscription-engine-neos-adapter#1, bwaidelich/subscription-engine-doctrine#9

Evidence

  • Before: catchUpActive(limit: 2) fails with Unknown named parameter $limit
    After: OK (67 tests, 186 assertions), and CI is green on PHP 8.3, 8.4 and 8.5

  • Before: two consecutive catchUpActive() calls with only a detached subscription: RecursiveCatchUpException on the second call
    After: the second call succeeds and processes 0 events

The real dcb and neos adapters against this branch (5 events, boot(limit: 2), in-memory subscription store) gave the same output:

run: processed=2 pending=true status=BOOTING position=2
run: processed=2 pending=true status=BOOTING position=4
run: processed=1 pending=false status=ACTIVE position=5
handled: 1,2,3,4,5

Not tested: locking and rotation between real workers on MySQL or PostgreSQL.

Merge Danger

Door: two-way until 2.0 is tagged, one-way after that

read() is expected to change again with the event filter follow-up. The README says so, and the adapters shouldn't be tagged before it is final.

Blast Radius: implementers

Every EventStoreAdapter without the new parameter fails with a fatal error on 2.x. Callers aren't affected unless they pass a limit. A laggard holds back the other subscriptions of a bounded run, which docs/decisions.md covers.

…ched

A catch-up that found nothing but detached subscriptions returned early
without restoring the processing state. Every following catch-up without
criteria on the same engine instance then failed with a
RecursiveCatchUpException.
A catch-up with a limit reads at most that number of events, persists the
positions and commits, which releases the lock of the subscriptions.
ProcessedResult::$hasPendingEvents reports whether another call could
process more events. Partially booted subscriptions stay BOOTING until no
events are pending.

BREAKING: Implementations of EventStoreAdapter::read() have to accept the
new $limit parameter.
@bwaidelich bwaidelich changed the title Feature/bounded catch ups FEATURE: Bounded catch-ups via limit parameter Nov 3, 2026
@bwaidelich
bwaidelich merged commit d87fd1e into main Nov 3, 2026
5 checks passed
@bwaidelich
bwaidelich deleted the feature/bounded-catch-ups branch November 3, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant