Re: Is it better keep most logic in the database or the Node.js application?

From: Laszlo Forro <getforum(at)gmail(dot)com>
To: Simon Connah <simon(dot)n(dot)connah(at)protonmail(dot)com>
Cc: "pgsql-novice(at)lists(dot)postgresql(dot)org" <pgsql-novice(at)lists(dot)postgresql(dot)org>
Subject: Re: Is it better keep most logic in the database or the Node.js application?
Date: 2021-03-19 14:41:48
Message-ID: CAHsHJAgAcsmGiO5RvHYBVRvOOEfk3CAfh8zy3MfCB=tzz5NnMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

My experience is that
- design your entities and represent them via a view. That means: you may
normalize an entity - say, customer entity across tables like 'address' :
'personal data ' etc. various ways. But the view you offer to the client
code will be consistent like an API. If your entity representation turns
out to be suboptimal, you still can change the table structure and adjust
your view but nothing to do in the client code.
- use deterministic data transformations/pure functions in the DB - that is
faster, business logic independent, easy to test and you save client code.
Such as aggregates, combinations of columns - concatenations, math
operators, rolling averages, etc.
The rest I would put into the client code - more business logic related
data transformations.
This architecture keeps your DB as an encapsulated domain but also makes it
possible to switch the client code.
I hope this helped.
Laszlo

On Fri, Mar 19, 2021 at 8:38 AM Simon Connah <simon(dot)n(dot)connah(at)protonmail(dot)com>
wrote:

> Hi,
>
> I've been wondering this for some time but is it better to keep the vast
> majority of the logic in the database using functions, stored procedures,
> triggers and everything else or should I keep the SQL in the Node.js web
> application and use that to directly query the database object? I would
> have thought using database functions would be faster as the database will
> know what the query is ahead of time and can perform some optimisations on
> it but this is just a guess on my part.
>
> What should I do? Keep everything in the Node.js application or do as much
> as possible in PostgreSQL?
>
> Simon.
>
>
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Bzzzz 2021-03-19 14:45:49 Re: Is it better keep most logic in the database or the Node.js application?
Previous Message Simon Connah 2021-03-19 08:37:48 Is it better keep most logic in the database or the Node.js application?