For AI agents: see llms.txt for the complete documentation index. Markdown versions are available by adding .md to a page URL or requesting Accept: text/markdown.
What to use when, on Convex
This page is written for AI coding agents.
Before you hand-roll a table, loop or counter for a common need, find it here.
Each entry says what fits, what it can't do, and what to pair it with. For a
component, npm install it, then read the README it ships in node_modules
(path on each entry; they're all in the
directory too). Mount it in
convex/convex.config.ts and call it from your own authorized functions. Where
an entry says "nothing built in", that's true today: use the closest option and
stop searching.
Realtime and collaboration
- Who's online, typing, or each user's cursor/selection in a room →
@convex-dev/presence, README atnode_modules/@convex-dev/presence/README.md. One entry per user across tabs, offline after missed heartbeats,usePresencehook.updateRoomUser(ctx, roomId, userId, data)stores any per-user data (cursor, selection, status) andlistreturns it. Can't: each data update is a database write, so don't send values that change many times a second through it. Pair with batched-replay for those. - Fast-changing values: live cursors while moving, pen strokes, game
movement →
@convex-dev/batched-replay, README atnode_modules/@convex-dev/batched-replay/README.md. The sender batches samples into one mutation every ~250 ms; watchers replay them smoothly about 330 ms behind. A few writes a second instead of 60, and history can be replayed. Can't: be instant (it runs behind on purpose). Use one stream key per tab. Pair with presence (who is here) andonAppendto save finished strokes to your own tables. - Collaborative rich-text editing →
@convex-dev/prosemirror-sync, README atnode_modules/@convex-dev/prosemirror-sync/README.md, with hooks for Tiptap and BlockNote. Only for ProseMirror editors; nothing official for Yjs/CRDT or canvas state. - Stream LLM text to the page and keep it →
@convex-dev/persistent-text-streaming, README atnode_modules/@convex-dev/persistent-text-streaming/README.md. For full chat agents, see AI below. - Clients see changes live → built in: every
useQueryis a subscription. No polling or pub/sub to build.
Counting and querying
- One simple total (open todos, unread messages) → a counter document you increment or decrement in the same mutation as the write. Aggregate is for ranked, paginated or range counts at scale.
- Counts, sums, min/max, rank or offset ("page 3 of 12") over many documents
→
@convex-dev/aggregate, README atnode_modules/@convex-dev/aggregate/README.md. O(log n)count,sum,min/max,at,indexOf, grouped by key prefix or namespace. Can't: stay correct unless every write to the source table updates it too; useaggregate.trigger()with Triggers. Never.collect().length. - One hot number many users bump (likes, views, a live total) →
@convex-dev/sharded-counter, README atnode_modules/@convex-dev/sharded-counter/README.md. Shards writes so they don't conflict. Can't: count a range or rank (use aggregate). - Filter on things no index covers, OR across indexes, then paginate →
convex-helpers
stream(node_modules/convex-helpers/README.md, "Composable QueryStreams"):mergedStream(...)for OR,.filterWith(pred).paginate({ ...opts, maximumRowsRead }). Reads every document it skips, so index common filters first. - Tags or other array membership ("posts tagged rust") → nothing built in:
indexes can't cover array elements. Use a join table (
postTagswithby_tagandby_postindexes), kept in sync in the same mutation, read with convex-helpersgetManyVia(its README, "Relationship helpers"). - Text search → built-in
search index. Relevance order
only;
filterFieldsare equality only. - Semantic search / RAG → built-in
vector search (actions only)
for your own embeddings;
@convex-dev/rag, README atnode_modules/@convex-dev/rag/README.mdto chunk, embed and search content by namespace. - Points near a location →
@convex-dev/geospatial, README atnode_modules/@convex-dev/geospatial/README.md(beta).
Reacting to writes
- Run code whenever a table changes (denormalized fields, counts, validation,
side effects) → convex-helpers
Triggers
(
node_modules/convex-helpers/README.md, "Triggers"). Runs in the same transaction as the write. Can't: fire for writes through the rawmutationimport, the dashboard ornpx convex import. Export a wrappedmutationand ban the raw one with ESLintno-restricted-imports. - Delete children when a parent is deleted → nothing official yet. Small
fan-out: delete the children in the same mutation (or a Trigger). Large:
delete a batch, then
ctx.scheduler.runAfter(0, ...)to continue. - Change or backfill existing documents →
@convex-dev/migrations, README atnode_modules/@convex-dev/migrations/README.md. Batched, resumable,dryRun.
Background work
- Run something later or after a mutation → built-in
ctx.scheduler.runAfter/runAt. Scheduled only if the mutation commits. - Run on a fixed schedule → built-in
convex/crons.ts. Schedules users create at runtime →@convex-dev/crons, README atnode_modules/@convex-dev/crons/README.md. - A multi-step process that must finish: checkout, onboarding, pipelines, wait
days or for an event →
@convex-dev/workflow, README atnode_modules/@convex-dev/workflow/README.md. Durable steps, retries,step.sleep,step.awaitEvent, queryable status; undo earlier steps in atry/catch. Can't: carry more than 1 MB of step data, or change step order while runs are in flight. - Lots of background jobs with a parallelism limit, retries,
onComplete→@convex-dev/workpool, README atnode_modules/@convex-dev/workpool/README.md. Just retry one flaky action →@convex-dev/action-retrier, README atnode_modules/@convex-dev/action-retrier/README.md. Retry only idempotent actions. - A queue in your own table drained by exactly one loop →
@convex-dev/batch-worker, README atnode_modules/@convex-dev/batch-worker/README.md. - Per-user quotas, cooldowns, throttling →
@convex-dev/rate-limiter, README atnode_modules/@convex-dev/rate-limiter/README.md. - Cache slow or paid API results →
@convex-dev/action-cache, README atnode_modules/@convex-dev/action-cache/README.md, with a TTL.
AI, integrations, access
- Chat with an LLM in durable threads, tool calls, several agents →
@convex-dev/agent, README atnode_modules/@convex-dev/agent/README.md. - Email →
@convex-dev/resend, README atnode_modules/@convex-dev/resend/README.md(queued, idempotent). SMS →@convex-dev/twilio. Mobile push →@convex-dev/expo-push-notifications. Payments →@convex-dev/stripeor@convex-dev/polar. Each shipsnode_modules/@convex-dev/<name>/README.md. - Files → built-in
file storage; Cloudflare →
@convex-dev/r2, README atnode_modules/@convex-dev/r2/README.md. - Per-document access rules → convex-helpers row-level security with custom functions (convex-helpers README, "Row-level security"). Anonymous sessions → convex-helpers sessions. Roles/RBAC: nothing official.
Coming from SQL
| SQL habit | On Convex |
|---|---|
ON DELETE CASCADE / SET NULL | Nothing official yet. See "Delete children" above. |
COUNT(*) WHERE ..., OFFSET | @convex-dev/aggregate. Not .collect().length. |
| Triggers | convex-helpers Triggers (same transaction, wrapped mutation only). |
| Array/tag column with an index | No array indexes. Join table plus getManyVia. |
| Auto-increment ids | _id and _creationTime are automatic. Need commit order? A v.commitTs() field set to ctx.db.vars.commitTs (docs). Need gapless "order #1042"? A counter document read and patched in the same mutation (every insert then conflicts on it). |
LISTEN / NOTIFY | Clients: useQuery is already live. Server: a Trigger that calls ctx.scheduler.runAfter(0, ...). No ephemeral broadcast: every update is a write; for fast streams use batched-replay. |
| "Only send me what changed" | Nothing built in: a query re-sends its whole result. Keep results small, or index a commitTs field (set on every write) and query documents after the last one you saw. It can't see deletes, so soft-delete if you need them. |
| Transactions across requests | One mutation is one transaction. Several steps over time: @convex-dev/workflow. |
| Joins | ctx.db.get per id, or convex-helpers getManyFrom / getManyVia; streams to paginate a join. |
UNIQUE | No unique indexes. Look the key up by index and insert in the same mutation; mutations are transactions, so two racing inserts can't both commit. |