# Cloudflare Durable Objects vs local SQLite with Litebackup

Litebackup backs up SQLite files your app already opens, while a Durable Object runs your code alongside a private SQLite database on Cloudflare.

## Can I keep my existing SQLite app?

**With Litebackup, yes.** Keep your driver, schema and queries. After you [join the app host to Litebackup](/back-up-sqlite-while-your-app-writes), run `litebackup start /var/lib/app/documents.sqlite`. Your app keeps writing to that file while Litebackup backs it up.

**With Durable Objects, move the code that reads and writes the database into an object.** A Cloudflare Worker calls the object by ID. This suits a collaborative editor or chat room because Cloudflare routes everyone working on the same document or room to the same object. [Build a room with WebSockets](https://developers.cloudflare.com/durable-objects/best-practices/websockets/).

| Decision | Local SQLite with Litebackup | Cloudflare Durable Objects |
| --- | --- | --- |
| What do I operate? | The app host, backup server and bucket. | Deploy the Worker and object code. Cloudflare runs the hosts. |
| How do I spread out writes? | Give customers separate files and route each to its writer. | Give each customer or room an object. One busy room still shares one object’s capacity. |
| What if the writer’s disk fails? | A local commit can be lost. Wait for a sync to a separate Litebackup server before confirming a write that must survive. | By default, the object sends success after other machines confirm the write. The edit survives loss of its host disk. |
| How do I undo a mistake? | [Restore a retained version](/restore-sqlite-to-any-version) into a new file and inspect it. | [Roll back the object’s database](https://developers.cloudflare.com/durable-objects/api/sqlite-storage-api/#pitr-point-in-time-recovery-api) to a point in the past 30 days. |
| What determines cost? | Your [Litebackup plan](/pricing), hosts and bucket usage. | Requests, compute duration, storage, and rows read or written. [Cloudflare pricing](https://developers.cloudflare.com/durable-objects/platform/pricing/) |

## Does each SQL query need a network call?

Two people open the same document. Alice saves first. When Ben saves, the app checks his editing permission and the version he opened so his older copy cannot overwrite Alice’s changes.

| Where the save runs | Round trips after the request reaches the app or Worker |
| --- | --- |
| Local SQLite app | **Zero** for SQL. Check both rows and save in one transaction. An explicit Litebackup sync adds a network wait. |
| Worker making separate read and write calls | **Two.** Fetch both rows from the object, then call it to save. The object must recheck both conditions because either could have changed. |
| Method inside the Durable Object | **One.** Send the whole edit to the object. Its code checks both rows and saves locally. |

For the one-call design, the Worker calls a method you define on the document’s object. It sends the signed-in user’s ID, the version they opened and their new text together.

```js
const objectId = env.DOCUMENTS.idFromName(documentId);
const document = env.DOCUMENTS.get(objectId);
const saved = await document.saveEdit(userId, openedVersion, newText);
```

SQL inside the object uses colocated storage. The reply waits for replication even though the queries themselves need no network round trip. [How Cloudflare confirms SQLite writes](https://blog.cloudflare.com/sqlite-in-durable-objects/).

## Install

[Install Litebackup](/install) to back up an existing SQLite app or [deploy a SQLite-backed Durable Object](https://developers.cloudflare.com/durable-objects/get-started/) to run code and storage together on Cloudflare.
