I am taking example of Java as I am comfortable with it. In a single JVM, locks like synchronized or ReentrantLock work well.
But in a clustered environment (e.g. multiple Spring Boot apps behind a load balancer), each node has its own memory, so:
Locking in memory doesn’t prevent another node from performing the same action.
You need a shared coordination mechanism — like Redis, Zookeeper etc...