How Track syncs: a Durable Object per workspace, an oplog and a copy in the browser
Yiğit Tanrıverdi ·
Gateweave Track is an open-source issue tracker. We wanted three things from it. A workspace should open instantly. An edit should show before the server has answered. And it should keep working on a train. We also wanted it to run on nothing but Cloudflare’s developer platform, so that self-hosting is one deploy and no servers to look after.
Those goals pull against each other. Instant reads mean the data is already on the device. Instant writes mean the device has to guess the result. Working offline means those guesses can pile up for hours before anyone checks them. And “one deploy, no servers” rules out the usual answer, a long-running sync process next to a Postgres database.
This post goes through how Track fits those together, one layer at a time. All of it is in the repository under AGPL-3.0, so you can read the code behind every claim here.
The shape
Track ships as one Worker. It serves the app, handles sign-in with Better Auth, and keeps identity in D1: users, sessions, workspaces, and who belongs to which. Everything inside a workspace lives in a Durable Object of its own, with its own SQLite database. That covers teams, issues, labels, comments and history.
A Durable Object is a small stateful server that Cloudflare runs in one place at a time, with its storage on the same machine. Giving each workspace its own means each workspace gets exactly one writer, with strict ordering, and we run nothing ourselves. A workspace nobody has opened in a week uses no compute at all. The Worker is the gateway. It checks the session and the membership in D1, and only then forwards the request to the workspace’s object, which has no public route of its own.
The server: an oplog with gapless versions
Every write in a workspace appends to an oplog, and every op gets the next workspace version:
1, 2, 3, with no gaps. An op is either a whole row (put) or a delete.
Versions are gapless and totally ordered, so a client’s entire sync state is one number: the highest version it has applied. Catching up means “send me everything after 4,812”. There are no vector clocks, no per-row timestamps to compare and no Merkle trees.
Connecting takes three steps:
- A client with nothing stored fetches a snapshot over plain HTTP. That way it can be compressed, and it downloads while the socket opens.
- The client opens a WebSocket and says
hello { since: <version> }. - The object streams every op after
since, then sendsready. After that, new ops arrive as they happen.
A client can come back after a month, by which point the oplog may no longer reach back to its
version. Every six hours an alarm compacts the oplog. An op is dropped only when it is more than
30 days old and more than 10,000 versions behind. A client older than the oldest remaining op
gets reset. It then fetches a fresh snapshot and keeps the edits it has not sent yet.
Idle connections are cheap as well. Every 30 seconds a client sends a plain ping, and Cloudflare
answers pong without waking the object. An object with only idle sockets can sleep.
Mutations, not patches
Clients don’t send rows. They send named mutations with arguments:
{
"type": "mutate",
"id": "6f1c2b1e-…",
"mutation": {
"name": "issue.update",
"args": { "id": "…", "baseVersion": 4810, "patch": { "status": "done" } }
}
}
The object handles each mutation in five steps:
- It validates the mutation with the same zod schema the client used.
- It checks permissions against its copy of the workspace’s members.
- It applies the mutation in a SQLite transaction. Handlers are synchronous, so nothing else can run in the middle of a write.
- It sends the resulting ops to every connected socket, the sender’s included.
- Only then does it send the sender
ack { id, version }.
So a client learns the result of its own edit exactly the way it learns about everyone else’s.
Every mutation id is recorded. A client that lost its connection can therefore resend everything it isn’t sure about. A repeated mutation returns its original version and writes nothing.
Why a server that decides, rather than CRDTs that merge anywhere? Because an issue tracker is full of rules that need one referee:
- Issue keys like TRK-42 count up per team.
- Only admins manage teams.
- A removed member’s edits have to stop.
- A deleted issue must not come back because an offline laptop edited it.
With one ordered writer per workspace, each of these is an ordinary if statement. A Durable
Object gives us that writer.
Concurrent edits, field by field
A server that decides doesn’t have to overwrite whole rows with the last write. An issue.update
carries the baseVersion of the issue as the client last saw it. The object remembers, for each
field, which version last wrote it and from which client. Simplified from
packages/sync-server/src/mutations.ts:
for (const [field, value] of Object.entries(args.patch)) {
const stamp = issue.fieldStamps[field];
if (stamp && stamp.version > args.baseVersion && stamp.clientId !== actor.clientId) {
conflicted = true; // someone else changed this field since the client looked
continue;
}
accepted[field] = value;
stamps[field] = { version, clientId: actor.clientId };
}
That has three effects:
- Two people can change the status and the assignee of the same issue, and both edits land.
- A laptop can come back online with a stale edit to a title that someone has changed since. That field is turned down and the rest of the edit goes through, so newer work is never silently overwritten.
- A tab never conflicts with its own edits. Several quick edits may all carry the same base version because the acks have not arrived yet, and all of them land.
Some changes are not patches at all. Labels are a set. issue.addLabel and issue.removeLabel
write nothing when there is nothing to change, so two people labelling the same issue at once both
get their label.
The client: confirmed state plus pending mutations
In the browser, packages/sync-client holds two things. One is the confirmed state, exactly as
the server last reported it. The other is the list of pending mutations: edits this browser has
sent that the server has not acknowledged yet. The UI never renders either one directly. It renders
the pending mutations replayed in order on top of the confirmed state:
#rebuild(): void {
let tables = this.#confirmed;
if (this.#pending.length > 0) {
const draft = new Draft(tables);
for (const pending of this.#pending) applyOptimistic(draft, pending, this.userId);
tables = draft.finish();
}
this.#state = toState(tables, this.#version);
for (const listener of [...this.#listeners]) listener();
}
Every delta updates the confirmed state, and every ack or reject removes a pending mutation. Either way, the view is rebuilt. Three things follow from that design:
- The server always wins. Its rows replace the client’s guesses as soon as they arrive.
- A rejected edit just stops being replayed, so there is no undo code anywhere.
- Guesses only have to be close. A new issue takes the next number locally. If someone else took that number first, the server’s row replaces the guess without fuss.
Tables are copy-on-write, and rows that did not change keep their identity. Components subscribe
through useSyncExternalStore, so a component re-renders only when the slice it reads changes.
Reads are synchronous and come from memory. The UI never waits on the network to show something it
already knows.
Storage, tabs and starting offline
The replica is stored in IndexedDB, with one database per user and workspace. A reload renders straight from it, then asks the server for what it missed, so the workspace is not downloaded again. Pending mutations are written with strict durability, because until the server has them they exist nowhere else.
Several open tabs would mean several sockets and several writers to the same database. Instead,
the tabs elect a leader with the Web Locks API, and only the leader connects. It writes whatever
arrives to IndexedDB. Once the write has committed, it announces the change to the other tabs on a
BroadcastChannel. A follower that misses an announcement, or sees a gap in versions, reloads from
storage. It is guaranteed to find at least what it was told about. When the leader tab closes, the
lock passes to another tab. That tab reconnects and resends anything not yet acknowledged, which
the mutation ids make safe.
A service worker caches the app’s files and an empty app shell, so Track starts with no connection at all. If the server can’t be reached, as opposed to refusing access, the app falls back to what the browser remembers. For each workspace you opened while signed in, that is its name and your role in it. Signing out forgets all of this, the replicas included.
AI agents take the same path
Track has an MCP server. After you approve an agent such as Claude with OAuth, it can search,
create and update issues. Agents don’t keep a replica. They read slices of the workspace over RPC.
Their writes, though, go through the same mutate path as a browser’s:
- the same validation and permissions,
- the same field-level conflict check,
- the same broadcast to every open tab.
When an agent closes an issue, you see it happen on screen.
How we test it
Sync bugs hide in timing, so the tests use the real pieces wherever they can:
- The server’s tests run inside workerd, Cloudflare’s runtime. They use a real Durable Object and real SQLite, over real WebSockets.
- The client’s tests connect to that same object, running in Wrangler’s local runtime. They go through the client’s real network code.
- Playwright drives Chromium against the production build. It covers what only a browser can show: realtime across tabs and people, going offline, and starting without a connection.
Two numbers are budgets: CI fails when either gets worse. Both are measured on a GitHub Actions runner:
| What | Median in a recent run | Budget |
|---|---|---|
| Reloading a 2,000-issue workspace until the list is painted | 536 ms | 1.5 s |
| An edit in one browser showing up in another | 14 ms | 100 ms |
The server runs locally on the runner, so these numbers measure the engine and the app, not your network. In production, add the round trip to wherever your workspace’s Durable Object lives. The person making the edit sees it straight away either way.
What it doesn’t do yet
- One workspace, one object. A workspace can take as many writes as one Durable Object can handle. That is plenty for a team’s issue tracker, but it is not built for a firehose.
- The browser holds the whole workspace. That is what makes Track fast and usable offline, and it works well for thousands of issues. Much larger workspaces will need partial sync.
- Conflicts are per field, not per character. If two people edit the same description at once, one keeps their edit and the other is told it conflicted. Editing text together would need a CRDT for that one field.
- No queries across workspaces. This is deliberate: each workspace’s data lives in its own database.
- Missing features. Full-text search, notifications and projects are next on the roadmap.
Try it
- Open the demo. You get a private workspace with sample data, and it is deleted after a day.
- Deploy your own with the Deploy to Cloudflare button in the README. Use the Workers Paid plan, because a password sign-in takes more CPU than the Free plan gives a request.
- Read the code on GitHub. docs/architecture.md goes deeper than this post.
Track is the first product of Gateweave, a family of open-source tools for teams that run on Cloudflare. We’d love to hear what you think: issues and pull requests are welcome.