What to do when dealing with N multiple transactions at the same time?
Most of the time we perform CRUD operations under the pragmatic standard transactional scope, thinking it will suffice under all circumstances. After all, what could go wrong when we always apply a standard ACID tool provided by our frameworks, right? But it feels βgood enoughβ only until we face corner cases of the real world production traffic: missing rows after pagination, duplicated updates, or metrics that refuse to add up.
Going deeper in the reasons of why to use more than the traditional transactional, scope can be hard without some real world examples of when or how should we use something different from what we use to. In this article I revisit those issues through a tiny Spring Boot/Java code base. The example we will use run through the following steps:
- Paginate 5 000
Sale
rows whose status starts asNOT_INITIALIZED
.- Publisheach id to a Kafka topic.
- Consumeeach message, updating its status to
PROCESSING
.- Demonstrate how plain idempotency checks and pagination fail under load.
- Apply REPEATABLE READ isolation level and optimistic locking to restore consistency with much better performance.
continue reading on medium.com
β οΈ This post links to an external website. β οΈ
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.