<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/build-durable-agents-with-temporal-and-lakebase-6rvqp9o1r" -->

---
title: Build durable agents with Temporal and Lakebase | daily.dev
description: A reference implementation demonstrates building a durable personal-loan underwriting agent using Temporal for control-flow execution and Databricks Lakebase...
canonical: https://daily.dev/posts/build-durable-agents-with-temporal-and-lakebase-6rvqp9o1r
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Build durable agents with Temporal and Lakebase | daily.dev
og:description: A reference implementation demonstrates building a durable personal-loan underwriting agent using Temporal for control-flow execution and Databricks Lakebase...
og:url: https://daily.dev/posts/build-durable-agents-with-temporal-and-lakebase-6rvqp9o1r
og:image: https://api.daily.dev/og/posts/6rvQp9O1r.png
og:image:alt: Build durable agents with Temporal and Lakebase
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Build durable agents with Temporal and Lakebase

**[databricks](https://daily.dev/sources/databricks)** · 13 min read · 0 upvotes · 0 comments

## Summary

A reference implementation demonstrates building a durable personal-loan underwriting agent using Temporal for control-flow execution and Databricks Lakebase Postgres for queryable operational state. Temporal's Event History drives Workflow replay and recovery after worker crashes, while Lakebase stores application-facing state (run status, messages, evidence, review decisions) that FastAPI can query with SQL. A synced table exposes Unity Catalog policy data to the running agent, and Change Data Feed (currently in Public Preview) can propagate Lakebase changes back to Unity Catalog Delta history tables for audit purposes. The piece walks through deterministic identifiers, guarded upserts, retry policies, and idempotency patterns needed because Temporal and Lakebase do not share a transaction, plus deployment considerations like OAuth credential rotation, autoscaling, and Temporal Cloud pricing.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.databricks.com/blog/build-durable-agents-temporal-and-lakebase>

## Questions this post answers

### How do I prevent duplicate writes to Postgres when a Temporal Activity retries after the worker loses connection?

Use deterministic identifiers combined with guarded upsert statements. An INSERT ... ON CONFLICT DO UPDATE targets a stable id (such as tool_call_id) and includes a WHERE clause that only allows updates when the row is still in a nonterminal status, so a retry after a committed write but lost completion signal affects zero rows instead of corrupting state, and that zero-row result must be checked by the caller.

_Developers wiring idempotent writes into agent workflows track these Temporal and Postgres patterns on daily.dev._

### What is the difference between Temporal Event History and application state stored in a database for an AI agent?

Event History drives Workflow replay and execution semantics, recording activity scheduling, results, timers, and signals needed to reconstruct control flow after a crash. A relational store like Lakebase Postgres instead holds the application-facing view, current run status, messages, evidence, and review state, so an application can run indexed SQL queries without treating that database as part of Temporal's replay mechanism.

_Teams designing durable agent architectures follow this Temporal-Postgres split on daily.dev._

### Why would a model call in a Temporal-based agent run twice even though the model provider already finished processing it?

If an Activity was in flight when the worker failed and Temporal never recorded its completion, Temporal schedules another attempt regardless of whether the external provider actually finished the call, because Temporal only trusts recorded results in Event History. Already-recorded model responses are safely returned during replay, but an unrecorded completion can cause a duplicate call.

_Engineers debugging retry behavior in long-running agents track these Temporal execution details on daily.dev._

## Similar posts on daily.dev

- [Simplify AI agent orchestration with Lakebase Postgres](https://daily.dev/posts/simplify-ai-agent-orchestration-with-lakebase-postgres-cfdi4m6tk) · databricks · 6 upvotes · 0 comments
- [Databricks wants to merge the two databases every company runs](https://daily.dev/posts/databricks-wants-to-merge-the-two-databases-every-company-runs-mivqdovba) · The New Stack · 2 upvotes · 0 comments
- [Every AI Agent May Need PostgreSQL. Not Every Agent Should Own the Truth.](https://daily.dev/posts/every-ai-agent-may-need-postgresql-not-every-agent-should-own-the-truth--gponqmm61) · Planet PostgreSQL · 0 upvotes · 0 comments
- [How to Build Production-Ready Data and AI Apps with Databricks Apps and Lakebase](https://daily.dev/posts/how-to-build-production-ready-data-and-ai-apps-with-databricks-apps-and-lakebase-u6tqwxua6) · databricks · 1 upvotes · 0 comments

---

Tags: [#ai-agents](https://daily.dev/tags/ai-agents), [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/build-durable-agents-with-temporal-and-lakebase-6rvqp9o1r)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Build durable agents with Temporal and Lakebase","url":"https://daily.dev/posts/build-durable-agents-with-temporal-and-lakebase-6rvqp9o1r","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/build-durable-agents-with-temporal-and-lakebase-6rvqp9o1r"},"datePublished":"2026-09-08T17:13:06.098Z","dateModified":"2026-09-08T17:34:12.946Z","description":"A reference implementation demonstrates building a durable personal-loan underwriting agent using Temporal for control-flow execution and Databricks Lakebase...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c6b3d06f5861756ef676ce5f057c4cad?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c6b3d06f5861756ef676ce5f057c4cad?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"databricks","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"databricks","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/fa7aa720f2db4d1eba826814730482c8","url":"https://daily.dev/sources/databricks"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/build-durable-agents-with-temporal-and-lakebase-6rvqp9o1r","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ai-agents,postgresql","timeRequired":"PT13M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"databricks","item":"https://daily.dev/sources/databricks"},{"@type":"ListItem","position":3,"name":"Build durable agents with Temporal and Lakebase"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/build-durable-agents-with-temporal-and-lakebase-6rvqp9o1r#faq","mainEntity":[{"@type":"Question","name":"How do I prevent duplicate writes to Postgres when a Temporal Activity retries after the worker loses connection?","acceptedAnswer":{"@type":"Answer","text":"Use deterministic identifiers combined with guarded upsert statements. An INSERT ... ON CONFLICT DO UPDATE targets a stable id (such as tool_call_id) and includes a WHERE clause that only allows updates when the row is still in a nonterminal status, so a retry after a committed write but lost completion signal affects zero rows instead of corrupting state, and that zero-row result must be checked by the caller. Developers wiring idempotent writes into agent workflows track these Temporal and Postgres patterns on daily.dev."}},{"@type":"Question","name":"What is the difference between Temporal Event History and application state stored in a database for an AI agent?","acceptedAnswer":{"@type":"Answer","text":"Event History drives Workflow replay and execution semantics, recording activity scheduling, results, timers, and signals needed to reconstruct control flow after a crash. A relational store like Lakebase Postgres instead holds the application-facing view, current run status, messages, evidence, and review state, so an application can run indexed SQL queries without treating that database as part of Temporal's replay mechanism. Teams designing durable agent architectures follow this Temporal-Postgres split on daily.dev."}},{"@type":"Question","name":"Why would a model call in a Temporal-based agent run twice even though the model provider already finished processing it?","acceptedAnswer":{"@type":"Answer","text":"If an Activity was in flight when the worker failed and Temporal never recorded its completion, Temporal schedules another attempt regardless of whether the external provider actually finished the call, because Temporal only trusts recorded results in Event History. Already-recorded model responses are safely returned during replay, but an unrecorded completion can cause a duplicate call. Engineers debugging retry behavior in long-running agents track these Temporal execution details on daily.dev."}}]}
```

