Skip to main content
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 at node_modules/@convex-dev/presence/README.md. One entry per user across tabs, offline after missed heartbeats, usePresence hook. updateRoomUser(ctx, roomId, userId, data) stores any per-user data (cursor, selection, status) and list returns 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 at node_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) and onAppend to save finished strokes to your own tables.
  • Collaborative rich-text editing → @convex-dev/prosemirror-sync, README at node_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 at node_modules/@convex-dev/persistent-text-streaming/README.md. For full chat agents, see AI below.
  • Clients see changes live → built in: every useQuery is 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 at node_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; use aggregate.trigger() with Triggers. Never .collect().length.
  • One hot number many users bump (likes, views, a live total) → @convex-dev/sharded-counter, README at node_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 (postTags with by_tag and by_post indexes), kept in sync in the same mutation, read with convex-helpers getManyVia (its README, "Relationship helpers").
  • Text search → built-in search index. Relevance order only; filterFields are equality only.
  • Semantic search / RAG → built-in vector search (actions only) for your own embeddings; @convex-dev/rag, README at node_modules/@convex-dev/rag/README.md to chunk, embed and search content by namespace.
  • Points near a location → @convex-dev/geospatial, README at node_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 raw mutation import, the dashboard or npx convex import. Export a wrapped mutation and ban the raw one with ESLint no-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 at node_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 at node_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 at node_modules/@convex-dev/workflow/README.md. Durable steps, retries, step.sleep, step.awaitEvent, queryable status; undo earlier steps in a try/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 at node_modules/@convex-dev/workpool/README.md. Just retry one flaky action → @convex-dev/action-retrier, README at node_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 at node_modules/@convex-dev/batch-worker/README.md.
  • Per-user quotas, cooldowns, throttling → @convex-dev/rate-limiter, README at node_modules/@convex-dev/rate-limiter/README.md.
  • Cache slow or paid API results → @convex-dev/action-cache, README at node_modules/@convex-dev/action-cache/README.md, with a TTL.

AI, integrations, access​

Coming from SQL​

SQL habitOn Convex
ON DELETE CASCADE / SET NULLNothing official yet. See "Delete children" above.
COUNT(*) WHERE ..., OFFSET@convex-dev/aggregate. Not .collect().length.
Triggersconvex-helpers Triggers (same transaction, wrapped mutation only).
Array/tag column with an indexNo 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 / NOTIFYClients: 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 requestsOne mutation is one transaction. Several steps over time: @convex-dev/workflow.
Joinsctx.db.get per id, or convex-helpers getManyFrom / getManyVia; streams to paginate a join.
UNIQUENo 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.