Sunday 21 April 2019

From 'PHP' -> 'Node.js event/loop' ... dealing with multiple web requests + database connections + privacy concerns?

I'm coming from a PHP background where things are pretty simple...Everything is synchronousEvery web request is in an entirely 'new + separate + private' PHP process that is killed as soon as the response is sentI never had a need to make multiple connections to a database from within a single PHP processNow I'm moving over to Node.js, and things are obviously quite different here given the event/loop model...where multiple web requests can be served by a single Node processlots of async things might be going on within a single process waiting for stuff to finishyour Node process could be holding some sensitive data in memory that only the relevant user should be able to accesssome of the users of your website might be doing stuff that involves slower database queries than others...so I'm wondering does this mean that each web request received by Node should create its own database connection, so that the slow requests don't block the fast ones?Obviously might not matter on small sites with only fast queries, so lets assume we're talking about bigger sites with parallel fast + slow queries to consider.I'm using postgres, but would be interested to hear if there are any differences with other databases.Also keen to hear any tips in general that might be good to know for people new to event/loop web servers coming from PHP backgrounds etc. I haven't even started to think about how security works here... seems like an area where you could easily make some mistakes when you're used to each application process being entirely private. Any guides or anything out there with some tips?

Submitted April 21, 2019 at 03:22PM by r0ck0

No comments:

Post a Comment