In this article
Choose a limit for the resource being protected and distinguish how often work starts from how much work remains active.
Identify the scarce resource
An agent workflow calls a slow model service and also accesses a small database connection pool. A limit on starts per time interval does not necessarily protect the pool from long-lived operations. Prefect’s global-limit concepts distinguish concurrency from rate control through slot release. First decide whether the resource constraint concerns active operations, arrival frequency or both.
Hold concurrency slots across the protected work
The concurrency context manager acquires slots before entering protected code and releases them when the context exits. The practical guide applies it to ordinary Python operations, not only entire Prefect flows. Put the boundary around the actual resource use. Releasing a slot immediately after submitting a long external job would measure submission time rather than that job’s active resource consumption.
Use decay for the desired start frequency
The rate-limit function requires a configured slot decay and releases capacity over time independently of operation duration. It can smooth starts without limiting how many slow requests remain active afterward. If both constraints matter, express both deliberately. Do not label a provider’s frequency allowance as proof that the application cannot accumulate too many concurrent outstanding requests. The appropriate combination depends on the external service contract and the workflow’s resource use.
Keep acquisition timeout separate
The synchronous API reference defines timeout_seconds as time waiting to acquire slots. It does not give the protected function that same runtime deadline. A task can wait for capacity and then spend additional time in the model request. Account for those stages when setting the user-visible task budget, and inspect which stage actually timed out before changing an unrelated request duration.
Verify occupancy with a controlled workload
Use harmless delayed operations to observe start times, active counts and release behavior. Confirm the named limit exists and is active before interpreting a run as evidence of enforcement. Task budgets help relate waiting to useful completion; tool observations distinguish acquisition and execution. Preserve the resource boundary with the configuration. A correct limit protects the intended resource rather than merely slowing a convenient part of the code.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.