node-redlock icon indicating copy to clipboard operation
node-redlock copied to clipboard

Redlock FIFO

Open KamalAman opened this issue 3 years ago • 2 comments
trafficstars

Is there any possible way with the redlock algorithm the enforce FIFO behaviour to resolve subsequent lock in order rather than randomly based on the retry interval?

KamalAman avatar Sep 14 '22 16:09 KamalAman

Sharing a thought: To enforce FIFO one would need to take in consideration the timestamp of when locking, but because the user is a distributed system, the nodes most likely aren't synchronized in their clocks, so those can't be relied on for ordering. Similarly from network traffic being sent from the user to Redis there's an unpredictable network delay, which means that the ingress timestamp can't be relied on either. Therefore strict FIFO is very hard to do.

soryy708 avatar Nov 17 '22 14:11 soryy708

What i was more thinking was: using Redis queues

  • every time a key is locked the lock goes into a queue on redis
  • clients peek the queue to see if they should handle it
  • the appropriate client will handle it, then pop the element off the queue
  • clients peek again

I feel like the order of the lock queue is the only thing that matters. Maybe there is something foundational that I do not understand here.

KamalAman avatar Jan 13 '23 17:01 KamalAman