Databricks Lakebase Data API: PostgreSQL REST API Access.

When your app needs a single row from a database, how you connect matters. The classic route is JDBC (Java Database Connectivity), a driver your application installs to talk to the database directly. Although it’s usually the faster option, you can't always use it. In an AWS Lambda function, a Lovable edge function or similar environments, you often can't install a driver at all.

A REST API gets around that. You send a plain HTTP request and get the row back, with no driver to install. It's also much easier to cache than JDBC.

Lakebase now offers this through the Lakebase Data API, which exposes your Postgres tables over HTTP. When Databricks CLI 1.25.0 added support for postgres_data_apis in Declarative Automation Bundles (DABs), I decided to try it myself. The bundle resource is currently in Private Preview.

How can I get data from Lakebase?

  • Lakebase Data API: use HTTP to read or change rows in Postgres. GET reads an order, POST creates one, and PATCH updates it.

  • JDBC: connect your app directly to Lakebase to run SQL or manage a transaction. In Python, psycopg serves the same purpose.

  • Databricks SQL: register Lakebase in Unity Catalog to join live orders with Delta tables. A serverless warehouse can read the registered orders.

How can I enable the Lakebase Data API?

In your Lakebase project, choose App Backend → Data API → Enable Data API. Screenshot from the Databricks setup guide.

What does parent mean in a Lakebase bundle?

A Declarative Automation Bundle (DAB) can enable the Lakebase Data API with postgres_data_apis. This bundle resource is in Private Preview.

parent tells Databricks which database gets the REST API. In this example, demo is a Lakebase project defined elsewhere in the bundle. The bundle fills in the project’s resource name and selects the default database on the production branch.

resources:
  postgres_data_apis:
    orders_api:
      parent: ${resources.postgres_projects.demo.name}/branches/production/databases/databricks-postgres
      db_schemas: [public]
      db_max_rows: 50

orders_api is the name I gave this resource in the bundle. I set db_schemas to expose the public schema where the orders table lives. I set db_max_rows to 50 so a single request returns at most 50 rows. Here’s the table I used.

CREATE TABLE public.orders (
  order_id bigint PRIMARY KEY,
  tenant_id integer NOT NULL,
  amount_cents bigint NOT NULL
);
INSERT INTO public.orders VALUES (42, 10, 714);

Lakebase Data API Python example

For the Python example, I sent a GET request to /public/orders. I used eq.42 to match order 42 and select to ask for just the order ID, tenant ID, and amount in cents.

import os
import requests

url = os.environ["API_URL"].rstrip("/") + "/public/orders"
token = os.environ["DATABRICKS_TOKEN"]
r = requests.get(
    url, headers={"Authorization": f"Bearer {token}"},
    params={"order_id": "eq.42",
            "select": "order_id,tenant_id,amount_cents"},
    timeout=15,
)
r.raise_for_status()
print(r.json())

Lakebase Data API operations at a glance

What else can an app do besides GET /public/orders ?

The table lists the available HTTP methods and when to use them.

Is the Lakebase Data API faster than JDBC?

For order 42, I measured a median of 4.56 ms on the JDBC connection. The same lookup over the Lakebase Data API took 6.31 ms. That gives JDBC a 1.75 ms advantage here. If I only need one row and the machine has no JDBC driver, I can usually make the HTTP call faster than it takes to set up JDBC. Additionally, HTTP is very cacheable, either in clients or in proxies, which will make repetitive requests faster.

How can I read Lakebase CDC over REST?

  • Use Lakebase Change Data Feed when you want order history in Delta for analytics or downstream pipelines. The feed requires REPLICA IDENTITY FULL on the source table.

  • Use Triggers on Data Changes when your app needs order history over REST. One GET to /public/orders_cdc uses the same Lakebase Data API as /public/orders.

When I looked for a way to read an order’s history, I found examples that used Lakebase Change Data Feed (CDF). That approach sends changes to Delta through a pipeline, then uses a SQL warehouse to query them. For an app that needs the latest change to one order, those extra steps add cost and delay. A Postgres trigger lets me read the history directly through the Lakebase Data API.

1. REPLICA IDENTITY FULL and Lakebase CDF

On the orders table, I start by setting the replica identity to FULL.

ALTER TABLE orders REPLICA IDENTITY FULL;

After running that SQL, I open the Lakebase UI and set up the pipeline that copies order changes to the lakehouse.

The feed writes changes to Delta in batches about every 15 seconds, so the new amount can take time to appear after the order commits.

To read the change over REST, run a query on a SQL warehouse through the Databricks SQL Statement Execution API. 

2. Triggers on Data Changes

With a native Postgres trigger, the app can read the history table through the Lakebase Data API.

An AFTER trigger on public.orders writes one history row in the same transaction. 

CREATE OR REPLACE TRIGGER orders_capture_change
AFTER INSERT OR UPDATE OR DELETE ON public.orders
FOR EACH ROW EXECUTE FUNCTION public.capture_order_change();

Grant your Data API reader SELECT on public.orders_cdc and refresh the schema cache in the Data API tab. 

fields = "order_id,operation,old_amount_cents,new_amount_cents" r = requests.get( os.environ["API_URL"].rstrip("/") + "/public/orders_cdc", headers={"Authorization": f"Bearer {token}"}, params={"order_id": "eq.42", "select": fields, "order": "event_id.desc", "limit": 1}, timeout=15, ) r.raise_for_status() print(r.json())

How much does the Lakebase REST API cost?

Databricks lists no separate fee for a Data API application or for individual requests. Each REST call uses your Lakebase compute. You pay for the Lakebase compute and storage you use.

For an app reading one order’s history, the trigger adds one Postgres write per change and uses Lakebase storage for the history table. The app can avoid Delta storage and SQL warehouse charges for that lookup. With managed CDF, capture runs inside Lakebase compute. You pay for Delta storage and for the warehouse compute used to query it.

How can I set up a read-only service principal?

For a read-only app, give a dedicated service principal CAN USE on the project. Grant its Postgres role to authenticator, then give that role USAGE on public and SELECT on public.orders.

How do I migrate the Lakebase Data API from the UI to DABs?

If you enabled the API in the UI, bind it to orders_api once. From your bundle folder, run these CLI commands with your Lakebase project ID.

$api = "projects/<project-id>/branches/production/databases/databricks-postgres/data-api"
databricks bundle deployment bind orders_api $api
databricks bundle deploy

TL;DR

Use the Lakebase Data API to read or write an order over HTTP, and use JDBC when you need SQL and transactions in Postgres. If your app needs the latest change to an order, use a Postgres trigger and read orders_cdc through the Data API. Choose managed Change Data Feed (CDF) when you want the history in Delta for analytics.

Hubert Dudek

Databricks MVP | Advisor to Databricks Product Board and Technical advisor to SunnyData

https://www.linkedin.com/in/hubertdudek/
Next
Next

Beyond Chat History: Lakebase as the Operational Backend for AI Agents.