Slash GraphQL’s pricing is based on the number of credits you backends consume over the month. A lot of people have been asking what a credit means and how to plan our their credits usage with Slash GraphQL.
What is a credit?
A credit represents the complexity of running a query in your Slash GraphQL backend. Credits are calculated based on the number of nodes that are accessed.
- A simple query that reads upto 1000 nodes costs a single credit
- A query that accesses 1000-10k nodes costs 2 credits
- A query that accesses 10k-100k nodes costs 3 credits
- A query that accesses 100k-1M nodes costs 4 credits
- And continues logarithmically beyond that.
We’ve chosen a log based scale between TouchedNodes and QueryCost to help make your planning easier. We don’t really want you worry about the difference between touching 2400 nodes and 2600 nodes, but if a query is 10x more complex, we’ll charge you an extra credit.
Astute readers will notice that firing a single query that touches 500 nodes will be cheaper than firing 5 queries that each read 100 nodes, thus multiple query blocks into a single /graphql request is a great way to reduce the number of credits your app consumes.
How do I know how many nodes were accessed?
All graphql requests return two headers with details for billing.
Graphql-QueryCostcontaining the cost of the query
Graphql-TouchedNodescontaining the number of nodes touched.
There are similar headers for GraphQL± requests as well, starting with
Dgraph stores each record as a set of nodes, so if you return 5 records with 10 fields each, then you will have touched 50 nodes. Additionally, if you’ve searched for these records, then we’ll have touched a few index nodes (depending on how the index is set up), so maybe you’ve touched 65 nodes for this query.
How do I estimate my credits usage?
A great way to estimate your credits usage is by looking at the sort of traffic and usage your app needs. Let’s say you get 1000 visitors a month. A visit to your app makes 3 queries, and an average query takes 1.5 credits. So you can plan capacity at 45k credits/month
What about introspection queries and subscriptions?
Introspection queries and health queries are not charged, and effectively are 0 credits (though you will still see the number of queries increasing due to these queries.
Subscriptions are charged whenever data is transmitted. This means that idle subscriptions are not charged, but only when updates are pushed to listeners.