Sync & Local-first
barrel-lite is an offline-first Barrel in the browser. Read and write locally, sync when connected, and search vectors on device. TypeScript, zero runtime dependencies.
Offline-first
Reads and writes hit a local OPFS store first; sync is the durability story, not the hot path.
Correct sync
HLC version vectors, byte-for-byte compatible with the server, so sync converges and never silently loses a write.
Multi-tab
One tab per origin owns the store via Web Locks; other tabs proxy to it and see the same changes.
Continuous updates
Adaptive polling with an optional continuous SSE stream that wakes it on server changes.
Local vector search
Pull per-document vectors and run brute-force cosine top-k on device, with an optional BQL filter.
Attachments and BQL
Content-addressed attachment sync and a local BQL subset matching the server document queries.
Quick Start
%% Two Barrel nodes converge over HTTP. One shot, then return.
{ok, Stats} = barrel_rep:replicate(<<"notes">>,
<<"http://edge.example/db/notes">>, #{direction => push}).
%% Or keep syncing in the background. The task is persisted, so it
%% resumes from its checkpoint after a restart.
{ok, TaskId} = barrel_rep_tasks:start_task(#{
source => <<"notes">>,
target => <<"http://edge.example/db/notes">>,
mode => continuous,
direction => push
}).
ok = barrel_rep_tasks:pause_task(TaskId),
ok = barrel_rep_tasks:resume_task(TaskId),
Tasks = barrel_rep_tasks:list_tasks(). import { Database } from "barrel-lite";
// Open an offline-first database that syncs to a Barrel server
const db = await Database.open("notes", {
remote: { url: "https://edge.example", db: "notes", token: "bsp_..." },
});
// Local reads and writes; works offline
await db.put({ id: "n1", title: "Design review" });
const doc = await db.get("n1");
// Keep converging in the background, vectors included
db.liveSync({ continuous: true, vectors: true });
// Brute-force vector search over the synced records, in the browser
const hits = await db.searchLocal(queryVector, { k: 10 }); When to Use
Use barrel-lite when:
- + Your app must work offline
- + You want on-device search over synced data
- + You need a local cache that converges with a server
- + You want the same wire and codecs as Barrel
Consider alternatives when:
- + You only ever talk to a server online
- + You need an ANN index in the browser (search runs server-side)
- + You are not on the Barrel wire