I am planning on building an application using Node JS that stores and retrieves its data from a postgresql database. My concern is that as the application scales will I run into query contention on the database? If I have perhaps a dozen or more Node JS instances talking to the database at once updating different tables and fields eventually something somewhere will collide. How can I prevent this from happening or what is the best way to mitigate it ?
1 Answer
...at once updating different tables and fields eventually something somewhere will collide. How can I prevent this from happening
For that PostgreSQL supports database transactions and locks.
3 Comments
Scoots
Worth warning about deadlocks here though. For the uninitiated, a deadlock occurs when a process gains a lock on table A, and does some heavy duty processing there. Meanwhile, another process has a lock on table B. The first process then needs access to table B, so it starts waiting. The second process then moves on to needing table A. Neither process can proceed until the other finishes. Postgres detects this, and kills both processes. Rolling back transactions in both if they are in transactions.
vitaly-t
@Scoots No spoilers! ;)
neatoh80
amazing answers ! Thanks !