Skip to content

Can one ensure one database connection per HTTP request with Express? #17076

Answered by ephys
webJose asked this question in Help & Questions
Discussion options

You must be logged in to vote

They indeed use the same Sequelize instance but a single sequelize instance can have many connection to the database (by default it's 5 concurrent connections, but can be configured)

So what would happen if two concurrent HTTP requests each started their own transaction would be that both would execute the following step concurrently:

  • Take a connection from the connection pool
    • Because the connection is removed from the pool while the transaction is active, no other query can use this connection, except if they're in the transaction callback
  • Start its transaction on that connection
  • Execute the callback, in which all queries will use that same connection that was taken from the pool
  • Onc…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@webJose
Comment options

@ephys
Comment options

@webJose
Comment options

@ephys
Comment options

Answer selected by webJose
@webJose
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants