Can Spring Integration Distributed Lock be Horizontally Scaled?

67 Views Asked by At

I have a user-case where multiple services would need to interact with the same resources, and as such I'm exploring distributed lock libraries.

Since multiple services (>5) will be requesting/releasing locks, I'm building a central lock manager service to separate out the lock management responsibility.

I was exploring Spring integration - distributed locking framework, but the documentation is pretty limited. I wanted to get some clarity on whether this approach is horizontally scalable.

From my understanding, this framework manages an in-memory map of locks to enhance the getLock operation performance. Unless there is a pub-sub mechanism like Redisson here where threads are updated after a lock is released/expired, I do not think this approach would be horizontally scalable, as the in-memory maps across multiple instances of lock management service may not always be in-sync.

Github - RedisLockRegistry

Spring integration - distributed locks

1

There are 1 best solutions below

3
On

You question is not clear. If you talk about a cluster of your applications, then you indeed need to look into some solution for distributed locks based on some shared data store. And if you use such a store, then you cannot say that those locks are managed in-memory. Well, yes, there is a local Lock management, since we still need to ensure a proper concurrency in the current JVM.

According to the Redis Lock Registry docs: https://docs.spring.io/spring-integration/reference/redis.html#redis-lock-registry, there is a RedisLockType.PUB_SUB_LOCK mode if you are interested exactly in pub-sub behavior.