Api rest vs directly to db? which is faster

Hi which way is faster? create app to connect directly to db postgresql? or create a api rest? which one is faster in terms of speed, perfomance, to load data to a table for example?

thank you

Hi @agaitan026

Any API needs to query the DB first, in order to format and deliver the response, thus, the direct DB call is faster by definition.

But, an API layer can exploit some cache strategy that can benefit the speed for queries that don't change often or that are very expensive in computing.

So, it depends of your use case.

Hope this help.

1 Like

Thank you

@agaitan026 I'd also add that it depends on how often you'll be calling the API, calling an API endpoint creates extra overhead (extra time for: retool overhead, calling API endpoint, sending API result back).

how much data would also matter depending on if you're using the New Table or Legacy Table, the new table. depending on what your data looks like you could try and use the New ListView instead to take advantage of virtualization which would load your data much quicker.

i think another thing to consider is if you need the API endpoint in other apps/modules. if you only need to use it in a single app/module then there isn't usually much need for an API endpoint and a Resource Query to directly access the db would almost always be faster.

1 Like

Yeah thats what I thought i will use db directly as its for one app only. So i dont need to develop api better

Thank you for the suggestion