Convex: a database that pushes query results
A reactive database: queries are functions, their results update live, and transactions behave as if they ran one at a time.
The idea
Most apps keep screens current by polling, or by invalidating caches by hand. Convex builds that into the database. A query is a function that runs inside a transaction, and the database records exactly which index ranges it read. Each committed write is checked against the read ranges of the live subscriptions, and only queries whose inputs changed are run again and pushed to their clients.
The same record of what was read gives them serializable transactions through optimistic concurrency control. A mutation runs against a snapshot; at commit the database checks whether anything it read has changed since, and if so the mutation runs again. Developers can write code as if transactions ran one at a time.
Read it alongside the live queries investigation, which asks you to design the subscription layer yourself: what to track, how precisely, and what happens when a popular query is invalidated constantly.
Read the originals
Written by the engineers who built it.
- How Convex Works
Sujay Jayakar · Post, Apr 2024
A walk through a reactive database from the inside: the transaction log, read sets, optimistic concurrency, and how a write finds the subscriptions it affects.
Practise it
Make the decisions yourself, then compare.