Files
system-design-101/data/guides/why-do-we-need-to-use-a-distributed-lock.md
Kamran Ahmed ee4b7305a2 Adds ByteByteGo guides and links (#106)
This PR adds all the guides from [Visual
Guides](https://bytebytego.com/guides/) section on bytebytego to the
repository with proper links.

- [x] Markdown files for guides and categories are placed inside
`data/guides` and `data/categories`
- [x] Guide links in readme are auto-generated using
`scripts/readme.ts`. Everytime you run the script `npm run
update-readme`, it reads the categories and guides from the above
mentioned folders, generate production links for guides and categories
and populate the table of content in the readme. This ensures that any
future guides and categories will automatically get added to the readme.
- [x] Sorting inside the readme matches the actual category and guides
sorting on production
2025-03-31 22:16:44 -07:00

1.7 KiB

title, description, image, createdAt, draft, categories, tags
title description image createdAt draft categories tags
Why Use a Distributed Lock? Explore the top use cases for distributed locks in distributed systems. https://assets.bytebytego.com/diagrams/0383-top-6-use-cases-of-distributed-lock.png 2024-02-25 false
cloud-distributed-systems
distributed systems
concurrency

A distributed lock is a mechanism that ensures mutual exclusion across a distributed system.

Top 6 Use Cases for Distributed Locks

  • Leader Election

    Distributed locks can be used to ensure that only one node becomes the leader at any given time.

  • Task Scheduling

    In a distributed task scheduler, distributed locks ensure that a scheduled task is executed by only one worker node, preventing duplicate execution.

  • Resource Allocation

    When managing shared resources like file systems, network sockets, or hardware devices, distributed locks ensure that only one process can access the resource at a time.

  • Microservices Coordination

    When multiple microservices need to perform coordinated operations, such as updating related data in different databases, distributed locks ensure that these operations are performed in a controlled and orderly manner.

  • Inventory Management

    In e-commerce platforms, distributed locks can manage inventory updates to ensure that stock levels are accurately maintained when multiple users attempt to purchase the same item simultaneously.

  • Session Management

    When handling user sessions in a distributed environment, distributed locks can ensure that a user session is only modified by one server at a time, preventing inconsistencies.