Scenario: You’re using React Server Components, so you can query the DB in a...


Scenario: You’re using React Server Components, so you can query the DB in a server component. Your app is the DB’s only consumer.

Do you query the DB directly?

Or do you still build an HTTP API in front of the DB?
My take?

Call the DB directly. Avoid needless abstractions.
Also, if 2 or more apps need to query the DB, that still doesn’t necessarily mean an HTTP API (REST/GraphQL) is the way to go.

🚩HTTP is slower than a direct DB call.

🚩Adding an API requires writing more code.

🚩Plain SQL is more flexible if apps need different data.

View original on X