1

In NodeJS applications, what is the best strategy for managing number of connections when transactions are involved (mysql community version)?

So, this is my line of thinking -

1) Do not hand over control to an ORM 2) Treat connection as an expensive commodity 3) mysql module for nodejs appears to be creating more connections

Given that, if n promises are executing at the same time (single thread part is understood), each representing a transaction, I do not want each of them create n connections - that much is obvious - but what happens when a transaction needs to be rolled back on a connection, if a connection is shared between promises? ..I do not want one transaction to fail if a another one fails as well..I would expect the 'connection' object to be little more intelligent..such that when beginTransaction is called, it provides a localized context...but just want to confirm if this is the case - I am looking for some documentations. If not, some sort of FIFO queue to facilitate sequalizing these transactions appear to be the way forward - but don't we already have one? What are other strategies you folks deployed?

1

1 Answer 1

1

I would suggest to you KnexJS, especially because of its transaction supprt and built-in connection pooling. I'm sure Sequelize handles this in some way as well.

The nice thing about knex is that you can pass this transaction object through your promise chain, and if any promise fails (even from a non-DB error, like a business rule!) the transaction promise will be rejected and everything is automatically rolled back.

I hope this helps you out and has "just worked" for us so far - we have not needed to delve into the management of a connection pool at this time.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Clay - will take a look

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.