Does Convex count updates from query as function calls?
For example, if we call query function and it triggers 10 updates (there's 10 mutations happening that cause the query to send updates to clients), would this incur cost as 1 function call or 10?
I presume that the cost is only 1 function call so it doesn't matter how many times this websocket connection sends updates.
10 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Yes, every update is a function call. A large amount of this is typically cached, and the team has mentioned treating cached responses differently than non-cached for billing purposes in the future, but currently they're treated the same.
I don't fully understand the details of the example case you shared - queries won't ever trigger updates, only mutations will - but in the simplified case where 10 app users are on a page with the same query and the underlying data changes, that'll cause 10 function calls to the query. I assume 9 or 10 of these would be cached, but that goes beyond my understanding.
for a subscription to a query, indeed each mutation function that changes it , unless they happen very quickly together, in which case they could be combined, does trigger a new query call.
Caching pays off when you have multiple clients subscribed to the same query, or repeatedly request a query or subscribe/unsubscribe on one client
If this isn't desirable, you can choose not to subscribe! Often the writes in applications are rarer than the reads and this update live behavior is what you want, but you can always treat convex like an api server and refresh data when you want to, eg every few minutes or whenever the user refreshes the page.
Adding a note from Jamie for posterity, cached calls count as function calls but don't use bandwidth: https://discord.com/channels/1019350475847499849/1019350478817079338/1374042998274261092
Doesn't this mean Convex is quite expensive if we have lots of free users?
Basically every time a user sees updates in the webpage due to mutations, we can count it as 1 function call right?
Example: see likes number go up, see new comment, etc
You can use server components if you want to prevent the data from being refreshed, and refresh the page with next invalidate route
But yeah they stated in a podcast that convex SHOULD be used on projects that are making money
Pays off in terms of bandwidth, or also function calls? Do I understand correctly, that even if the query is cached, it still consumes the function call?
I couldn't really find information about this in the docs and that's how I stumbled upon this thread. Just wanted to clarify, because function calls seem to be one of highest possible costs for my app.
any update on whether or not a cached query avoids using a function call @ballingt or @erquhart ? maybe I'm thinking of it wrong but would seem a bit egregious if you have heartbeat-like queries e.g. to show how many total users are online, if you have 1,000 users online at all times and give updates every 5 minutes, that's 1k function calls every 5 min, 12k/hour, so 8mm calls / month just from this. If caching didn't charge the dev using convex, it would be 1 function call every 5 min, 12/hr, 8k calls / month which is much more palatable
just following up on this
Each individual subscribed client does make a function call when changes occur, so if you have a lot of users it's a lot of function calls. Your scenario of 8m function monthly function calls would cost $15 per month for function call overage, which feels pretty reasonable (imo) for servicing 1,000 active users.
I think 8m just feels like a big number, but Convex is sort of designed to run lots of small operations, and to try to make it relatively cost effective to do so. A high traffic app is just going to have a lot of function calls. Having really effective caching to avoid database bandwidth charges makes this generally tenable.
Also note if you're on pro plan it includes 25m function calls per month, so would probably cover your use case, and gives you access to support where you can get direct help from the team on strategies for scaling efficiently.
thanks for the response @erquhart, and to be fair i'm guessing there are better ways of storing a user's last seen timestamp at that scale via redis or cloudflare durable object for 1k concurrent users. i guess another deeper question is that if changes do not occur to underlying data and a query is cached (and applicable to any visitor), would the next visitor that comes along and calls the same query not only avoid bandwidth charges between underlying db & convex functions but also avoid a function call? if not, would there be consideration to make it count as like half a function call or something if the query is cached? i know that might be a hard question to answer and is more of a convex business model question, just seems like convex rewards good/performant developer decisions in general (e.g. like with data bandwidth not incurred for cached queries) so figured that would also align with incentivizing devs to do proper architecture