Skip to content

Commit 1cfd622

Browse files
committed
Docs: README, add section on read only use case
1 parent c0d0265 commit 1cfd622

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ DataSourcePool pool = DataSourcePool.builder()
1717
.build();
1818
```
1919

20+
For read-only use cases, configure the pool with `readOnly(true)` and `autoCommit(true)` for optimal performance:
21+
2022
```java
2123
DataSourcePool readOnlyPool = DataSourcePool.builder()
22-
.name("mypool")
24+
.name("mypool-readonly")
2325
.url("jdbc:h2:mem:test")
2426
.username("sa")
2527
.password("")
@@ -67,6 +69,51 @@ are returned to the pool that have throw SQLException. This makes the connection
6769
but also robust.
6870

6971

72+
### Read-Only Connection Pools
73+
74+
For read-only use cases (analytics, reporting, caching, microservices that only query), create a
75+
separate read-only pool configured with `readOnly(true)` and `autoCommit(true)`. This optimizes
76+
the connection pool specifically for read-only workloads:
77+
78+
```java
79+
DataSourcePool readOnlyPool = DataSourcePool.builder()
80+
.name("mypool-readonly")
81+
.url("jdbc:postgresql://read-replica.example.com:5432/myapp")
82+
.username("readonly_user")
83+
.password("pass")
84+
.readOnly(true)
85+
.autoCommit(true)
86+
.minConnections(5)
87+
.maxConnections(30)
88+
.build();
89+
```
90+
91+
**Benefits of read-only pools:**
92+
93+
- **Database optimization:** Read-only mode signals the JDBC driver and database that no transactions
94+
will be written. This allows the database to optimize query execution and skip transaction overhead.
95+
96+
- **Reduced resource usage:** `autoCommit(true)` eliminates the overhead of managing explicit transaction
97+
boundaries for each query. The database doesn't need to maintain transaction state for read-only operations.
98+
99+
- **Lower latency:** Queries execute faster without transaction coordination overhead, improving response
100+
times for read-heavy workloads.
101+
102+
- **Separation of concerns:** Using a dedicated read-only pool makes the intent of your code clear and
103+
allows you to configure connection pooling independently from your write pool.
104+
105+
- **Better scaling:** Read-only pools can often use different connection sizing, timeouts, and validation
106+
strategies optimized specifically for query operations.
107+
108+
**Common read-only scenarios:**
109+
110+
- Analytics and reporting engines querying large datasets
111+
- Microservices that only read from shared databases
112+
- Caching layers (e.g., warm-up queries for distributed caches)
113+
- Read replicas in multi-region deployments
114+
- Background workers that periodically fetch reference data
115+
116+
70117
### Kubernetes / Container Deployment
71118

72119
When deploying to Kubernetes or other container orchestration platforms, configure `initialConnections`

0 commit comments

Comments
 (0)