Spring Transaction and Connection Management

Introduction In this article, we are going to see how Spring handles transaction and database connection management. I decided to write this article because this topic has been requested recurringly by the students taking my High-Performance Java Persistence training.

Spring MDC Transaction Logging

Introduction In this article, we are going to see how to configure a Spring application to use MDC (Mapped Diagnostic Context) for transaction logging. This technique is going to help us inject the Persistence Context information as well as the associated database transaction identifier in all the log entries emitted from within a @Transactional service method.

Strong Consistency with YugabyteDB

Introduction In this article, we are going to see why the default strong consistency guarantees offered by YugabyteDB allow you to design applications that are more resilient than when using traditional relational database systems. If you’re new to YugabyteDB, check out this article first, in which I explain what YugabyteDB is and why you should consider using it.

Spring Transaction Best Practices

Introduction In this article, I’m going to show you various Spring Transaction Best Practices that can help you achieve the data integrity guarantees required by the underlying business requirements. Data integrity is of paramount importance because, in the absence of proper transaction handling, your application could be vulnerable to race conditions that could have terrible consequences for the underlying business.

The race condition that led to Flexcoin bankruptcy

Introduction It’s hard to imagine that a race condition bug could lead to the bankruptcy of a given online service, isn’t it? In this article, I’m going to show you how a race condition led to the bankruptcy of Flexcoin in 2014.

The best way to use the Spring Transactional annotation

Introduction In this article, I’m going to show you the best way to use the Spring Transactional annotation. This is one of the best practices I applied when developing RevoGain, a web application that allows you to calculate the gains you realized while trading stocks, commodities, or crypto using Revolut.

Connection Monitoring with JPA and Hibernate

Introduction In this article, I’m going to show you how you can set up connection monitoring for your JPA and Hibernate application, no matter if you are using Spring or other application frameworks.

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.

PostgreSQL triggers and isolation levels

Introduction In this article, we are going to see how the PostgreSQL isolation levels guarantee read and write consistency when executing database triggers. While relational database systems provide strong data integrity guarantees, it’s very important to understand how the underlying transactional engine works in order to choose the right design for your data access layer.

How to log the database transaction id using MDC

Introduction In this article, I’m going to show you how you can log the database transaction id associated with a given SQL statement using the MDC (Mapped Diagnostic Context) feature offered by many logging frameworks. If you are writing data access code, you have to use logging. As I explained in this article, using a JDBC proxy tool like datasource-proxy or p6spy is the best approach to logging SQL statements. With datasource-proxy, you can easily build a JUnit extension to automatically detect N+1 query issues. For more details, check out the Hypersistence… Read More