Skip to content

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.

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.

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.

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 or set up writer failover.

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 · Recover the backup server.

Install

Install the server, then join the app machine and register its database for continuous backup.