---
title: Serve Feature Views
description: Serve Feature Views online using model serving endpoints and Feature Serving endpoints backed by a FeatureSpec.
canonical_url: https://docs.databricks.com/aws/en/machine-learning/feature-store/serve-declarative-features
---

# Serve Feature Views

You can serve Feature Views online in two ways:

* **Model serving**: Deploy a model that was trained on Feature Views. The endpoint looks up or computes feature values automatically, using the lineage tracked when the model was logged. Use this to serve model predictions.
* **Feature Serving**: Deploy a [`FeatureSpec`](https://docs.databricks.com/aws/en/machine-learning/feature-store/feature-function-serving.md) that references Feature Views directly, without a model. The endpoint returns the requested feature outputs. Use this when an application needs feature values rather than model predictions.

Both approaches support precomputed and on-demand features. Table- and stream-backed leaf features must have [supported online materializations](https://docs.databricks.com/aws/en/machine-learning/feature-store/materialized-features.md). `RequestSource` supplies values from the request, and `CustomUDF` computes features on demand. For a `CustomUDF` with `FeatureViewSource`, serving resolves upstream dependencies and evaluates the feature dependency graph automatically.

Register the requested features and all of their transitive upstream features in Unity Catalog. Materialize only the table- and stream-backed leaves, not the request-time or derived `CustomUDF` features.

## <a id="permissions" />Permissions

To serve a feature, the principal that creates the model serving endpoint must have `SELECT` on the Unity Catalog table that backs the materialized feature. Online lookups read directly from the materialized table, so table-level `SELECT` is what grants serving access. For the privilege description, see [SELECT](https://docs.databricks.com/aws/en/data-governance/unity-catalog/access-control/privileges-reference.md#select).

Because a materialized table can hold more than one feature, granting `SELECT` on it grants access to every feature in that table, not only the one you intend to serve. Before you grant serving access, confirm that every feature sharing the table can be shared with the principal. To limit exposure, materialize sensitive features separately.

To grant this access without resolving tables by hand, use `FeatureEngineeringClient.grant_feature_serving_access`. Given a model or feature spec, it resolves each feature to its online table, grants `SELECT` (along with `USE CATALOG` and `USE SCHEMA`) on those tables to the principals you specify, and returns a report of each table and the additional features the grant exposes. Pass `dry_run=True` to preview the report before granting.

```python
from databricks.feature_engineering import FeatureEngineeringClient

fe = FeatureEngineeringClient()

# Preview the tables and the features each grant would expose.
report = fe.grant_feature_serving_access(
    grant_to=["serving-principal@example.com"],
    model_uri="models:/main.ecommerce.fraud_model/1",
    dry_run=True,
)
print(report)

# Grant SELECT on the resolved online tables.
fe.grant_feature_serving_access(
    grant_to=["serving-principal@example.com"],
    model_uri="models:/main.ecommerce.fraud_model/1",
)
```

## Deploy a model serving endpoint

Use an existing model serving endpoint, or use the Databricks SDK to create a new one. The model must be registered in Unity Catalog.

If a `CustomUDF` uses a user-defined function (UDF) that imports Python packages, pass them explicitly through `extra_pip_requirements` when you call `log_model`. See [Custom UDF dependencies](https://docs.databricks.com/aws/en/machine-learning/feature-store/train-with-declarative-features.md#custom-udf-dependencies).

The following code shows how to create a new model serving endpoint. For more information, see [Create custom model serving endpoints](https://docs.databricks.com/aws/en/machine-learning/model-serving/create-manage-serving-endpoints.md).

```python
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import EndpointCoreConfigInput, ServedEntityInput

w = WorkspaceClient()

endpoint_name = "fraud-detection-endpoint"
model_name = "main.ecommerce.fraud_model"

w.serving_endpoints.create(
    name=endpoint_name,
    config=EndpointCoreConfigInput(
        name=endpoint_name,
        served_entities=[
            ServedEntityInput(
                entity_name=model_name,
                entity_version=1,
                max_provisioned_concurrency=4,
                min_provisioned_concurrency=0,
            )
        ],
    ),
)
```

## Query the endpoint

```python
from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

response = w.serving_endpoints.query(
    name="fraud-detection-endpoint",
    dataframe_records=[
        {"user_id": "user_123", "transaction_time": "2026-03-01T12:00:00"},
    ],
)
```

## Query the endpoint with RequestSource features

If the model was trained with `RequestSource` features, the request payload must also include all `RequestSource` columns. These columns were added to the MLflow model signature during `log_model`, so the endpoint's API schema reflects the required request fields.

```python
response = w.serving_endpoints.query(
    name="fraud-detection-endpoint",
    dataframe_records=[
        {
            "user_id": "user_123",
            "transaction_time": "2026-03-01T12:00:00",
            "transaction_amount": 275.30,  # RequestSource column
            "vendor_id": "v_42",           # RequestSource column (also used as entity key)
        },
    ],
)
```

Entity keys are used for looking up table-backed features from the online store. A `ColumnSelection` feature can pass a `RequestSource` value through to the model. A `CustomUDF` feature transforms its request inputs before the model uses the result.

You can also use `curl`:

```bash
curl -X POST "https://<workspace>.cloud.databricks.com/serving-endpoints/<endpoint>/invocations" \
  -H "Authorization: Bearer $DATABRICKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "dataframe_records": [
      {
        "user_id": "user_123",
        "transaction_time": "2026-03-01T12:00:00",
        "transaction_amount": 275.30,
        "vendor_id": "v_42"
      }
    ]
  }'
```

## <a id="serve-features-with-a-featurespec" />Serve features with a `FeatureSpec`

To serve Feature Views without a model, create a `FeatureSpec` that references the features and deploy it to a Feature Serving endpoint. The endpoint returns only the feature outputs requested in the spec. It computes intermediate values automatically without returning them unless you also request those features.

Register all of the features in Unity Catalog and create supported online materializations for the table- and stream-backed leaves before you create the endpoint.

To declare the `FeatureSpec` and the endpoint in a bundle instead, see [Serve Feature Views using Declarative Automation Bundles](https://docs.databricks.com/aws/en/dev-tools/bundles/feature-store-serving-tutorial.md).

> [!NOTE]
>
> A `FeatureSpec` that contains Feature Views cannot also contain `FeatureLookup` or `FeatureFunction` definitions. Feature Views cannot be mixed with those definitions in the same `FeatureSpec`.

```python
from databricks.feature_engineering import FeatureEngineeringClient
from databricks.feature_engineering.entities.feature_serving_endpoint import (
    EndpointCoreConfig,
    ServedEntity,
)

fe = FeatureEngineeringClient()

# 1. Retrieve a registered Feature View
agg_feature = fe.get_feature(full_name="main.ecommerce.amount_sum_sliding_7d_1d")

# 2. Create a FeatureSpec that includes the Feature View
feature_spec_name = "main.ecommerce.transaction_feature_spec"
fe.create_feature_spec(name=feature_spec_name, features=[agg_feature])

# 3. Deploy a Feature Serving endpoint backed by the FeatureSpec
fe.create_feature_serving_endpoint(
    name="transaction-features",
    config=EndpointCoreConfig(
        served_entities=ServedEntity(
            feature_spec_name=feature_spec_name,
            workload_size="Small",
            scale_to_zero_enabled=True,
        )
    ),
)
```

Query the endpoint with the entity keys used to look up the materialized features:

```python
from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

response = w.serving_endpoints.query(
    name="transaction-features",
    dataframe_records=[{"user_id": "user_123"}],
)
```

For more about Feature Serving endpoints see [Serve feature tables](https://docs.databricks.com/aws/en/machine-learning/feature-store/feature-function-serving.md).

### <a id="serve-derived-features" />Serve CustomUDF features and their dependencies

This example serves the transaction and margin features defined in the [`CustomUDF`](https://docs.databricks.com/aws/en/machine-learning/feature-store/feature-views-api-reference.md#customudf) and [`FeatureViewSource`](https://docs.databricks.com/aws/en/machine-learning/feature-store/feature-views-api-reference.md#featureviewsource) examples. Use `databricks-feature-engineering` version 0.18.0 or above for these Feature Views APIs.

* `log_transaction_amount` applies `main.ecommerce.log_amount_udf` to the request's `transaction_amount` value using NumPy.
* `margin` uses `FeatureViewSource` to compute a margin from `revenue_sum_7d` and `cost_sum_7d`. These upstream features use `customer_id` as their entity key and `event_time` as their timeseries column.

Register both output features and every upstream feature before creating the spec. For this example, online-materialize only the `revenue_sum_7d` and `cost_sum_7d` leaves. Serving looks up their values and computes `margin` for each request.

Retrieve the registered `Feature` objects and pass them to `create_feature_spec`. Declare NumPy for online execution even if it is already listed in the UDF's `ENVIRONMENT` clause:

```python
from databricks.feature_engineering import FeatureEngineeringClient

fe = FeatureEngineeringClient()
log_transaction_amount = fe.get_feature(
    full_name="main.ecommerce.log_transaction_amount"
)
margin = fe.get_feature(full_name="main.ecommerce.margin")

fe.create_feature_spec(
    name="main.ecommerce.derived_transaction_features",
    features=[log_transaction_amount, margin],
    extra_pip_requirements=["numpy==1.26.4"],
)
```

Follow the endpoint creation steps above with `feature_spec_name="main.ecommerce.derived_transaction_features"` and an endpoint name such as `derived-transaction-features`. After the endpoint is ready, supply the lookup key and request-time value:

```python
from databricks.sdk import WorkspaceClient

w = WorkspaceClient()
response = w.serving_endpoints.query(
    name="derived-transaction-features",
    dataframe_records=[
        {"customer_id": "customer_123", "transaction_amount": 99.0},
    ],
)
```

The response contains only the requested `log_transaction_amount` and `margin` outputs, not the intermediate revenue and cost values. For dependency formats, wheel permissions, and installation troubleshooting, see [Add Python dependencies](https://docs.databricks.com/aws/en/machine-learning/feature-store/feature-function-serving.md#python-dependencies).
