Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 8 min read How-to mediumAdept

TanStack DB with Sync – the future of real-time UI

Pairing TanStack DB with the ElectricSQL sync engine gives web apps end-to-end real-time updates and optimistic mutations, with Postgres as the source of truth. ElectricSQL uses Postgres logical replication and HTTP long-polling to push changes to clients and handles reads only, so writes still go through normal server actions or APIs. TanStack DB collections map to tables, apply optimistic inserts, updates and deletes through callbacks that roll back on failure, and support live queries with SQL-like filters and joins. A Next.js and Neon contacts demo shows the collection setup, the live queries, and a proxy endpoint that enforces auth and adds per-user row filters before forwarding requests to Electric.

Related posts

  • Neon now has realtime

    Neon mediumAdept

    Neon Realtime, now in free public beta, turns any read-only deterministic SQL query (joins, aggregates, window functions, subqueries) into a live query whose result stays updated as data changes, running inside Postgres rather than as a separate realtime service. A TypeScript SDK lets backends define queries via raw SQL, Drizzle or Kysely and "seal" them so browsers or agents can subscribe safely, with React's useLiveQuery, optimistic writes confirmed via awaitTxId, SSR and TanStack DB support. Clients connect to Neon's ingress layer so subscriptions don't block scale-to-zero, incremental maintenance runs on a replica without consuming connections, and Realtime is enabled per branch. Beta limits include no row-level security, no published benchmarks, a changing protocol and four regions.

  • Offline-first React Native Apps with Expo, WatermelonDB, and Supabase

    Supabase mediumAdept

    An offline-first React Native/Expo app can use WatermelonDB (SQLite-based, last-write-wins sync) as its local store and sync to Supabase Postgres through two RPC calls: a `push` function that applies client changesets and a `pull` function that returns all changes since the last sync timestamp. The walkthrough covers adding simdjson via expo-build-properties, defining WatermelonDB models, and writing the PL/pgSQL push/pull and epoch-conversion functions, with soft deletes tracked via deleted_at/last_modified_at. The main tradeoff is friction when changing the data model, since the Postgres schema, the local WatermelonDB schema and the sync functions must all be kept in step. That makes the approach best suited to apps with a stable schema where snappy interactions matter.

  • Sub-10ms Postgres queries for Vercel Edge Functions

    Neon mediumAdept

    Neon's serverless Postgres driver now supports SQL-over-HTTP via fetch, and Neon's proxy adds opt-in experimental connection caching (`fetchConnectionCache`). Together they cut query latency from Vercel Serverless and Edge Functions by about 40%, bringing same-region one-shot queries to single-digit milliseconds. Use the `neon` HTTP function for a single query per invocation and `Pool` when a function runs multiple queries. Drizzle-ORM also supports the driver for type-safe queries.

  • GraphQL, meet LiveGraph: a real-time data system at scale

    Figma mediumAdept

    LiveGraph is Figma's real-time data layer on Postgres: frontend code declares GraphQL-like live queries via a React useSubscription hook, and the server keeps results updated by tailing the Postgres write-ahead log distributed over Kafka instead of polling. Each view is decomposed into a tree of join-free single-table subqueries. An index of active subqueries routes replication-stream changes to the right cached results, and subqueries are shared across users to cut database load. The client is isomorphic with the NodeJS server and receives ordered, exactly-once incremental updates, with permission checks and optimistic updates built in. Performance-critical parts are written in Go, a single instance currently handles about 10,000 writes/second, and open problems include sharding, thundering-herd reconnects after deploys, and pagination of live views.

  • Neon Functions: backend logic next to your data

    Neon mediumAdept

    Neon Functions are long-running Node.js 24 compute deployed onto a Neon branch, in the same region and on the same infrastructure as its Lakebase Postgres database, with DATABASE_URL and other Neon backend credentials injected automatically. Running next to the data removes the cross-network hop per query and lets a function keep a pg Pool open across requests, so agents can stream for minutes and WebSockets or SSE can fan out via Postgres LISTEN/NOTIFY. Functions branch with the database: each child branch gets its own function copy and URL, and deleting the branch deletes it. They are declared in neon.ts, Hono is the recommended framework, and the pg Pool is recommended over the serverless driver; functions are not for frontend hosting or background jobs, and cron and event triggers are planned.

The quest for software engineering knowledge.

Look:
Layout: