A Flask request is an object that represents one HTTP request. The Flask infrastructure in a deployed app ensures that these are thread-specific, so that the "request" object which seems like it's a global variable is in fact thread-global, not process-global.
If you really want to know the underlying details, check out this Q&A with ChatGPT: Flask Request Implementation
No, making a database connection per request doesn't avoid all
possible threading bugs. It only allows correct use of the
MySQL last_insert_id() function. If you used a global
database connection, you might get the wrong answer. Imagine:
last_insert_id() and gets 71; She walks away.
last_insert_id() and gets 71;
Great question! MySQL is designed to handle multiple connections. Remember in the beginning of the course when we all were running the MySQL client (shell) at the same time? Those are multiple connections.
Also, last time, we learned about locks and transactions, whose purpose is to support concurrency.
As to performance, MySQL does very well. At the very lowest levels, the DMBS needs to have exclusive access to the data structure for a row or table, but that is kept small to maximize concurrency.
I asked ChatGPT about how does mysql perform on measure of concurrency
Great!