Sub topic 3
Choosing Workload Size and Scale to Zero
Assume you know basic Python, Databricks notebooks, Unity Catalog, and REST/JSON requests. This chapter focuses on operating an existing Model Serving endpoint.
Choosing compute behavior
A serving endpoint runs the registered model on managed compute. workload_size controls the compute capacity. Choose a larger size when the model needs more memory, receives concurrent requests, or has strict latency targets.
scale_to_zero_enabled=True stops compute when the endpoint is idle. This reduces cost, but the first request after inactivity can take longer while compute starts.
| Setting | Benefit | Trade-off |
|---|---|---|
| Small workload | Lower cost | Less capacity and possible higher latency |
| Larger workload | More memory and concurrency | Higher cost |
| Scale to zero | No idle compute cost | Cold-start delay |
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import EndpointCoreConfigInput, ServedEntityInput
w = WorkspaceClient()
w.serving_endpoints.create_and_wait(
name="iris-endpoint",
config=EndpointCoreConfigInput(
served_entities=[
ServedEntityInput(
entity_name="main.default.iris_classifier",
entity_version="1",
workload_size="Small",
scale_to_zero_enabled=True,
)
]
),
)Authenticating requests
Clients authenticate with a Databricks personal access token or another supported bearer token. Store the token in a secret manager or environment variable. Do not place it in source code or log output.
Sending scoring requests over REST
The request must match the model signature. This example uses dataframe_split, which includes column names and rows.
curl -X POST "https://<workspace-host>/serving-endpoints/iris-endpoint/invocations" \
-H "Authorization: Bearer $DATABRICKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"dataframe_split":{"columns":["sepal length (cm)","sepal width (cm)","petal length (cm)","petal width (cm)"],"data":[[5.1,3.5,1.4,0.2]]}}'Rolling forward to a new version
Update the endpoint to point at a tested model version. An alias can identify the intended version, but the endpoint configuration still needs a concrete served version.
w.serving_endpoints.update_config(
name="iris-endpoint",
served_entities=[
ServedEntityInput(
entity_name="main.default.iris_classifier",
entity_version="2",
workload_size="Small",
scale_to_zero_enabled=True,
)
],
)Monitoring and troubleshooting
Check the endpoint state and event logs first. Then check:
401or403: token, workspace access, or model privileges.400: JSON shape, column names, or model signature.5xx: model code, dependency, or serving compute failure.- Slow first request: scale-to-zero cold start.
- Slow every request: workload size, model latency, or concurrency.
Exercise
A request returns 400 after the endpoint was updated to version 2. What should you compare first?
Show answer
Compare the request columns and data types with version 2's model signature.