Storage
Network
This is within the capacity of 1 redis cluster without sharding.
lock(client_id, name, ttl=inf) // wait for lock to be acquired
try_lock(client_id, name, timeout=0, ttl=inf) // Return if lock is not acquired within timeout
boolean release_lock(client_id, name) // true if the lock was acquired by this client
boolean refresh_lock(client_id, name, ttl=inf)
Redis option:
if (get(key) == clientid)
delete(key)
Zookeeper option:
The graph depicts the redis based option. Client calls redis API directly. In the case of releasing the lock, the script is wrapped in a LUA script to ensure atomicity.
The request flow is pretty simple. The client initiates direct call to redis or zookeeper.
For the redis option, for better reliability we should stand up N redis clusters/masters in high availability mode.
How to avoid deadlock:
The TTL can alleviate deadlocks.
Redis vs Zookeeper
Zookeeper's Paxos-like protocol is fault tolerant against server failures, network partitions. However, it is computationally more intensive. We can shard zookeeper if needed.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?