Back to Building apps with Sync: TanStack DB & ElectricSQL

Mental model: Read‑path sync + reactive client state

Authors: Kyle Mathews
License: CC0 1.0

Topic Outcomes

You’ll be able to explain why ElectricSQL focuses on read‑path sync (replicating subsets of Postgres outward) while leaving the write path to your app/API, and how TanStack DB gives you a fast, reactive client store with live queries and optimistic mutations on top.

Topic Summary

Electric syncs Shapes—small, declarative slices of your Postgres—over plain HTTP; clients consume a Shape Log with offsets/handles and switch to long‑polling “live mode” for updates. TanStack DB sits client‑side and treats synced data as immutable base state with a separate optimistic layer, exposing live queries that update incrementally (implemented via a TypeScript differential‑dataflow engine, d2ts). Functionally: Electric = high‑scale, CDN‑friendly replication from Postgres; TanStack DB = instantaneous reads + optimistic UX in the client, with explicit integration between the two.

Topic Sources

  • ElectricSQL: https://electric-sql.com/docs/intro & https://electric-sql.com/docs/api/http

  • TanStack DB: https://tanstack.com/db/latest/docs/overview & https://tanstack.com/db/latest/docs/guides/live-queries

Topic Authors

Kyle Mathews