Skip to main content

A distributed leader election python package using postgresql notify.

Project description

Notifelect: Robust Leader Election for Distributed Systems Using PostgreSQL NOTIFY

Notifelect is a Python package designed for seamless leader election in distributed systems. It utilizes the NOTIFY feature of PostgreSQL to manage elections, offering a robust and reliable solution for systems requiring fault tolerance and consistency across nodes. Leveraging the Bully algorithm, Notifelect ensures dynamic leader selection with minimal configuration.

Why Notifelect?

  • Efficient Leader Elections: Utilizes PostgreSQL's NOTIFY and sequences for efficient and accurate leader determination.
  • Asynchronous Operations: Built with asyncio, allowing for non-blocking, event-driven communication.
  • Easy to Integrate: Simple API that fits naturally into existing Python applications.

Enhance your distributed systems with Notifelect’s efficient leader election mechanism for improved reliability and performance.

Getting Started

Installation is straightforward using pip:

pip install notifelect
python -m notifelect install  # Set up necessary database sequences

Quick Example

Simulate a leader election among N processes:

import asyncio
import contextlib
import random
import sys
from typing import AsyncGenerator

import asyncpg
from notifelect import election_manager

@contextlib.asynccontextmanager
async def connection() -> AsyncGenerator[asyncpg.Connection, None]:
    conn = await asyncpg.connect()
    try:
        yield conn
    finally:
        await conn.close()

async def process() -> None:
    await asyncio.sleep(random.random() * 2)
    async with connection() as conn, election_manager.Coordinator(conn):
        await asyncio.sleep(float('inf'))

async def main() -> None:
    N = int(sys.argv[1])
    processes = [process() for _ in range(N)]
    await asyncio.gather(*processes)

if __name__ == "__main__":
    asyncio.run(main())

Enhancements

  • Clear Value Proposition: Begins with why Notifelect is beneficial and its specific features.
  • Streamlined Setup and Example: Simplified instructions and example for easier comprehension and quicker start.
  • Engaging Introduction: More direct and impactful opening to grab attention immediately.

These changes are intended to make the README not only more attractive but also more user-friendly, encouraging community use and contributions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notifelect-0.0.3.tar.gz (14.8 kB view hashes)

Uploaded Source

Built Distribution

notifelect-0.0.3-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page