@@ -67,6 +67,63 @@ are returned to the pool that have throw SQLException. This makes the connection
6767but also robust.
6868
6969
70+ ### Kubernetes / Container Deployment
71+
72+ When deploying to Kubernetes or other container orchestration platforms, configure ` initialConnections `
73+ in addition to ` minConnections ` and ` maxConnections ` :
74+
75+ ``` java
76+ DataSourcePool pool = DataSourcePool . builder()
77+ .name(" mypool" )
78+ .url(" jdbc:postgresql://db.example.com:5432/myapp" )
79+ .username(" user" )
80+ .password(" pass" )
81+ .minConnections(5 )
82+ .initialConnections(20 ) // Start with sufficient connections for production load
83+ .maxConnections(50 ) // Upper bound during peak usage
84+ .build();
85+ ```
86+
87+ ** Why this matters:**
88+
89+ - ** Rapid production readiness:** When a new pod is deployed, it immediately serves production traffic.
90+ Setting ` initialConnections ` higher than ` minConnections ` (typically between min and max) ensures
91+ the pod can handle incoming requests without the cold-start overhead of creating many connections.
92+
93+ - ** Automatic scaling down:** The pool continuously trims unused connections in the background
94+ (default trim frequency is 59 seconds). Over time, the pool naturally shrinks back to a
95+ sustainable size as demand normalizes, so you don't waste resources.
96+
97+ - ** Prevent connection storms:** Without adequate initial connections, new deployments spike
98+ database load by creating many new connections simultaneously to service incoming requests.
99+
100+ ** Configuration strategies:**
101+
102+ ** Low-traffic services:**
103+ ``` java
104+ .minConnections(2 )
105+ .initialConnections(5 )
106+ .maxConnections(20 )
107+ ```
108+
109+ ** Medium-traffic services:**
110+ ``` java
111+ .minConnections(5 )
112+ .initialConnections(20 )
113+ .maxConnections(50 )
114+ ```
115+
116+ ** High-traffic services:**
117+ ``` java
118+ .minConnections(10 )
119+ .initialConnections(40 )
120+ .maxConnections(100 )
121+ ```
122+
123+ Start with these values as a baseline and adjust based on your application's observed connection usage
124+ and deployment patterns. The pool will automatically trim idle connections over time, so starting with
125+ more connections during deployment doesn't permanently increase resource consumption.
126+
70127
71128### Mature
72129
0 commit comments