Skip to content

Start

Why Sync?

Sync keeps clients in step with shared state on your server. Connect a client to a source and it receives the current state, follows live changes, and catches up after a disconnect.

Your app decides what data to share, who can access it, and how it changes. Sync handles initial loading, update delivery, reconnection, and recovery.

Server data stays in sync across clients. A Sync source shares server data with connected clients. Clients receive live updates, and a reconnecting client catches up on the changes it missed.
  • Yielded Sync: Sync sourceData on your server
  • Yielded Sync: Client AGets live updates
  • Yielded Sync: Client BGets live updates
  • Yielded Sync: Client CReconnects and catches up
  • Sync source to Client A
  • Sync source to Client B
  • Sync source to Client C

Once the client is connected, your components can render its local copy, called a replica. Actions handled by Sync update the server state and send events to connected clients. The replica updates as those events arrive:

App.tsx
import { RegistryProvider, useAtomValue } from "@effect/atom-react";
import { counter } from "./counter-atoms";
function CounterValue() {
const replica = useAtomValue(counter.replica);
if (replica._tag === "Failure") {
return <p role="alert">Could not load the counter.</p>;
}
if (replica._tag !== "Success") {
return <output>Connecting…</output>;
}
return <output>{replica.value.value?.value ?? "Connecting…"}</output>;
}
export function App() {
return (
<RegistryProvider>
<CounterValue />
</RegistryProvider>
);
}

Sync tracks which version each client has seen. After reconnecting, it replays missed updates or loads a fresh snapshot if that history is no longer available. Your components keep reading the same replica throughout.

Clients can also send typed actions to the server. An optimistic reducer shows an edit immediately, before the server replies. Sync confirms the edit if it’s accepted or rolls it back if it’s rejected.

If a reply is lost, automatic retries use the original command identity so the server doesn’t apply the same edit twice. With IndexedDB persistence, pending edits survive reloads. Unresolved edits stay available through the recovery controls for your app to resolve.

Effect Schema defines your shared state, actions, results, and errors. Server handlers are Effects, and client bindings work with Effect Atom and React. Use the Cloudflare and IndexedDB adapters or supply your own storage and transport.

Get started with a synced counter, or explore the complete board example.