Sub topic 9
Choosing workload size and scale to zero
This chapter assumes you can create an endpoint with the Databricks SDK, as in the previous chapter, and that you know what a concurrent request is. It covers the two compute settings you choose when you create an endpoint. These are workload size, which sets how many requests the endpoint can handle at once, and scale to zero, which sets whether the endpoint can shut down when idle.
Workload size means concurrency
Workload size does not describe memory or CPU directly. It sets the range of provisioned concurrency for the served model. Provisioned concurrency is the number of requests the endpoint can process at the same time.
| Workload size | Intended use |
|---|---|
| Small | Development, tests, light traffic |
| Medium | Moderate traffic with several simultaneous callers |
| Large | Heavy traffic with many simultaneous callers |
Each size covers a band of concurrency. Check the current Databricks documentation for the exact numbers, because they can change. Within the band, the endpoint scales up and down automatically as traffic changes.
Concurrency depends on latency. A model that answers in 50 ms can serve many more requests per second than one that takes 2 seconds, even at the same size. To estimate the concurrency you need, multiply expected requests per second by the average response time in seconds. For example, 20 requests per second at 0.2 seconds each means about 4 requests in flight at any moment.
Scale to zero trades latency for cost
With scale to zero enabled, the endpoint releases its compute after a period with no traffic. You stop paying for idle compute. The cost is a cold start. The next request has to wait while compute is provisioned and the model is loaded. That wait can be minutes, and the request may time out or fail instead of returning a prediction.
With scale to zero disabled, the endpoint keeps a minimum amount of compute running. Responses stay fast, but you pay for that compute around the clock.
Setting both options in code
The settings live on ServedEntityInput. This example creates a production-style endpoint: Medium size, scale to zero off.
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import EndpointCoreConfigInput, ServedEntityInput
w = WorkspaceClient()
w.serving_endpoints.create_and_wait(
name="iris-endpoint-prod",
config=EndpointCoreConfigInput(
served_entities=[
ServedEntityInput(
entity_name="main.default.iris_classifier",
entity_version="1",
workload_size="Medium",
scale_to_zero_enabled=False,
)
]
),
)The iris-endpoint from the earlier example used Small with scale_to_zero_enabled=True. That is a sensible choice for a development endpoint that is only called now and then.
Common errors
- First request after idle time fails or times out. This is a cold start. Retry after a short delay, or disable scale to zero if the endpoint serves users or other systems that expect fast answers.
- Requests are rejected with a "too many requests" error (HTTP 429) under load. Concurrent requests exceed what the current size can serve. Move to a larger workload size, or reduce how many requests your client sends at once.
- Cost is higher than expected. An endpoint with scale to zero disabled bills for its minimum compute even when no one calls it. Remove or re-enable scale to zero on test endpoints you are not using.
- Sizing from average traffic. Size for peak concurrency, not the daily average. Bursts are what cause rejected requests.
Exercise
An endpoint receives about 30 requests per second at peak, and each request takes 0.1 seconds on average. It backs a checkout page that must answer quickly at any hour. What is the approximate peak concurrency, and should scale to zero be enabled?
Show answer
Peak concurrency is about 30 x 0.1 = 3 requests in flight, so a Small size may be enough, though you should leave headroom for bursts and check the documented concurrency band. Scale to zero should be disabled, because the checkout page needs low latency at all times and a cold start would cause slow or failed requests.