Connection Per Request
Connection Per Request is a software design pattern where a new database connection is established for each individual HTTP request or operation, and then closed immediately after the request is processed. This approach ensures that connections are not held open longer than necessary, reducing the risk of resource exhaustion and connection leaks. It is commonly contrasted with connection pooling, where connections are reused across multiple requests.
Developers should use Connection Per Request in scenarios where application load is low to moderate, or when simplicity and isolation are prioritized over performance, as it avoids the complexity of managing a connection pool. It is particularly useful in serverless architectures or microservices where requests are infrequent and stateless, ensuring clean resource management without the overhead of pooling. However, for high-traffic applications, this pattern can lead to performance bottlenecks due to the overhead of repeatedly establishing connections.