# Leader Election With S3 Conditional Writes

DevFeed: [Leader Election With S3 Conditional Writes](<https://devfeed.tech/articles/leader-election-with-s3-conditional-writes-18847.md>)

Original publisher: [Read original article](<https://www.morling.dev/blog/leader-election-with-s3-conditional-writes/>)

Published: 2024-08-26T08:15:00Z

Content type: tutorial

Language: en

Sources: [Gunnar Morling](<https://devfeed.tech/sources/gunnar-morling.md>)

Topics: [Amazon S3](<https://devfeed.tech/topics/amazon-s3.md>), [distributed-systems](<https://devfeed.tech/topics/distributed-systems.md>), [Kafka](<https://devfeed.tech/topics/kafka.md>), [API](<https://devfeed.tech/topics/api.md>), [Filesystems](<https://devfeed.tech/topics/filesystems.md>), [JSON](<https://devfeed.tech/topics/json.md>)

Tags: [amazon-s3](<https://devfeed.tech/tags/amazon-s3.md>), [aws](<https://devfeed.tech/tags/aws.md>), [data](<https://devfeed.tech/tags/data.md>), [distributed](<https://devfeed.tech/tags/distributed.md>), [distributed-systems](<https://devfeed.tech/tags/distributed-systems.md>), [json](<https://devfeed.tech/tags/json.md>), [kafka](<https://devfeed.tech/tags/kafka.md>), [locking](<https://devfeed.tech/tags/locking.md>), [locks](<https://devfeed.tech/tags/locks.md>), [object-storage](<https://devfeed.tech/tags/object-storage.md>), [s3](<https://devfeed.tech/tags/s3.md>)

## AI overview

This article explains how to implement leader election for distributed workloads using Amazon S3 conditional writes. Nodes compete to create a lock file, and a new file is used for each leadership epoch because conditional writes do not prevent lost updates to existing files.

## Source excerpt

Table of Contents The Algorithm Obtaining the Lock Expiring a Lock Lock Validity Fencing Off Zombies In distributed systems, for instance when scaling out some workload to multiple compute nodes, it is a common requirement to select a leader for performing a given task: only one of the nodes should process the records from a Kafka topic partition, write to a file system, call a remote API, etc. Otherwise, multiple workers may end up doing the same task twice, overwriting each other's data, and worse.