Read-write and read-only transaction routing with Spring

Introduction In this article, I’m going to explain how you can implement a read-write and read-only transaction routing mechanism using the Spring framework. This requirement is very useful since the Single-Primary Database Replication architecture not only provides fault-tolerance and better availability, but it allows us to scale read operations by adding more replica nodes.

Spring read-only transaction Hibernate optimization

Introduction In this article, I’m going to explain how the Spring read-only transaction Hibernate optimization works. After taking a look at what the Spring framework does when enabling the readOnly attribute on the @Transactional annotation, I realized that only the Hibernate flush mode is set to FlushType.MANUAL without propagating the read-only flag further to the Hibernate Session. So, in the true spirit of open-source software developer, I decided it’s time to make a change.

How does Hibernate READ_ONLY CacheConcurrencyStrategy work

Introduction As I previously explained, enterprise caching requires diligence. Because data is duplicated between the database (system of record) and the caching layer, we need to make sure the two separate data sources don’t drift apart. If the cached data is immutable (neither the database nor the cache is able to modify it), we can safely cache it without worrying about any consistency issues. Read-only data is always a good candidate for application-level caching, improving read performance without having to relax consistency guarantees.