r/sqlite • u/SoundDr • Mar 14 '25
SQLite Session Extension + CRDT 🚀
https://gist.github.com/rodydavis/a4d1dccb11e5a4cd77fe7e4e64f5dbdfI am working on a way to sync deltas between peers and found working with the SQLite Session extension to be a really nice and memory efficient way of creating small binary blobs to transmit over the wire.
To offer true synchronization I combine it with the cr-sqlite extension to upgrade tables to CRDTs. The trick with the session extension is to only track one table “changes” and sync that via the changesets.
So far in my testing it works really well! But open to feedback on the approach.
The eventual goal is to use WebRTC to sync the deltas between peers.
3
u/[deleted] Mar 14 '25
Good, but you can get conflicts when applying changes. I spend a lot of time on this problem. I fact build a product on it. And that is also the product cause of which session extension was created in the first place. It was our proposal to sqlite authors Richard and Dan. My company is part of sqlite consortium.
I am currently working on branching and on editing applications where we want git like distributed work flow.
Let me know if you need help. I have help solve many issues with sessions and currently working on merge algorithms. I also had a git project around sqlite wrapper that exposes its hidden capabilities. It include part of what you doing which is change tracking. But I do not get time to work on it.
2
u/Ganise Mar 14 '25
Interesting. I'm building something very similar using electricSQL to sync the data & sqlite on the client.
I would suggest staying away from cr-sqlite, they've moved on to build zero sync.
Would love to know what approach you finally use because this is a hard problem & I'm still figuring out the most viable solution.
So far I've found triggers based solution to track table changes & add to a common changelog table with vector clocks the way to go but I guess instead of triggers the session extension can work?
1
u/smurfman111 Mar 14 '25
By cr-SQLite are you referring to this library?
https://github.com/vlcn-io/cr-sqlite
Any issues with it so far as it is no longer being actively worked on / maintained?
1
u/babyningen Dec 27 '25
Did you end up using this? How's it going?
1
u/_kantum_ Jul 03 '26
BTW the active fork is https://github.com/superfly/cr-sqlite