Is it bad to make multiple database calls?
In general, I have found making multiple database calls to not be a problem. This is mostly because of connection pooling and the small latency between the DB and web server. There is a point where making a bunch of different db calls will negatively impact performance, but I do not have a hard number for you.
Which is better n or 2 database calls?
In the example above, you would have 2 database calls. 2 is fine. 3 may be fine. N is not fine. If you call the database in a loop, you have now made performance linear, which means it will take longer the more that is in the loop’s input.
How to decouple database calls from HTTP requests?
It’s about flexibility. Sometimes to achieve good decoupling, you want to have 2 database calls separated. For example, perhaps every HTTP request is routed through a generic security filter which validates from the DB that the user has the right access rights. If they do, proceed to execute the appropriate function for that URL.
Why does the API make calls to the database?
The API would make calls to the database. One theme that recurs in our discussions is performance: some people on the team believe that you should not have multiple database calls (usually reads) from a single API call because of performance; you should optimize them so that each API call has only (exactly) one database call.
Why do you not recurs in an API call?
One theme that recurs in our discussions is performance: some people on the team believe that you should not have multiple database calls (usually reads) from a single API call because of performance; you should optimize them so that each API call has only (exactly) one database call. But is that really important?
Which is cheaper database call or network call?
You mentioned that a database call should be cheap compared to a network call from the app to the API. But you also mentioned that the app and the API servers are in the same LAN. Therefore, aren’t both of them comparable as network calls?
How to reduce the size of source data?
When source data is loaded into memory, it is possible to see 10x compression, and so it is reasonable to expect that 10 GB of source data can compress to about 1 GB in size. Further, when persisted to disk an additional 20% reduction can be achieved.