ElectricSQL enables local-first applications by syncing a subset of Postgres data to local SQLite using Shapes and CRDT-based conflict resolution. Test your understanding of this paradigm.
0 / 5 completed
1 / 5
What is the local-first paradigm that ElectricSQL enables?
Local-first with ElectricSQL means the app reads from and writes to a local SQLite database (in the browser or on device), giving instant responses with no network latency. ElectricSQL's sync engine replicates changes bidirectionally between the local SQLite and a Postgres server, handling conflicts using CRDTs.
2 / 5
What are Shapes in ElectricSQL's sync model?
Shapes are ElectricSQL's sync primitives — they define a query (e.g., all rows in todos where user_id = 123) that the client subscribes to. ElectricSQL streams the matching rows to the local database and keeps them in sync, replacing the need to write custom websocket sync code or polling loops.
3 / 5
What role do CRDTs play in ElectricSQL?
CRDTs (Conflict-free Replicated Data Types) are mathematical structures that can be merged in any order without conflicts. ElectricSQL uses CRDT-based merge logic so that when two clients edit the same data offline and sync, the changes are merged deterministically — no user-facing conflict dialogs or lost writes.
4 / 5
How do you write reactive queries in ElectricSQL to automatically update the UI when data changes?
ElectricSQL provides reactive hooks like useShape() (React) that subscribe to a Shape and return live query results. When the local SQLite database updates (either from local writes or incoming sync), the hook automatically triggers a re-render with the new data — no manual polling or subscription management needed.
5 / 5
What does ElectricSQL require on the Postgres server side to enable sync?
The Electric sync service is a separate process that connects to your Postgres database using logical replication (the same mechanism as Postgres streaming replication). It reads the WAL (write-ahead log) to detect changes and streams them to connected clients, while writing client changes back to Postgres through a standard connection.