Idempotency refers to the property of an operation where performing it multiple times has the same effect as performing it once.
Key takeaways:
Leases provide a structured way to allocate resources for a limited time, ensuring efficient sharing and utilization across nodes.
By using a Consistent Core, leases help maintain consistency and enable systems to handle failures effectively.
Requestor can renew leases before expiration, allowing continued access while minimizing the risk of resource contention.
In leader-follower architecture, leases are managed by a leader, ensuring that all requests and renewals are logged and replicated for reliability.
In a distributed system, multiple nodes require access to resources, which are allocated and managed across these nodes. Allocating resources for an indefinite period of time could be chaotic as it prevents efficient sharing and utilizing of resources. These nodes can fail, temporarily disconnect due to network failure, or due to some other failure that results in resources being acquired but not utilized. If these nodes hold the resources indefinitely, other nodes will not be able to access them.
Leasing means giving permission to use a resource for a specific period of time. Once the lease has expired, the one who had the lease has no access to the resource(s) unless the lease is extended or renewed. It helps smooth the process of fault tolerance.
Leases are implemented with a
In a leader-follower architecture, where consistency is critical, a leader is elected from multiple servers through a leader election process, while the remaining servers act as followers. In this scenario, leases are replicated across both the leader and followers to ensure reliability. The leader tracks all leases on the Consistent Core using a monotonic clock and initiates tasks once a lease is granted.
Let’s delve into the intricacies of lease functionality:
We can request a lease using the following five steps:
The requestor must connect to the leader of the Consistent Core.
The requestor must request the lease.
The lease requested is logged and replicated on both the leader and followers.
The leader will check whether the requested resource is already on lease.
If the resource is already on the lease, it gives an error message to the requestor.
If the resource is not on the lease, the leader then leases the resource to the requestor.
Once the lease expires, the entry in the log is updated or deleted if necessary.
A requestor can renew a lease using the following way:
Requestor send a renewal request to the server before the lease expires. This request often includes the current lease ID and requestor identifier.
The leader checks for active modifications and assesses the requestor state for consistency.
If valid, the leader extends the lease duration, maintaining exclusive access for the requestor.
If renewal fails or is late, the leader revokes the lease, ensuring the requestor is available for others.
Leader failure is expected in a distributed system, so we’ve got to be prepared if that happens. If the leader fails, we can manage a lease using the following three steps:
The new leader is elected.
The new leader starts to track all the leases.
The new leader refreshes all the leases it knows by extending their lease time of time-to-live value.
In distributed systems, leases play a crucial role in managing resource allocation efficiently and reliably. By granting temporary permission to use resources, leases prevent conflicts and ensure that resources are utilized optimally, even in the face of potential node failures.
Elevate your system design skills!
Join "Grokking the Principles and Practices of Advanced System Design" to learn how to build scalable and reliable systems. Master key principles and tackle system design challenges with confidence.
Quiz!
What do leases help prevent in distributed systems?
Network latency
Unauthorized access
Resource conflicts
None of them
Haven’t found what you were looking for? Contact Us
Free Resources