How to address the OptimisticLockException in JPA and Hibernate

Introduction Application-level repeatable reads are suitable for preventing lost updates in web conversations. Enabling entity-level optimistic locking is fairly easy. You just have to mark one logical-clock property (usually an integer counter) with the JPA @Version annotation and Hibernate takes care of the rest. The catch Optimistic locking discards all incoming changes that are relative to an older entity version. But everything has a cost and optimistic locking makes no difference. The optimistic concurrency control mechanism takes an all-or-nothing approach even for non-overlapping changes. If two concurrent transactions are changing distinct entity… Read More

The simple scalability equation

Queuing Theory The queueing theory allows us to predict queue lengths and waiting times, which is of paramount importance for capacity planning. For an architect, this is a very handy tool since queues are not just the appanage of messaging systems. To avoid system over loading we use throttling. Whenever the number of incoming requests surpasses the available resources, we basically have two options: discarding all overflowing traffic, therefore decreasing availability queuing requests and wait (for as long as a time out threshold) for busy resources to become available This behavior applies… Read More