What is distributed lock and why use it?

Why do people need distributed locking?

When a shared resource is protected by a local machine, does this mean that we do not need a distributed lock?

I mean, when a shared resource is exposed by another using some kind of api or service, and this api or service is protected using local locks ; then we do not need such a distributed lock; I'm right?

+4
source share
2 answers

After asking people on quora . I think I got the answer.

Suppose that N production server has accessed a database server. There are two parts here:

  • The database has its own locking methods to protect data from being damaged by the simultaneous access of other clients (N production servers). This is where the local lock in the database is called.

  • For production N servers, some coronation may be required to ensure that they are arriving correctly, and this is application specific. A distributed lock is issued here. Let's say if two production servers work with the same process, which deletes the database table and adds some record to the table. The database server can guarantee that its internal data is correct, but this process requires a distributed lock to coordinate each other, otherwise one process will drop another process table.

+1
source

Yes and no, if you publish your information from the local API through a lock in order to prevent the mutex, depending on how the lock is configured, your implementation may be exactly what the distributed lock is trying to do, but if you have not developed an API, then you will have to delve into the source of the API to find out if this is a localized or distributed locking system. Honestly, a castle is a castle, it is a castle, it is trying to do the same, no matter what. The advantage of distributed locking over localized locking is that you already take precedence into account to prevent clients from accessing expensive cache points.

+2
source

All Articles