Orchestra AIBy Hyperdrift

AI engineering / Databases and agent state

Lakebase vs MongoDB and Cosmos DB: which approach fits?

Compare Lakebase’s Postgres approach with MongoDB and Cosmos DB document models: relationships, transactions, use cases and when Databricks integration matters.

By Yann VR · 4 min readShare article ↓Discuss your agent data model →

Databricks Lakebase is managed Postgres; MongoDB and Azure Cosmos DB's document model organise data around documents. Choose the relational approach when relationships, shared constraints and transactions across records drive the application. Consider documents when the workload mainly reads and changes independent, nested records. Lakebase adds a separate reason to choose it: integration with an existing Databricks platform.

That is the useful comparison for AI applications. An agent producing JSON does not settle the database choice. This guide compares the approaches, then uses a refund and a support case to show where each can fit. The examples are illustrative designs, not benchmarks or client results.

What is the difference between Lakebase and document databases?

Lakebase provides a managed Postgres backend integrated with Databricks. In a relational design, customers, orders and approvals can live in separate tables, connected by keys. SQL joins and constraints help express relationships and rules across those records. Postgres also supports JSON storage and indexing, so relational data need not mean rigid rows for every attribute.

A document model groups related fields into a nested record. A support case might contain messages, device details and review notes. MongoDB's modelling guidance starts from access patterns: information read together is often stored together. That can simplify retrieving a complete case, while relationships across documents still need deliberate design. Flexible fields do not remove validation or indexing work.

Lakebase is a particular service; document databases are a category. MongoDB and Cosmos DB also have different capabilities. Compare the model first, then the service and its documented transaction scope.

How do their transactions differ?

Postgres can commit related table changes in one transaction. A unique operation identifier can reject duplicate writes; constraints can enforce relationships independently of the agent.

MongoDB supports both single-document atomic writes and multi-document transactions. A document design does not give up transactions. Evaluate the actual records, queries and deployment before assuming a relational migration is necessary.

Azure Cosmos DB transactional batches apply to operations with the same logical partition key. For the document model discussed here, check whether the business operation fits that boundary. Do not generalise one API's guarantees to every Cosmos offering.

Choose around relationships and write boundaries; JSON alone does not choose your database.

WORKED EXAMPLE / REFUND

What has to change together?

For this refund, start with Postgres. The case document answers a different need.

£40refund
BUSINESS OPERATIONrefund_1042One identity across every retry
01 / FIRST CHOICE FOR THIS REFUND

Postgres / Lakebase

ONE TRANSACTION
  1. C
    Customerbalance
    updated
  2. R
    Refundoperation_id
    1042
  3. A
    Approvaldecision
    allowed

Commit the related changes together

Separate records. Shared business rules.

02 / CASE-FIRST ALTERNATIVE

A support-case document

CASE / 1042

messagesconversation

proposal£40 refund

reviewapproved

Read and update the case as a unit

Customer balanceSeparate record → define its transaction boundary
BEYOND EITHER DATABASEThe payment provider

Use provider idempotency
and a recoverable workflow.

For this refund, start with Postgres. Balance, refund and approval can commit together. MongoDB can transact across documents; Cosmos DB document batches need one logical partition key.

Illustrative design · No benchmark or executed refund
For this refund, start with Postgres; the payment provider needs its own retry protection. Save the visual ↓
Explanation and primary sources

For the illustrated refund, start with Postgres: related customer balance, refund and approval records can commit in one transaction. Lakebase is a managed Postgres choice when Databricks integration matters. A support-case document groups messages, proposal and review state, but a separately stored balance needs an explicit cross-document design. MongoDB supports multi-document transactions; Cosmos DB document API batches share one logical partition key. A provider payment sits beyond either database transaction, requiring provider idempotency and a recoverable workflow. The duplicate-request control illustrates looking up a recorded operation rather than starting a new payment.

Reviewed 22 September 2026 · Illustrative design, not a client result.

When is the relational approach a better fit?

Consider a £40 refund. The application must update a customer balance, record the refund, retain its approval and recognise a repeated request. Those records share rules even though they represent different things. I would start with Postgres for this design, keeping the related database changes inside one transaction. The diagram illustrates that boundary.

A payment provider remains outside the database transaction. Use its idempotency mechanism and a recoverable workflow so a lost response cannot trigger a second payment. The streaming and recovery guide follows this failure through the interface.

When is a document database a better fit?

Consider a support assistant handling independent product issues. Each case contains messages, screenshot links, product-specific attributes and a generated summary. The interface usually reads and updates the whole case; no shared balance changes. A document database is a natural starting point for this workload because the main access pattern matches one self-contained record.

This is a fit recommendation, not proof that documents are faster. If the organisation already operates Postgres, its JSON support may be simpler than adding another service. Conversely, an established MongoDB application may already handle the refund safely with transactions.

Which approach should you choose for an AI application?

Choose relational modelling when relationships, joins and shared business rules dominate. Choose document modelling when independent, evolving records dominate the reads and writes. Test both against the actual transaction boundaries, query patterns, recovery needs and operating cost.

Choose Lakebase specifically when Postgres fits and Databricks integration removes meaningful work. Otherwise, include ordinary managed Postgres in the service comparison. Regional availability, authentication, recovery and connection behaviour still need checking; no universal cost or performance winner follows from the data model.

Bring the question back to the application: which facts must stay consistent together, and what does it usually retrieve? Send this comparison to the engineer choosing the data store. Bring your current stack and one operation to discuss your agent data model.

Know someone working on this? Pass it on.

Put the idea to work

What would this look
like for you?

Tell us about one workflow and the tools involved. We’ll discuss where agents could help and which decisions should stay with your team.

A personal reply within one working day.

We’ll use these details to reply to your enquiry.