What is barrel_p2p?

View Source

Barrel P2P is a peer-to-peer distribution layer for Erlang/OTP. It replaces the default TCP-based Erlang distribution with three opinionated pieces, while keeping Pid ! Msg, gen_server, rpc:call/4, and global working exactly as you expect.

The three pieces are:

  • A bounded membership protocol (HyParView). Each node keeps a small, bounded set of gossip peers. The cluster as a whole remains fully addressable: any node can reach any other node on demand, through OTP's auto-connect.
  • A secure transport (QUIC + Ed25519). One QUIC connection per peer carries the dist channel; an Ed25519 mutual handshake proves identity before any Erlang traffic flows. Connection migration moves the session to a new local network path without dropping streams.
  • A service registry (CRDT-backed). Processes register under a name; the name is replicated through the cluster and lookups return either a local pid or the remote node + pid. No external service-discovery service is required.

Visually, this is the shape of a barrel_p2p cluster from one node's point of view:

HyParView active view: a node connects to a small set of gossip peers, with additional known peers held in a passive cache.

Each node holds a small active view (its current gossip peers, typically five) and a larger passive view (known but disconnected peers used as warm spares). The cluster topology scales: a node with a thousand peers in its passive view still keeps only five active links.

What you get out of the box

CapabilityWhat it gives youWhere to read more
-proto_dist barrel_p2p boot flagDrop-in replacement for the default distDist channel concept
HyParView membershipBounded connection count, gossip-based reachabilityCluster membership concept
Ed25519 mutual authTOFU or strict per-peer key pinningAuthentication concept
CRDT service registryCluster-wide named services with eventual consistencyService registry concept
Replicated mapsGossiped key-value state for config, flags, routing tablesReplicated maps concept
Plumtree gossipEfficient broadcast for service-state updatesGossip broadcast concept
Tagged user streamsApp-level multiplex over the same QUIC connectionStreams concept
Connection migrationRFC 9000 ยง9 path rebind without restartMigration concept
instrument metricsOpenTelemetry-style counters and histogramsObserve a cluster

What barrel_p2p does not do

A few things are explicitly not part of the project:

  • NAT traversal, STUN, UPnP, hole punching. Nodes are expected to reach each other directly. If they cannot, an external relay is wired through the connect-time override hook (route through a relay).
  • Topologies other than HyParView. There is no full-mesh, no client-server, no hub-and-spoke mode. If you need topology flexibility, Partisan is the right library.
  • A standalone HTTP metrics server. The instrument library provides formatters; you wire them into your existing HTTP layer.

When to use barrel_p2p

Barrel P2P is a good fit when:

  • You want a partial-membership topology to replace Erlang's full mesh, without giving up Pid ! Msg.
  • You need cluster-wide service discovery without standing up a separate registry (Consul, etcd).
  • You want encryption between peers by default, with no certificate authority to operate.
  • You prefer opinionated defaults to a wide configuration surface.

Barrel P2P is the wrong fit when:

  • You need multiple topology backends.
  • You need explicit message channels with per-channel parallelism.
  • You are building research on distributed protocols.

For each of those, Partisan is the better library.

Next

  • Benefits lists the trade-offs in more detail.
  • Introduction is the longer narrative, ideal if you want to understand why each piece is shaped the way it is before reading the per-concept pages.
  • Getting started gets a two-node cluster running.