Local-First App with ElectricSQL & TanStackDB #12506
Replies: 3 comments
-
Hi @GermanJablo . Please take a look #12506 . Here is the full doc TanStack DB - Documentation |
Beta Was this translation helpful? Give feedback.
-
Proposal: Local-First In-App Notification System for Payload CMSSummary 1. Why Local-First In-App Notifications?
2. Component Overview
3. Architecture3.1 Client-Side
3.2 Bi-Directional Sync
4. UI Integration
5. Benefits & Cost
|
Beta Was this translation helpful? Give feedback.
-
Thank you for diving deep into this. I’m very familiar with the local-first ecosystem and literature, and I’ve been working for a couple of years on my own CRDT. I’d love for Payload to offer a solution to this problem—I imagine it as a plugin. The two most important questions to tackle first, IMO, are:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Why “Local-First”?
Local-first (aka offline-first) apps store data on the client so they work seamlessly without a network. According to the RxDB docs,
In practice, this means:
Overall, local-first apps feel faster and more robust—operations hit the local store first (no spinners!), and updates propagate automatically when you reconnect.
ElectricSQL: PostgreSQL Sync Engine
ElectricSQL is an open-source local-first sync platform for Postgres. It sits between your Postgres database and clients:
You can query/update your data locally (in a web or mobile app), and ElectricSQL handles background reads/writes, partial replication, and conflict resolution for you. In short, it “solves the hard problems of sync.”
TanStack DB: Reactive Client-Side Store
TanStack DB is a new in-browser database from the TanStack Query team, tailored for live, offline-capable UIs:
It acts as the write-path under your UI: you define typed collections, components subscribe to reactive queries, and TanStack DB handles local edits. Later, it can sync those edits to any backend. Pairing it with ElectricSQL gives you:
Use Cases for Payload CMS Developers
Mobile-first & PWAs
Let users browse/edit content on their phone without a connection; sync automatically when online.
Field-work & Low-connectivity
Remote teams (branches, warehouses) edit catalog or inventory data offline; changes queue & merge later.
Real-time Collaboration
Multiple authors editing the same entry see each other’s updates live (à la Google Docs).
Edge & Offline Admin UIs
Integrate TanStack DB into the Payload admin panel so it works when the CMS server is unreachable.
Any scenario that demands reliability and responsiveness—spotty Wi-Fi, mobile users, multiple editors—benefits from local-first.
Proposed Features & Integrations
ElectricSQL Plugin
Add a first-class plugin or “Electric Mode” in Payload to publish selected collections to Electric’s sync layer.
Starter Kits & Guides
Official examples (e.g. Next.js +
@tanstack/db
+@electric-sql/react
) so devs don’t build plumbing from scratch.CRDT-Friendly API Hooks
Extend Payload’s REST/GraphQL endpoints to accept batched, CRDT-compatible updates.
Offline-Capable Client Cache
Recommend TanStack DB as a built-in cache for Payload queries—components query local collections and mutate offline. For example, a TanStack DB collection could mirror a Payload collection, so UI components query the local collection (no stale data) and use mutations that “just work” offline.
CLI & Scaffolding
Automate setup for local DBs (PGLite with Drizzle ORM) and sync; document lifecycle hooks for create/update.
Simplifying Development for All Skill Levels
ElectricSQL and TanStack DB abstract away websockets, background sync loops, and conflict resolution:
useShape
) that auto-sync data.Junior devs can “write to this collection” and get eventual sync for free—no manual IndexedDB or fetch loops. Fewer bugs, faster feature development.
Discussion
This is a community-driven idea, not an official roadmap announcement. We welcome feedback:
Please share your thoughts, questions, or prototypes. Let’s explore how Payload can power fast, collaborative, local-first apps!
Useful Links
Beta Was this translation helpful? Give feedback.
All reactions