Elixir clustering using Postgres
Elixir nodes can discover each other for distributed Erlang clustering through Postgres LISTEN/NOTIFY, which avoids a cloud-specific discovery service. The libcluster Postgres strategy has each node NOTIFY a configured channel with its node() name. Each node listens for notifications via Postgrex.Notifications and connects to any node it hears about. A periodic heartbeat re-broadcasts the node name so libcluster can heal the cluster. Supabase uses this in Logflare, Supavisor and Realtime and has open-sourced it as libcluster_postgres.
Related posts
- Supavisor 1.0: a scalable connection pooler for Postgres
Supabase mediumAdeptSupavisor 1.0, Supabase's Elixir-based Postgres connection pooler, is production-ready and adds query load balancing, named prepared statement support in transaction mode, and query cancelation. All SQL is now parsed via pg_query.rs through Rustler. Reads are randomly spread across primary and replicas, while writes find the primary by probing until a write succeeds, which adds a few milliseconds but makes failover transparent. PREPARE statements are broadcast to all backend connections, trading some memory for throughput. The release also raises default client limits for smaller projects and uses IPv4-to-IPv6 mediation to avoid AWS IPv4 charges.
- Realtime: Multiplayer Edition
Supabase mediumAdeptSupabase Realtime's Broadcast and Presence features are now generally available, with every feature organized around Channels that also carry Postgres change events. Broadcast is ephemeral pub/sub that bypasses the database, which suits things like cursor positions. Presence syncs shared state to new joiners and drops users automatically when they disconnect. Realtime originally chose logical replication over LISTEN/NOTIFY because NOTIFY payloads are capped at 8,000 bytes. It now runs as a globally distributed Elixir cluster on Fly, using Phoenix PubSub for Broadcast and the delta-CRDT-based Phoenix Tracker for Presence, and supabase-js examples show both features in use.
- How We Export Postgres Logs to Third-Party Services
Neon mediumAdept
Neon exports customer Postgres logs by having Postgres write to rsyslogd alongside stderr, with rsyslogd pushing RFC 5424 syslog over TCP to an OpenTelemetry Collector that enriches and forwards them to Datadog or any OTLP-compatible platform. Scraping pods by label wasn't supported by the OTel Collector, and unstructured logs from multiple NeonVM processes made filtering unreliable, so they switched from pull to push. Roadblocks included rsyslogd requiring a restart rather than a config reload, and a k8sattributes bug fixed by a transform step that copies net.peer.ip into k8s.pod.ip for pod matching. The same rsyslogd instance also ships pg_audit logs to secure storage for HIPAA customers.
- Supavisor: Scaling Postgres to 1 Million Connections
Supabase mediumAdeptSupavisor is a multi-tenant Postgres connection pooler written in Elixir that Supabase built to replace single-threaded PgBouncer. In benchmarks one 16-core instance held 250,000 client connections over a 400-connection database pool, and a 64-core instance held 500,000. Two 64-core nodes, one connected to the database and one relaying through it, held 1,003,200 connections at 20,000 QPS. Median query latency was under 2ms at 5,000 QPS, but running the pooler as a separate cluster adds about 2ms per query compared with co-located PgBouncer, in exchange for not consuming the database server's CPU and RAM.
- Postgres Meets Analytics: CDC From Neon to ClickHouse Via PeerDB
Neon mediumAdept
Neon serverless Postgres can serve as the transactional system of record while ClickHouse handles real-time analytics, with PeerDB streaming changes between them via Postgres logical replication. Setup involves creating a replication-capable user and a publication in Neon, enabling logical replication (wal_level=logical), creating a destination database and a user with insert/alter grants in ClickHouse, then defining peers and a CDC mirror in PeerDB with an initial snapshot and table selection. PeerDB, now owned by ClickHouse, is slated to power the Postgres CDC connector in ClickPipes.