# Which SQLite writes survive a crash or disk failure?

A local commit survives an app crash, but an order must reach another machine to survive the loss of the app’s disk.

## Wait for a second copy before sending an order receipt

This checkout sends a receipt only after both the app and the backup server have stored the order.

```ts
import { DatabaseSync } from "node:sqlite";
import { Litebackup } from "@litebackup/sdk";

// Run on the writer beside its registered orders.sqlite file.
const db = new DatabaseSync("orders.sqlite");
const litebackup = new Litebackup();

db.exec("PRAGMA journal_mode = WAL");
db.exec("PRAGMA synchronous = FULL");
// Use a new order ID in the existing orders table.
db.prepare("INSERT INTO orders (id) VALUES (?)").run(1042);
// The order is committed locally.

await litebackup.databases.sync("orders.sqlite", { durability: "server" });
// The separate Litebackup server has the order. Send the receipt.
```

- [Set up continuous backup](https://litebackup.com/back-up-sqlite-while-your-app-writes)

## Where to recover a SQLite write after a failure

| What fails | Earliest safe reply | Where to recover |
| --- | --- | --- |
| App process crashes | Local commit | Reopen the writer’s database with its journal files intact. |
| Writer’s disk is lost | Server sync | Restore a retained version from the separate Litebackup server. |
| Only the backup server is lost | Local commit | The writer still has the order. The bucket also holds archived versions. |
| Both disks are lost | Bucket archive | Recover an archived version using bucket access and your recovery kit or passphrase. |

## When can the app tell the customer the order is saved?

### Reply after SQLite commits locally

Ordinary SQLite commits have no network wait. For power loss, the disk must survive and honor sync requests. Keep the database and its journal on persistent storage.

- **WAL with FULL.** SQLite syncs the WAL at each commit. Set `synchronous=FULL` on the writing connection.
- **WAL with NORMAL.** Recent commits can roll back after a power or OS failure.
- **DELETE journal.** SQLite recommends `synchronous=EXTRA` for power-loss durability. [SQLite sync settings](https://sqlite.org/pragma.html#pragma_synchronous).

### Wait for a copy on the backup server

Call `databases.sync(name, { durability: "server" })` after commit on the writer, as above. A timeout leaves server durability unknown. Retry the wait. Reuse the same order ID if the write itself is retried. After lease expiry, a standby takes over from the latest version the server received. [Restore a retained version](/restore-sqlite-to-any-version) or [set up writer failover](/fail-over-sqlite-between-servers).

### Wait for a copy in the bucket

Save the `syncedServer.version` returned by the sync. Wait until `databases.get(name)` reports `syncedCloud.version` at least that high.

The archive delay defaults to 15 minutes, and uploads can take longer. For a separate, unregistered export, a foreground backup with `durability` set to `cloud` waits for archival. [SDK durability options](/sdk-reference) · [Recover the backup server](/run-your-litebackup-server-and-bucket).

## Install

[Install the server](/install), then [join the app machine and register its database for continuous backup](/back-up-sqlite-while-your-app-writes).
