/db-locking-poc

POC to get a better understanding about optimistic and pessimistic locking

Primary LanguageJava

Optimistic and pessimistic locking proof of concept

More details can be found in this article

Optimistic and pessimistic locking are techniques used to avoid conflicts that arise when multiple instances or threads of an application attempt to access or update the same data simultaneously. This proof of concept (POC) was created to simulate the conditions in which these conflicts could occur and demonstrate how to avoid them using one or both approaches depending on the situation.

This POC is a Java-based project was built using Spring Boot 3 and needs JDK 17 to be compiled and run.

The microservice will be scaled horizontally into a Kubernetes cluster having four instances to provide the right conditions to demonstrate the behavior described before. The files dblockingpoc.yaml and postgresql_pod.yaml include all the configurations required for deployment.

The following diagram depicts the Kubernetes cluster.

My Image

Deploying service

  1. Build docker image
gradle bootBuildImage
  1. Deploying postgresql database
kubectl apply -f postgresql_pod.yaml
  1. Deploying service with 4 replicas
kubectl apply -f dblockingpoc.yaml

Resources