We have an architecture setup where we have the client application running in a server and we would want to have a Micro Service responsible for offering the Distributed Lock/Map/Cache functionality. This Micro service internally uses Redisson , a java based client that can talk to Redis. Now we would want to provide apis lock, unlock, get,put from the Micro service which the client application can consume.For application to micro service communication, we would use gRPC protocol.
What is the right way to offer lock/unlock apis from Microservice to the client? Currently, we use Redisson's Semapbased on RedissonMap RMap.getLock(..)) and it follows java Lock specification so thread that acquires a Distributed lock only can unlock. One issue with this is Since Locking is handled by a Microservice, client has to make separate lock and unlock requests which may or may not be served by same node (Microservice) and same thread. this can be worked around by using Semaphore (with 1 permit). So, essentially we use Rsemaphore of redisson to server the usecase of mutual exclusion
I am more interested to find out what should be the factors that need to be considered when we come up with API spec for acquire/release, like whether the call to acquire/release permits at the Microservice should be synchronous or asynchronous.