Skip to main content

DynamoDB DCS backend for Patroni PostgreSQL HA

Project description

Dynatroni

Dynatroni (Patroni DynamoDB DCS)

Dynatroni is a DynamoDB-based Distributed Configuration Store (DCS) backend for Patroni PostgreSQL HA.

Features

  • DynamoDB as arbiter: leader election via DynamoDB atomic operations
  • No quorum requirement: a single surviving node can operate
  • AWS-native: IAM auth, managed service
  • Cost-effective: pay‑per‑request pricing for small clusters
  • Highly available: DynamoDB's built‑in multi‑AZ replication

Docs

Installation

pip install dynatroni

DynamoDB Table Setup

Create a DynamoDB table with:

  • Partition Key: cluster_name (String)
  • Sort Key: key (String)
  • TTL attribute: ttl
aws dynamodb create-table \
  --table-name patroni-dynamodb \
  --attribute-definitions \
    AttributeName=cluster_name,AttributeType=S \
    AttributeName=key,AttributeType=S \
  --key-schema \
    AttributeName=cluster_name,KeyType=HASH \
    AttributeName=key,KeyType=RANGE \
  --billing-mode PAY_PER_REQUEST

aws dynamodb update-time-to-live \
  --table-name patroni-dynamodb \
  --time-to-live-specification "Enabled=true,AttributeName=ttl"

Patroni Configuration

In your patroni.yml:

scope: my-cluster
name: node1

dynamodb:
  region: us-east-1
  table_name: patroni-dynamodb
  # Single dial for cost vs responsiveness tradeoff:
  #   15s  = fast failover, ~24 DynamoDB ops/min
  #   60s  = balanced (default), ~6 ops/min
  #   180s = cost optimized, ~2 ops/min
  failover_time: 60
  # Optional: for local testing with DynamoDB Local
  # endpoint_url: http://localhost:8000

# Timing values are derived from failover_time:
#   ttl = failover_time
#   loop_wait = failover_time / 3
#   retry_timeout = failover_time / 3

# ... rest of patroni config

IAM Permissions

The EC2 instance role needs:

{
  "Effect": "Allow",
  "Action": [
    "dynamodb:GetItem",
    "dynamodb:PutItem",
    "dynamodb:UpdateItem",
    "dynamodb:DeleteItem",
    "dynamodb:Query",
    "dynamodb:BatchWriteItem"
  ],
  "Resource": "arn:aws:dynamodb:REGION:ACCOUNT:table/patroni-dynamodb"
}

How It Works

Dynatroni uses DynamoDB as a distributed lock service for PostgreSQL leader election.

Leader Election (Atomic Operations)

All leader operations use conditional writes to ensure exactly one leader:

Operation Condition Guarantees
Acquire (new cluster) attribute_not_exists Only one node creates the lock
Renew (current leader) session = :mine Only the holder can extend
Takeover (expired TTL) ttl < :now Only one node wins the race
Release (step down) session = :mine Only the holder can release

The lock has a TTL (default 60s). If not renewed, it expires and another node can take over atomically.

Boundaries

  • Single leader guarantee: Conditional writes prevent split-brain
  • Leader lease: Bounded by TTL; leader must renew before expiry
  • Failure detection: failover_time bounds how long a dead leader blocks promotion
  • No fencing tokens: Relies on session IDs and TTL; applications should use PostgreSQL's own fencing

See docs/dynamodb.md for implementation details.

License

MIT

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

dynatroni-0.1.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynatroni-0.1.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file dynatroni-0.1.0.tar.gz.

File metadata

  • Download URL: dynatroni-0.1.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dynatroni-0.1.0.tar.gz
Algorithm Hash digest
SHA256 79fca5cd2be2bffffa92696959c49fbdf2a208d28d07d947bfb58883f9b4cc87
MD5 b60d805a17b9eefebaabd08ba4912190
BLAKE2b-256 6861cae0080aca101df7c2c006ec8ecc631c54dbbf31adb9079265da33562175

See more details on using hashes here.

Provenance

The following attestation bundles were made for dynatroni-0.1.0.tar.gz:

Publisher: publish.yml on SoftOboros/dynatroni

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dynatroni-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dynatroni-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dynatroni-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90a903a0a04f0f52bdb5a0a926476d861695cd10bf61bd60245596bdc874d866
MD5 83dcc04190feb581871a09cf1e9fd4c6
BLAKE2b-256 c311c0fae9a563a7e40c0d06194dd7eefec6da5e25ee90a586a03c2f3ea70577

See more details on using hashes here.

Provenance

The following attestation bundles were made for dynatroni-0.1.0-py3-none-any.whl:

Publisher: publish.yml on SoftOboros/dynatroni

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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