#React useQuery stop receive new data for some users

5 messages · Page 1 of 1 (latest)

serene night
#

I nave react native app which uses convex. When there became about 72k users it stopped receive new messages for some users. But sometimes not always. Any thoughts about this?

glass crestBOT
#

Hi @serene night. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

This sounds like you’re hitting Convex’s per-function read limits or scalability constraints in how your queries are written, which can cause some subscriptions to stop updating once the data set gets large.

From the docs:

  • Each query and mutation has limits on how much data it can read (and write) in a single execution, to guarantee performance. [Query limits; Mutation limits]
  • If a query scans too many documents (for example, via a full table scan or a broad filter), you can hit read/write limit errors, and Convex will stop that function. [Read/write errors]
  • Filters like .filter((q) => ...) can cause full table scans; with tens of thousands of documents this can easily run into limits. You should switch to indexed queries with .withIndex(...). [Filtering performance; Queries that scale]

For real‑time chat / messages specifically:

#
  • If you have a query like “get all messages for a chat” that returns a large list, every change (new message, edit, delete) will cause Convex to recompute and resend the entire result set to each subscribed client. [GPT streaming list; Discord thread]
  • With “THOUSANDS of messages” this becomes inefficient; the recommended pattern is:

Example from the Discord thread (adapted):

// schema
chatMessages: defineTable({
  chatId: v.id("chats"),
  userId: v.id("users"),
  content: v.string(),
}).index("by_chat_id", ["chatId"]);

// query
import { query, paginationOptsValidator } from "convex/server";
import { v } from "convex/values";

export const getPaginatedMessages = query({
  args: {
    chatId: v.id("chats"),
    paginationOpts: paginationOptsValidator,
  },
  handler: async (ctx, { chatId, paginationOpts }) => {
    const messagesQuery = ctx.db
      .query("chatMessages")
      .withIndex("by_chat_id", (q) => q.eq("chatId", chatId))
      .order("desc");

    const page = await messagesQuery.paginate(paginationOpts);
    return page;
  },
});

What I’d check in your app:

#
  1. Server logs for Read/write limit errors or similar when those users stop receiving updates. [Read/write errors]
  2. Any queries that:
    • Use .filter instead of .withIndex.
    • Return very large arrays (all messages, all users, etc.) without pagination.
  3. Whether you have any “presence” / heartbeat‑style data that updates very frequently and is read by many queries; that can cause frequent invalidation and recomputation. The “Queries that scale” article shows how to split frequently changing fields into separate documents to reduce this. [Caching optimization]

If you can share the code of the query your React Native client subscribes to (the one that should deliver new messages), I can help map it directly to the patterns above and suggest a concrete rewrite.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: