---
title: Using Lakebase with Databricks Apps
description: Connect a Lakebase database to a Databricks app using a template to store transactional data in managed Postgres
canonical_url: https://docs.databricks.com/gcp/en/oltp/projects/databricks-apps
---

# Using Lakebase with Databricks Apps

Databricks Apps lets you build and deploy interactive applications directly in your Databricks workspace. Adding Lakebase as a resource gives your app a fully managed Postgres backend. Databricks creates a service principal for your app, grants it a matching Postgres role, and injects connection details as environment variables. Your app connects to a fully managed Postgres database without managing credentials or connection strings.

![Architecture diagram showing client, Databricks Apps, and LKB integration](https://docs.databricks.com/gcp/en/images/oltp/lakebase-apps-architecture.png)

This tutorial walks you through deploying a template app connected to a Lakebase database. By the end, you'll have a running app with data you can inspect and query directly from Lakebase, and optionally register in Unity Catalog alongside your lakehouse data.

## <a id="prerequisites" />Prerequisites

Before you begin, make sure you have the following:

* Access to a Databricks workspace with Lakebase and [serverless compute](https://docs.databricks.com/gcp/en/compute/serverless/index.md) enabled. Contact your workspace admin if needed.
* Permission to create compute resources and apps.

## <a id="provision-lakebase" />Step 1: Provision a Lakebase project

A Lakebase project is a managed Postgres instance that your app connects to as a resource. Projects are organized into [branches](https://docs.databricks.com/gcp/en/oltp/projects/manage-branches.md), each representing an isolated database environment.

To create a Lakebase project, see [Get a Postgres database](https://docs.databricks.com/gcp/en/oltp/projects/get-started.md). Lakebase creates your project with a `production` branch and a `databricks_postgres` database.

## <a id="create-app" />Step 2: Create a Databricks app

Databricks provides three autoscaling app templates that demonstrate Lakebase integration using a todos app: Dash, Flask, and Streamlit. To create an app from a template:

1. In your Databricks workspace, click the ![App icon.](https://docs.databricks.com/gcp/en/images/product-icons/AppIcon.svg) app switcher and select **Databricks Apps**.
2. Click **+ Create app**.
3. Select your preferred template from the **Database** tab.

![Flask + LKB app template](https://docs.databricks.com/gcp/en/images/oltp/lakebase-postgres-app-template.png)

## <a id="configure-database" />Step 3: Configure a database resource

Adding Lakebase as a resource creates a service principal with the correct database permissions and injects your connection details as [environment variables](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/lakebase.md#lakebase-variables) into the app. This lets the template connect to your database automatically, without any connection strings in your code.

In the **Configure** step, configure the following settings.

1. For **App resources**, select your Lakebase project, branch, and database. Branch names appear as IDs. To match IDs to names, see your project's [branches page](https://docs.databricks.com/gcp/en/oltp/projects/manage-branches.md).
2. For **Compute size**, select **Medium**. This controls [app server compute](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/compute-size.md), which is separate from the Lakebase database compute and scales independently.

![Database resource configuration showing project, branch, and database selection](https://docs.databricks.com/gcp/en/images/oltp/app-database-resource-config.png)

For more information, see [Add a Lakebase resource to a Databricks app](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/lakebase.md).

## <a id="review-auth" />Step 4: Review authorizations

Each Databricks app runs as its own [service principal](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/auth.md), a dedicated identity separate from any individual user. When you connect Lakebase as a resource, Databricks creates a matching [Postgres role](https://docs.databricks.com/gcp/en/oltp/projects/postgres-roles.md) for that service principal and grants it full database access. No manual role setup is required.

![Authorization review showing service principal permissions](https://docs.databricks.com/gcp/en/images/oltp/app-authorization-review.png)

## <a id="name-app" />Step 5: Name your app and install

Lakebase uses the app name to generate a schema name in the format `{app-name}_schema_{service-principal-id}` (hyphens removed from the ID). You can't change the app name after creation, but you can rename the schema later. The template defaults to `lakebase-autoscaling-app`.

Click **Create app** to create the app.

## <a id="deploy" />Step 6: Deploy the app

After you create the app, compute starts automatically and your app deploys in about 2-3 minutes without any further action. When the app status shows **Running**, click the URL next to it to open your app.

![App overview showing Running status and active compute](https://docs.databricks.com/gcp/en/images/oltp/app-running-status.png)

## <a id="verify" />Step 7: Verify the integration

Add a few todos in your app. In your Lakebase project, open **Tables** and select the todos table under your app's schema. The app's service principal wrote those rows using the connection details injected in Step 3.

![LKB Tables view showing todos written by the app](https://docs.databricks.com/gcp/en/images/oltp/lakebase-tables-todos.png)

To query the data directly, use the SQL Editor in your Lakebase project. Because Lakebase scales to zero when idle, the first query after a long pause might take a few seconds to respond. For other connection options, see [Connect to your database](https://docs.databricks.com/gcp/en/oltp/projects/connect.md).

## <a id="uc-fed" />Step 8: Query through Unity Catalog (optional)

By default, your app's Lakebase data is accessible directly through Postgres connections. Registering it in Unity Catalog makes it queryable alongside your lakehouse data using standard Databricks SQL. You can then join your app's transactional tables with Delta tables in the same query.

To register, open Catalog Explorer and create a new catalog. Select **Lakebase Postgres** as the catalog type, choose **Autoscaling**, and select the same project and branch as your app. See [Register a Lakebase database in Unity Catalog](https://docs.databricks.com/gcp/en/oltp/projects/register-uc.md) for full details.

Note that schema names in Unity Catalog preserve hyphens from your app name. Both the catalog and schema names require backtick quoting:

```sql title="Databricks SQL"
SELECT * FROM `your-catalog-name`.`lakebase-autoscaling-app_schema_aeb6ff9198ff4752af7dfc6d4cf570d0`.todos;
```

## <a id="additional-resources" /> Additional resources

* [Get started with Databricks Apps](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/get-started.md)
* [Develop Databricks apps](https://docs.databricks.com/gcp/en/dev-tools/databricks-apps/app-development.md)
* [Connect to your database](https://docs.databricks.com/gcp/en/oltp/projects/connect.md)
