public inbox for [email protected]
help / color / mirror / Atom feedFrom: Laszlo Forro <[email protected]>
To: Simon Connah <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: Is it better keep most logic in the database or the Node.js application?
Date: Fri, 19 Mar 2021 14:41:48 +0000
Message-ID: <CAHsHJAgAcsmGiO5RvHYBVRvOOEfk3CAfh8zy3MfCB=tzz5NnMQ@mail.gmail.com> (raw)
In-Reply-To: <iP1Q7A5jXefT-1pnTm_xe11oZwWMxeZydnC6UfZAOu4BesbseT2xtKgwpR_3FORbOpg44gUNHiH1N_9FRzCDyz98hXlIubXTRuTKX1TNFVA=@protonmail.com>
References: <iP1Q7A5jXefT-1pnTm_xe11oZwWMxeZydnC6UfZAOu4BesbseT2xtKgwpR_3FORbOpg44gUNHiH1N_9FRzCDyz98hXlIubXTRuTKX1TNFVA=@protonmail.com>
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 <[email protected]>
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.
>
>
>
view thread (7+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Is it better keep most logic in the database or the Node.js application?
In-Reply-To: <CAHsHJAgAcsmGiO5RvHYBVRvOOEfk3CAfh8zy3MfCB=tzz5NnMQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox