Skip to main content
Version: Current

Databricks Model Serving integration

Overview​

Nussknacker can call models of the Databricks Unity Catalog that are served by Databricks Model Serving endpoints. Once the integration is configured, Nussknacker generates an ML Enricher component, which can be used in the scenario to infer ML models.

This integration calls the models where Databricks serves them. The Databricks Unity Catalog integration reads the same registry, but runs the models in the Nussknacker ML Runtime (Ray).

The ML Enricher lists the models of one Unity Catalog schema (modelsSchema) that a ready endpoint serves, and for each model the versions that a ready endpoint serves, newest first. Feature specs, foundation models and models of other schemas are not listed. Only endpoints in the READY state count. A route-optimized endpoint counts only when Databricks also gives the URL of its data plane, where the endpoint is queried. An endpoint that the service principal may only view (CAN_VIEW) does not count.

A version must be served by exactly one ready endpoint. When two or more ready endpoints serve the same version, the Designer shows an error that names them. For example, a probe endpoint that serves the same version as the main endpoint causes it. Delete one of them, or serve the version on one endpoint only.

The ML Enricher calls the served entity of the version that the scenario author chose. It sends one request per event.

The input fields and their types come from the /openapi document of the endpoint: the required properties of dataframe_records. The outputs are the properties of predictions, or one output value when a prediction is not an object. Properties that are not required, for example the feature overrides of a model with automatic feature lookup, are not inputs. The model must be logged with a signature, otherwise the endpoint has no schema and the Designer says so.

Configuration​

Put the configuration in the Designer configuration file:

components.databricks-models {
providerType: "databricksMl"
componentPrefix: "databricks-"
modelsCache { type: "expiry", modelNames: "30 seconds", modelVersions: "30 seconds", model: "60 minutes" }
databricks {
workspaceUrl: "https://dbc-a1b2345c-d6e7.cloud.databricks.com"
clientId: "<application ID of the service principal>"
clientSecret: ${DATABRICKS_CLIENT_SECRET}
}
modelsSchema: "main.models"
httpClient { timeout: 120 seconds }
}

clientId and clientSecret are the OAuth credentials of a service principal. httpClient is optional. Do not set the com.databricks.sdk loggers to DEBUG: the SDK then logs the token exchange of a route-optimized endpoint. Otherwise Nussknacker never logs the secret or a token.

modelsCache sets how long the Designer keeps what it reads: the lists of models and versions (modelNames, modelVersions) and the schema of a version (model). Without modelsCache, it keeps the lists for 30 seconds and a schema for 365 days. Until a schema expires or the Designer restarts, the Designer does not see that somebody deleted the version, or that a second ready endpoint serves it.

Permissions​

Grant the service principal:

  • CAN_QUERY on the serving endpoints,
  • EXECUTE on each model, and USE CATALOG and USE SCHEMA on its catalog and schema.

The Designer needs all of them to list models and read their schemas, and a scenario needs them when it starts. A scenario that already runs needs only CAN_QUERY. Databricks applies a changed permission after 1 to 3 minutes, and the list of endpoints can be incomplete until then.

Databricks reports a missing permission in the Designer and in a failed event. Its message names the endpoint or the model.

Endpoints and timeouts​

A call to a model waits up to httpClient.timeout, 120 seconds by default. Each request to Databricks for a token, the list of endpoints or a schema waits up to 30 seconds. Retries, and the calls queued before a call, can make the call take longer. The engine also limits the time of a call:

  • In a Flink scenario, the timeout of the model configuration, 10 seconds by default, limits the part of the scenario that holds the ML Enricher. With asynchronous interpretation, which is on by default, the job fails past this limit and restarts. With synchronous interpretation, the event fails with "Interpreter is running too long".
  • In a Lite streaming scenario, interpreterTimeout of the model configuration, 10 seconds by default, limits the processing of the records of one Kafka poll. Past this limit, Nussknacker aborts the Kafka transaction of these records and restarts the task. No single event fails.
  • In a request-response scenario, the request timeout of the HTTP server that runs the scenario (pekko.http.server.request-timeout) limits the call. Past this limit, the server answers 503 Service Unavailable.

An endpoint that scales to zero reports READY. It holds the first requests after an idle time instead of refusing them: on a trial workspace the first answer came after 94 seconds, and a cold start can take longer. To wait until a cold start ends, set the limit of the engine above httpClient.timeout. When no answer comes within httpClient.timeout, the event fails with a message that names the timeout and scale to zero. For a streaming scenario, or a scenario that must answer fast, turn scale to zero off.

On a trial workspace in eu-central-1, a call from Poland over a kept-alive connection took about 200 ms.

Route-optimized endpoints work. Nussknacker calls them with a token that is valid only for the endpoint.

When something changes while a scenario runs​

Nussknacker finds the served entity of a version when a scenario starts, and then keeps calling it.

  • Databricks gives the name of the served entity that answers in the served-model-name header. When it is not the expected served entity, the event fails: "Databricks answered with served entity ..., not ...: the endpoint changed while the scenario runs. Restart the scenario." The header does not give the version. If somebody changes the served entity so that it serves another version under the same name, Nussknacker does not see it: the scenario scores the other version until it restarts. So give each version its own served entity name. The Databricks default name, <model>-<version>, does it. When the answer has other outputs than the schema, the event fails too.
  • If somebody deletes a version or a model that an endpoint still serves, the endpoint keeps scoring and the scenario keeps running. The Designer cannot read the schema any more. It shows a validation error when the schema expires from modelsCache, or after a restart of the Designer. A Flink scenario reads the schema again at each restart, automatic failovers included, so it fails at its next restart.
  • If somebody deletes the endpoint, the event fails with "Endpoint ... or its served entity ... no longer exists". Databricks can keep scoring for a few minutes after the delete.
  • If somebody deletes the client secret, Nussknacker keeps scoring with its token for up to one hour, the lifetime of the token. After that the Designer and the events fail with a message that Databricks rejected the client ID or secret.
  • If Databricks does not answer when Nussknacker gets a token, the next events wait. An event that waits longer than 30 seconds fails with "The call to Databricks waited longer than 30 seconds behind other calls: Databricks does not answer in time." It fails only when the call before it ends, so when Databricks does not answer for a long time, 1000 events can wait. When 1000 events already wait, the next event fails at once with "Too many calls to Databricks wait for an answer: Databricks does not answer in time."

Other answers fail the event with the message of Databricks: a refused input (400), a rejected token (401) and a missing CAN_QUERY permission (403).

Feature Serving​

A Feature Serving endpoint is a Model Serving endpoint that serves a feature spec. The Feature Store Enricher reads the latest features of an entity from such endpoints. Put its configuration beside the one above, with providerType: "databricksFeatureStore"; the Feature Store Enricher page shows it.

The Feature Store Enricher lists the endpoints that are ready and serve exactly one served entity, a feature spec of featuresSchema. An endpoint that the service principal may only view (CAN_VIEW) is not listed. The Designer shows the endpoint name as the feature view. The endpoint states, the route-optimized endpoints and the credentials are as for models.

  • The inputs are the required fields of the feature spec: its join keys, and the request values of its on-demand features. The features are the other fields of the answer.
  • A field has one of these types: a string, Long or Integer, Double, BigDecimal (a decimal), Boolean, LocalDate (a date), Instant (a timestamp; Nussknacker reads the offset of the answer) and a list of one of these types. A feature spec with a field of another type, for example a map or a struct, cannot be used yet: the Designer shows an error that names the field.
  • The enricher sends every input. It sends an empty input value as JSON null.
  • A key that the store does not know is not an error: Databricks answers, and every feature is null.
  • A function of an on-demand feature gets its request values untyped. For example, Feature Serving passes a date to it as a string. The function must convert its inputs.

The service principal needs USE CATALOG and USE SCHEMA on the catalog and schema of the feature spec, and CAN_QUERY on the endpoint. The Designer needs them, and a scenario needs them when it starts. A scenario that already runs needs only CAN_QUERY, until it restarts: a Flink scenario reads the endpoint again at each restart, automatic failovers included. It then needs USE CATALOG and USE SCHEMA again, and the restart fails when somebody deleted the endpoint or gave it a second served entity. EXECUTE on the feature spec and SELECT on its table are not needed.

httpClient.timeout is 120 seconds by default, and the timeout of the engine still applies, as in Endpoints and timeouts. A Feature Serving endpoint can scale to zero too; the timeouts above apply to it the same way.

cache.listFeatureViews (30 seconds by default) is how long the Designer keeps the list of endpoints. It is also how long a running scenario keeps a key whose endpoint is missing, or serves another feature spec, before it looks again. cache.describe (60 minutes by default) is how long the Designer keeps the definition of an endpoint.

When something changes while a scenario runs, the events fail with a message as for models:

  • If the endpoint serves another feature spec than when the scenario started, or the same feature spec under another served entity name, Nussknacker sends nothing and the event fails with a message that says to restart the scenario. Nussknacker compares them when it finds the endpoint, at the first lookup. After a mismatch, it finds the endpoint again after cache.listFeatureViews, so the events stop failing when somebody restores the feature spec. After a match, only the served-model-name header of each answer shows a change.
  • If the served-model-name header names another served entity, or a feature is missing from the answer, the event fails and the message says to restart the scenario.
  • A refused input (400) gives "Databricks refused the input", with the message of Databricks. A rejected token (401) says to check the client ID and secret. A missing CAN_QUERY (403) names the endpoint. A deleted endpoint (404) says that the endpoint no longer exists. Other answers give the status and the message of Databricks, never its stack trace.
  • When no answer comes within httpClient.timeout, the message names the timeout and scale to zero.
  • If Databricks does not answer when Nussknacker gets a token or looks for an endpoint, the next events wait. They fail with the same messages as for models.