#convex state reactivity

1 messages · Page 1 of 1 (latest)

grand grove
#

I was wondering how the automatic reactivity state of convex will scale in larger apps? are there any cache or similar systems to handle larger data among sessions?

hasty loomBOT
#

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

#

Convex’s automatic state reactivity is designed to scale efficiently, even in larger applications. Here’s how it works and how caching supports scalability:

  • Automatic Reactivity: When you use Convex query functions, clients are automatically subscribed to changes in the underlying data. Any updates to the data trigger updates to all subscribed clients, ensuring a consistent and up-to-date view across sessions and users. This is managed by Convex’s sync engine, which handles the propagation of changes in real time without requiring manual intervention or polling from developers Realtime.

  • Automatic Caching: Convex automatically caches the results of query functions. If multiple clients request the same query with the same arguments, they receive the cached response. The cache is invalidated and recomputed only when the underlying data changes. This means that as your app grows and more users access the same data, Convex serves more requests from cache, reducing redundant computation and database reads What is Sync? > End-to-end cache management, The platform you need, when you need it.

  • Cache Keying: The cache is keyed by the combination of query code, parameters, and the set of database records read by the query. This ensures that only relevant changes trigger cache invalidation and recomputation, making the system efficient even with many concurrent users What is Sync? > End-to-end cache management.

#
  • Scalability Considerations: Convex’s architecture is built to handle high fan-out scenarios (many users subscribing to the same data) efficiently. The number of function invocations grows linearly with the number of unique queries, not the number of users, thanks to caching. There are also plans for pricing models that better reflect high cache-hit, high-fanout use cases Implementing Presence with Convex, Discord: Pricing for high fan-out + high cache hit use cases.

  • Best Practices: To maintain performance, Convex recommends keeping queries and mutations light and fast, ideally working with a few hundred records and completing in under 100ms. For very large datasets, you should use pagination and indexes to avoid scanning too many documents at once The Zen of Convex, Operational maturity for production.

In summary, Convex’s automatic reactivity and caching are designed to scale with your app, minimizing redundant work and ensuring efficient updates across sessions. As your app grows, leveraging indexes, pagination, and keeping queries efficient will help maintain performance.

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