---
title: "Pylon Sync Engine: live queries over WebSocket, local-first"
description: "db.useQuery is a live WebSocket subscription. Pylon pushes the exact diff on every write, supports offline work, and keeps tabs coherent without polling or cache invalidation."
url: "https://www.pylonsync.com/product/sync"
---

Sync engine

# Live queries over WebSocket.

db.useQuery is a WebSocket subscription. Pylon walks the change log on every write and pushes the exact diff to each subscribed client, keeping the UI current without polling or cache invalidation.

[Create your account →](https://cloud.stack0.dev/signup)[Read the docs](https://docs.pylonsync.com)

components/Messages.tsx

```


import { db } from "@pylonsync/react";

 

function Messages({ roomId }: { roomId: string }) {

  // A live subscription. Re-renders the instant anyone,

  // anywhere, inserts or edits a matching Message row.

  const { data: messages } = db.useQuery<Message>("Message", {

    where: { roomId },

  });

 

  return messages.map((m) => <Bubble key={m.id} message={m} />);

}

```

- Subscriptions update in milliseconds because the server pushes diffs instead of waiting for clients to poll
- Local-first: reads hit an in-browser store, writes apply optimistically and reconcile
- Queue mutations offline and sync them when the connection returns
- Multi-tab coherent via a leader election over BroadcastChannel

## How it works.

01The server computes the diff02Optimistic by default, consistent always03One engine, every client

orders · subscribed

`db.useQuery("Order")`live

ord\_9f2aSarah Chen$1,240

ord\_7c41Marcus Lee$880

ord\_5b88Priya Nair$2,100

ord\_3d10Elena Duarte$640

diff streamed to 44 clients

On every write, Pylon walks an append-only change log and finds the affected subscriptions. Clients receive a minimal insert, update, or tombstone instead of fetching the result again. A 10,000-row table therefore updates as cheaply as a 10-row one.

## What you’d otherwise wire up.

Each line is a piece teams normally assemble for this one capability. On Pylon it is part of the runtime.

- A WebSocket server, plus reconnect and backoff logic
- A client cache and the invalidation rules that keep it honest
- Optimistic update plumbing and its rollback path
- A polling loop, or an SSE fallback for browsers that drop the socket

## Apps built with it.

Scaffold any of these with `npm create @pylonsync/pylon`.

[All examples →](/developers/examples)

liveMarketplace

A trading marketplace deployed from a monorepo, with listings, watchlists, an activity feed, faceted search, and per-user ownership.

Faceted searchfield.owner()Optimistic inserts

template: marketplace[Open](https://market.pyln.dev) 

liveWorld3D

A multiplayer procedural island with three.js in the browser and Pylon SSR and realtime sync on the server. Every visitor moves through the same world.

Realtime multiplayerthree.js + SSRLive sync

[Open](https://world3d.pyln.dev) 

Consumer app

A social feed with live posts and likes, public reads, and owner-only writes.

Live feedPublic readsfield.owner()

template: consumer

Keep exploring

[Database

Typed schema. Migrations on save.](/product/database)

[Realtime

Rooms, presence, and authoritative shards.](/product/realtime)

[Server functions

Backend logic in TypeScript.](/product/functions)

## Build it on Pylon.

One framework for your schema, sync, auth, functions, realtime, and SSR. Free to start.

[Create your account →](https://cloud.stack0.dev/signup)[Read the docs](https://docs.pylonsync.com)
