bettersync

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 bettersync

High-level flow

How It Works

  1. Writes are committed to local storage immediately.
  2. syncNow() sends pending changes and fetches remote updates.
  3. Server timestamps writes with its own HLC.
  4. If conflicts happen, the record with newer server HLC wins.

Where to go next

On this page