Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle concurrent transactions from multiple pods in kubernetes

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 ?

like image 509
LearningBuddy Avatar asked Sep 19 '25 16:09

LearningBuddy


1 Answers

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.

If you want to avoid problems like lost update then you need locking.

There are two types of locking.

  • Optimistic
  • Pessimistic

Optimistic is handled by Hibernate with a version field. Pessimistic is the locking mechanism of the database.

You should also read Hibernates documentation about Locking. https://docs.jboss.org/hibernate/orm/5.5/userguide/html_single/Hibernate_User_Guide.html#locking

like image 181
Simon Martinelli Avatar answered Sep 21 '25 06:09

Simon Martinelli