Show HN: ElectricSQL, Postgres to SQLite active-active sync for local-first apps (opens in a new tab)electric-sql.com
617 pointsWe're really excited to be sharing ElectricSQL with you today. It's an open source, local-first sync layer that can be used to build reactive, realtime, offline-capable apps directly on Postgres with two way active-active sync to SQLite (including with WASM in the browser).
Electric comprises a sync layer (built with Elixir) placed in front of your Postgres database and a type safe client that allows you to bidirectionally sync data from your Postgres to local SQLite databases. This sync is CRDT-based, resilient to conflicting edits from multiple nodes at the same time, and works after being offline for extended periods.
Some good links to get started:
- website: https://electric-sql.com
- docs: https://electric-sql.com/docs
- code: https://github.com/electric-sql/electric
- introducing post: https://electric-sql.com/blog/2023/09/20/introducing-electri...
You can also see some demo applications:
- Linear clone: https://linear-lite.electric-sql.com
- Realtime demo: https://electric-sql.com/docs/intro/multi-user
- Conflict-free offline: https://electric-sql.com/docs/intro/offline
The Electric team actually includes two of the inventors of CRDTs, Marc Shapiro and Nuno Preguiça, and a number of their collaborators who've pioneered a lot of tech underpinning local-first software. We are privileged to be building on their research and delighted to be surfacing so much work in a product you can now try out.

Comments (170) 71 threads
Earlier commentsLooking forward to seeing more people trying out this architecture.
Still hoping we can find some time to collaborate on reactivity, tree-sql, typed-sql or some such other effort in the near future.
I've made quite a bit of progress on incremental view maintenance for SQLite which I'd like to share in the near future if that's a problem you're also dealing with.
Electric is designed to support partial sync, and so you don’t have to sync your whole dataset. (Note that this is feature is under development and not yet public)
There are limitations on how much data a browser will store for an individual site, so the number of rows you can sync will depend on the shape of your dataset. Finally there are also some performance considerations with WASM SQLite, this is something the SQLite team are working on in collaboration with the browser developers, particularly with the development of the new OPFS apis which we plan to support as they mature.
So, thousands of rows are definitely viable, and we have that working with our own internal development tests. Hundreds of thousands or millions may cause issues right now, but are something we do want to support.
https://www.sqlite.org/cves.html
> Almost all CVEs written against SQLite require the ability to inject and run arbitrary SQL.
> The advertised consequence of most CVEs is "denial of service", typically by causing a crash through a NULL pointer dereference or a division by zero, or similar.
> But if an attacker can already run arbitrary SQL, they do not need a bug to cause a denial of service. There are plenty of perfectly legal and valid SQL statements that will consume unlimited CPU, memory, and disk I/O in order to create a denial-of-service without requiring help from bugs.
> Hence, the mere fact that an attacker has a way to inject and run arbitrary SQL is in and of itself a denial-of-service attack. That the arbitrary SQL might also tickle a bug in SQLite and cause a crash is not a new vulnerability.
Continue this thread — 1 reply
[1] https://docs.powersync.co/
I have yet to dive deeper in the docs and examples, but does anyone know how easy it would be with Electric to provide some kind of client-side transformations (encryption/decryption) of specific fields or entire rows in your SQLite db before syncing? A major reason to go local-first, is often privacy, and the idea that the user owns their data...
Also, it's unfortunate permissions haven't been implemented yet; https://electric-sql.com/docs/usage/data-modelling/permissio... If I understand correctly, that means in a multi-user system, everyone will sync everyone else's data?
And too bad my favorite stack (Angular + Nest.js backend) isn't supported, but I guess it should still be straightforward to integrate the client-side and run the sync service in the backend. I might try it if I have a weekend...
Handling encryption/decryption of user data is one of our priorities. We're thinking along the lines of adding hooks for transforming data as you're seeing it.
We're getting there on permissions implementations. If you want to do row-based filtering based on user_id today, you can add a special column 'electric_user_id' to your table: https://electric-sql.com/docs/reference/roadmap#shapes
We plan to integrate Electric with popular web frameworks: https://electric-sql.com/docs/integrations/frontend. To integrate with Angular, the client should work out of the box. What you'd need is to provide is the code for reactivity, which should not be a lot. Reach out on Discord and we can have a chat about it.
E2E encryption would also be nice to have, it could be worth having a look at https://www.etesync.com/ for inspiration
[1] https://electric-sql.com/docs/api/ddlx
We assessed nearly every new data solution available and ultimately chose Electric. We recognized that the combination of SQLite's convenience on the client-side and PostgreSQL's flexibility on the server-side is a potent foundation for our work.
I've spent years grappling with the challenges of the local-first (lo-fi) approach, particularly when using the PouchDB <-> CouchDB combination to support vital offline features in our Point of Sale tools. While not every feature aligns with the lo-fi concept (even though real-time synchronization status on the client can significantly reduce the need for numerous API end points), having PostgreSQL on the backend grants us access to a wealth of existing tools and support built around PostgreSQL. This assurance provides us with peace of mind, knowing that we won't encounter insurmountable obstacles, and any challenges we face will be no more daunting than those encountered in traditional server-based API programming paradigms.
I sincerely hope that ElectricSQL achieves the recognition it deserves and can implement many of the ideas outlined in their roadmap documentation. These ideas have the potential to overcome the initial hurdles that have hindered the widespread adoption of the lo-fi approach.
In the meantime, we're having a great time developing an opinionated, React-based low-code tool (internally, we refer to it as "Visual Basic using React"). We're looking forward to leveraging some of the outstanding work done by James' team thus far!
All comments shown.
Couldn't load more comments. Check your connection and try again.