mirror of
https://github.com/ByteByteGoHq/system-design-101.git
synced 2026-04-10 12:07:25 -04:00
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
43 lines
1.7 KiB
Markdown
43 lines
1.7 KiB
Markdown
---
|
|
title: "Why Use a Distributed Lock?"
|
|
description: "Explore the top use cases for distributed locks in distributed systems."
|
|
image: "https://assets.bytebytego.com/diagrams/0383-top-6-use-cases-of-distributed-lock.png"
|
|
createdAt: "2024-02-25"
|
|
draft: false
|
|
categories:
|
|
- cloud-distributed-systems
|
|
tags:
|
|
- "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.
|