Introduction
Local-first sync for Postgres and TypeScript apps
bettersync
bettersync is a local-first sync engine for TypeScript applications that need offline UX and fast collaborative updates without adopting a brand-new backend stack.
It keeps your app responsive by writing locally first, then syncing changes to Postgres with deterministic conflict resolution. You keep your existing server architecture and database tools.
Why teams pick bettersync
- Drop-in architecture: works with existing Next.js, Express, NestJS, Hono, Elysia, and Bun APIs.
- No extra control plane: no dedicated sync service to manage.
- TypeScript-first API: strongly typed schema and model helpers.
- Deterministic conflict handling: Hybrid Logical Clock (HLC) + Last-Write-Wins.
- Offline-first UX: local writes + background sync.
Quick install
pnpm add bettersyncHigh-level flow
How It Works
- Writes are committed to local storage immediately.
syncNow()sends pending changes and fetches remote updates.- Server timestamps writes with its own HLC.
- If conflicts happen, the record with newer server HLC wins.
Where to go next
/docs/getting-started: full setup in six steps./docs/concepts: HLC, scope, tombstones, and merge semantics./docs/adapters: Drizzle/Postgres, PGlite, memory adapter APIs./docs/react:SyncProvider,useSyncQuery, and live updates.