TECHNOLOGY

BentoML startup hooks: worker resources are not deployment-wide singletons

In this article
THE QUICK TAKE

Deployment hooks precede worker spawning; startup hooks initialize each worker, so process-local connections and shared preparation need different ownership.

Initialization unexpectedly runs repeatedly

A model service creates an external collection during startup. After increasing workers, the collection creation happens repeatedly and concurrent startup attempts conflict. The application treated a worker lifecycle callback as a deployment-wide singleton operation.

Separate preparation of a shared asset from opening the process-local client that uses it. These actions may happen near each other during development, yet they have different ownership and retry requirements in a multi-process service.

Deployment and worker startup are distinct phases

The lifecycle guide distinguishes deployment hooks before workers are spawned from startup hooks executed for each worker. Place worker-specific connections and initialized runtime state in the worker phase.

A deployment hook is not a universal distributed lock across every deployment or restart in an infrastructure estate. If shared preparation changes external state, make the operation safe under the actual deployment topology and repeated execution policy.

Process ownership determines what can be shared

The worker guide explains separate service processes. Do not assume a Python object created in one process becomes a live shared connection in all others. Initialize the client according to its library’s process-safety requirements.

Stream-ordered allocation lifetime offers a useful parallel: availability is meaningful only within the resource’s actual lifetime and owner. A path to a prepared artifact and an active process-local connection are different kinds of resource.

Readiness should reflect usable dependencies

The service guide describes the running service boundary. The lifecycle reference also documents readiness hooks. Base readiness on the resources needed for the endpoint rather than only on completion of a global preparation message.

A prepared collection does not prove that a worker can authenticate to it. Registry authentication diagnosis illustrates the broader distinction between identifying an asset and having valid access in the environment that consumes it.

Exercise restart and partial failure

Restart a worker, restart the service and make the external dependency temporarily unavailable. Observe which preparation and initialization operations execute, whether retries conflict and whether readiness follows actual usability.

Cleanup should release resources owned by the exiting worker without deleting shared assets still needed elsewhere. A correct lifecycle design describes ownership through startup, serving and shutdown, not merely the happy-path order seen in a single local process.

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.

Explore GPU hosting
← All articles