WritingDatabricks (DBRX)Databricks (DBRX)published Nov 23, 2026seen 4d

Announcing General Availability of native Lakebase Postgres sink for Spark Structured Streaming

Open original ↗

Captured source

source ↗

Announcing General Availability of native Lakebase Postgres sink for Spark Structured Streaming | Databricks Blog Skip to main content

Summary

Announcing General Availability of the native Lakebase sink for Apache Spark™ Structured Streaming: stream computed results directly into Lakebase with a single writeStream call, replacing custom foreach writers.

Learn how Real-Time Mode and the native Lakebase sink together enable real-time feature computation and ingestion into Lakebase in one streaming pipeline.

See it in action on a real-time feature pipeline, upserting ~20K EPS for 5 million users into Lakebase at p99 under 500 ms, end-to-end.

Low-latency use cases like fraud detection, live personalization, and real-time feature computation need computed results in a serving-ready OLTP store. Lakebase Postgres is Databricks' fully managed, serverless PostgreSQL database offering, with autoscaling, branching, native Unity Catalog integration, and sub 10ms reads. But writing to it from a streaming pipeline has meant building a custom foreach writer and handling batching, retries, and upserts yourself, which is complex to get right and hard to keep performant under load. Today, we are announcing the general availability of the native Lakebase sink for Apache Spark™ Structured Streaming, a connector that writes computed results directly to Lakebase and handles all of that for you. The same connector works in both micro-batch and Real-Time Mode . We show it on a feature pipeline that ingests watch and like events from a video streaming platform, computes each user's recent activity, and upserts one feature row per user into Lakebase in hundreds of milliseconds. You get that performance without building or maintaining the connector yourself. Why the native Lakebase sink matters The problem it solves A foreach writer has to do a lot at once: batch writes for throughput, a bounded queue for backpressure, pool connections and refresh OAuth tokens, retry transient failures with backoff, deduplicate within a batch. It also has to implement upsert semantics correctly, including keeping the greatest timestamp or updating a column only when an incoming event has a newer ordering value. Even for an experienced developer, writing and tuning all of this is weeks of work, and it does not end there. The connector turns into something you maintain, fixing throughput regressions, credential refresh, and keeping the code current with the latest versions. For a sense of what that looks like in practice, see this reference implementation . "We stream real-time data into Lakebase so our risk agent can pull a user's recent activity when it investigates an alert. We initially built that path with a custom ForeachWriter, which meant building and maintaining the write infrastructure ourselves. As part of our development work, we found that the native sink reduces the custom work required for connection pooling, batching, and retries."  - Maria Marinova , Sr. Lead Software Engineer, DraftKings

What it handles for you The native sink takes care of it. You wire up a Lakebase write in minutes with a single writeStream call, and spend no time on performance, tuning, or maintaining the connector. You get: Ease of use: no custom sink code; batching, connection reuse, and error handling are built in. Upserts: declare an upsertkey and the sink maintains one row per key. Merge strategies for upserts: declarative custom merge logic for how non-key columns update on conflict. See supported merge strategies . Reliable delivery: transient JDBC errors (connection failures, deadlocks, rate limiting) are retried automatically with exponential backoff. A familiar API: the same writeStream and .toTable() used for Unity Catalog tables. Tunable batching: optional caps on batch size and interval when the defaults don't fit your SLA. UC-managed authentication: the connector authenticates to Lakebase automatically as the running user or service principal.

"Testing real-time data flows into Lakebase is an important part of validating how our risk agent can quickly access the freshest available user data when making decisions. As we evaluated the native sink, we found that its built-in connection pooling, batching, and retries reduce the custom infrastructure we need to build and maintain." - Georgi Stoychev , Sr. Software Automation Engineer, DraftKings

Example: A real-time feature pipeline for recommendation systems Use case A video streaming provider wants to recommend videos to its viewers. A recommendation model needs what users watched most recently. So for each user we compute the last 6 videos they watched and the last 3 they liked. We store that as one row per user in Lakebase. At inference time, the recommendation model looks up that row by user_id to rank what to show next. The pipeline A feature is an input the model uses to make a prediction. Here, the features are each user's recent activity, computed from a stream of events. Each event has a user_id and a video_id and an event type (WATCH/LIKE). For each user we keep their recent watches and likes as one row, keyed by user_id . Every new event for a user_id updates that row in place. The pipeline is three stages: Stream: read engagement events from Kafka. Transform: group by user_id and maintain each user's last-6 watched and last-3 liked with transformWithState , emitting one feature row per user. Write: upsert that row into Lakebase with the native sink.

Writing to Lakebase Writing to Lakebase is a single writeStream call. How you point it at Lakebase depends on whether the target table is registered in Unity Catalog. If the Lakebase table is registered in Unity Catalog , write with .toTable() using the fully qualified catalog.schema.table . The connector manages credentials as the running user or service principal, and creates the table if it doesn't exist:

If the Lakebase table isn't registered in Unity Catalog, write to the Lakebase endpoint directly with format("postgresql") (see Lakebase tables not registered with Unity Catalog ). The same format("postgresql") path also supports writing to external PostgreSQL databases (e.g. Amazon RDS or self-hosted) via a Unity Catalog connection (DBR 19+, Public Preview). Serving the features The sink writes the features into Lakebase within 100-200 milliseconds of being produced, with no offline-to-online sync in between. Applications and models can query them in single-digit...

Excerpt shown — open the source for the full document.

Notability

notability 5.0/10

Databricks GA feature for Spark Streaming Postgres sink.