Add highly available background task delivery#22609
Draft
zzstoatzz wants to merge 7 commits into
Draft
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #21218
this PR replaces process-local deferred-task delivery with Docket-backed delivery so TaskWorkers can receive background tasks from any Prefect server replica.
Implementation
SCHEDULEDtask runs. This covers Redis restoration, the database/Docket transaction boundary, pre-upgrade runs, and unknown-task drops during mixed-version rollout.SCHEDULED.HA model
The Prefect database remains the durable source of truth for task-run state. Docket and shared Redis provide scheduling, leases, and cross-replica delivery. Any API replica can publish and any API replica serving a matching TaskWorker subscription can claim.
The implementation was exercised against real Redis by killing the API process holding an unacknowledged delivery. A second replica received the same task-run/state delivery and acknowledged it; a replica subscribed to another task key never received it.
Mixed-version workers that do not recognize
deliver_task_runcan drop an execution. Reconciliation recreates it while the database task run remains deferred andSCHEDULED, so the run becomes deliverable when an upgraded Docket worker is available.Results
Docket results are not Prefect task results. Docket tracks completion of the delivery operation.
PrefectDistributedFuturestill observes the Prefect task run and loads its return value through the existingResultStore; parameter and return-value persistence are unchanged.Compatibility
The TaskWorker subscription protocol,
Task.delay,Task.map(..., deferred=True),PrefectDistributedFuture, task-run REST/state schemas, and result storage are unchanged.The existing queue-size settings and
prefect.server.task_queueimports remain available.server.tasks.scheduling.delivery_visibility_timeoutis additive. A separate review discussion can decide whether the compatibility-only process-local queue implementation should be deprecated or removed in a minor release.Docket is raised to
>=0.23.1. Self-hosted HA requires every server replica to share the configured Docket Redis backend, as described by the existing server HA documentation.Performance
OSS end-to-end benchmark, PostgreSQL + Redis, one API server, one TaskWorker, 2,000 mapped no-op deferred tasks:
This is slower than the earlier equivalent main baseline (~39 tasks/s); the durable Redis reservation and atomic delivery work is visible overhead. The change prioritizes HA correctness, and the benchmark is included so that tradeoff is explicit.
Validation