@@ -144,6 +144,52 @@ To enable automatic badge updates and coverage reports, ensure the following Git
144144 - "Read and write permissions"
145145 - "Allow GitHub Actions to create and approve pull requests"
146146
147+ ## Read Write Datasource Routing
148+
149+ ![ Read Write Deployment] ( docs/arch_diagram_datasource_read_write.png )
150+
151+ The application supports read-write splitting for database operations. This feature is disabled by default but can be enabled through configuration.
152+
153+ ### Configuration
154+
155+ ``` yaml
156+ spring :
157+ datasource :
158+ writer :
159+ jdbcUrl : jdbc:postgresql://localhost:5432/flighttracker
160+ username : flighttracker
161+ password : flighttracker
162+ driverClassName : org.postgresql.Driver
163+ type : com.zaxxer.hikari.HikariDataSource
164+ reader :
165+ jdbcUrl : jdbc:postgresql://localhost:5433/flighttracker
166+ username : flighttracker
167+ password : flighttracker
168+ driverClassName : org.postgresql.Driver
169+ type : com.zaxxer.hikari.HikariDataSource
170+
171+ app :
172+ read-write-routing :
173+ enabled : false # Set to true to enable read-write splitting
174+ ` ` `
175+
176+ ### Important Notes
177+
178+ 1. When enabled, you must configure both write and read data sources
179+ 2. The routing is based on Spring's ` @Transactional` annotation:
180+ - Read operations : Use `@Transactional(readOnly = true)`
181+ - Write operations : Use `@Transactional` or `@Transactional(readOnly = false)`
182+
183+ 
184+
185+ 3. If read-write splitting is enabled but not properly configured, the application will fail to start
186+ 4. For development and testing, it's recommended to keep this feature disabled
187+ 5. The routing is handled by :
188+ - `DatasourceConfig` : Configures the data sources and routing
189+ - `RoutingDataSource` : Routes requests to the appropriate data source
190+ - `ReadWriteRoutingAspect` : Sets the context based on transaction type
191+ - `DbContextHolder` : Thread-local holder for the current context
192+
147193# # Project Structure
148194
149195```
@@ -171,6 +217,12 @@ To enable automatic badge updates and coverage reports, ensure the following Git
171217โ โ โ โ โ โโโ Mediator.java
172218โ โ โ โ โ โโโ SpringMediator.java
173219โ โ โ โ โโโ infrastructure/
220+ โ โ โ โ โโโ datasource/
221+ โ โ โ โ โ โโโ DbContextHolder.java
222+ โ โ โ โ โ โโโ ReadWriteRoutingAspect.java
223+ โ โ โ โ โ โโโ ReadWriteRoutingProperties.java
224+ โ โ โ โ โ โโโ RoutingDataSource.java
225+ โ โ โ โ โโโ DatasourceConfig.java
174226โ โ โ โ โโโ KafkaConfig.java
175227โ โ โ โ โโโ OpenApiConfig.java
176228โ โ โ โโโ flightdata/
0 commit comments