Skip to content
Back

How to reduce DB Reads?

  • 0
  • Databases
  • Cloud
armur
16 May, 2025, 03:57

I just noticed that I hit the 500k db reads limit on my very small next js app with the most data being present in one collection having around 50 documents.

I do use a lot of relations to link the collections. When creating a relation to another collection, I usually do a 2 way relationship. Is this the root cause?

Or could it be something like infinite loops on the app, calling the database?

Any suggestions on how to diagnose and fix?

TL;DR
Developers are concerned about high DB read count due to relations between collections causing a cascade effect. They hit the read limit and suspect it's due to 2-way relationships or infinite loops. Suggestions for diagnosis and fix are needed. Solution: 1. Check for any unnecessary or redundant relationships in the collections. 2. Ensure relations are optimized and not causing unnecessary reads. 3. Look for any potential infinite loops in the app code that may be leading to excessive database calls. 4. Monitor and analyze database queries to identify performance bottlenecks.
D5
16 May, 2025, 09:37

How many related docs do you have?

Steven
16 May, 2025, 16:44

Fyi, relationships are experimental and should be used with caution as they may lead to performance issues

Steven
16 May, 2025, 16:45

Relationships could be related. Every related document adds to the DB read count

armur
18 May, 2025, 12:46

For example I have a collection that is realted to 4 other collections, one of which is a one to one relationship and the remaining three are many to one or many to many

armur
18 May, 2025, 12:48

So if I read 10 documents in a collection which has 4 relations to other collections, then the total reads will be 10 + (10 x 4) total of 50 reads on the DB? What if those related documents contain relations to other collections? Will the read count cascade multiply for each document read?

Steven
18 May, 2025, 15:27

Yes, every document returned is 1 read

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more