<p>We are accessing shared database from multiple pods in kubernetes. All the pods may writes/updates and reads from the db. How to handle data integrity in this case ? Is JPA isolation levels are enough for handling this or need to go with pessimistic locking ?  Can you also help me with the difference between both ?</p>

LearningBuddy
<p>Your question has nothing to do with Kubernets. This simply concurrent database access that you'll get if more than one connection is accessing your database.</p>
<p>If you want to avoid problems like <a href="https://www.geeksforgeeks.org/concurrency-problems-in-dbms-transactions/#:%7E:text=In%20the%20lost%20update%20problem,by%20transaction%202%20on%20X." rel="nofollow noreferrer">lost update</a> then you need locking.</p>
<p>There are two types of locking.</p>
<ul>
<li>Optimistic</li>
<li>Pessimistic</li>
</ul>
<p>Optimistic is handled by Hibernate with a version field. Pessimistic is the locking mechanism of the database.</p>
<p>You should also read Hibernates documentation about Locking.
<a href="https://docs.jboss.org/hibernate/orm/5.5/userguide/html_single/Hibernate_User_Guide.html#locking" rel="nofollow noreferrer">https://docs.jboss.org/hibernate/orm/5.5/userguide/html_single/Hibernate_User_Guide.html#locking</a></p>
