<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/erlang-solutions-implementing-a-phoenix-pubsub-adapter-with-eventstore--82cqqerek" -->

---
title: Erlang Solutions Implementing a Phoenix PubSub Adapter...
description: A walkthrough demonstrates building a custom Phoenix PubSub adapter backed by EventStore instead of the default PG2 or Redis adapters. The approach lets nodes...
canonical: https://daily.dev/posts/erlang-solutions-implementing-a-phoenix-pubsub-adapter-with-eventstore--82cqqerek
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Erlang Solutions Implementing a Phoenix PubSub Adapter with EventStore % | daily.dev
og:description: A walkthrough demonstrates building a custom Phoenix PubSub adapter backed by EventStore instead of the default PG2 or Redis adapters. The approach lets nodes...
og:url: https://daily.dev/posts/erlang-solutions-implementing-a-phoenix-pubsub-adapter-with-eventstore--82cqqerek
og:image: https://api.daily.dev/og/posts/82cQqEreK.png
og:image:alt: Erlang Solutions Implementing a Phoenix PubSub Adapter with EventStore %
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Erlang Solutions Implementing a Phoenix PubSub Adapter with EventStore %

**[Erlang Solutions](https://daily.dev/sources/erlangsolutions)** · 7 min read · 0 upvotes · 0 comments

## Summary

A walkthrough demonstrates building a custom Phoenix PubSub adapter backed by EventStore instead of the default PG2 or Redis adapters. The approach lets nodes communicate through a shared PostgreSQL-backed event log rather than requiring Erlang distribution configuration, with the added benefit that every broadcast is persisted and replayable. The tradeoffs are storage overhead and per-broadcast database latency, making it suited for lower-throughput, persistence-sensitive messaging rather than high-speed use cases. The post covers implementing the required Adapter callbacks (broadcast, direct_broadcast, node_name), pluggable serialization (defaulting to base64-encoded Erlang term serialization to preserve type fidelity through EventStore's JSON storage), duplicate-delivery avoidance via unique node IDs, and routing direct broadcasts using a destination_node metadata field. Full source is available on GitHub as a proof of concept with no load testing performed.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.erlang-solutions.com/blog/how-to-write-a-phoenix-pubsub-adapter-tutorial-example-based-on-eventstore>

## Questions this post answers

### How can I implement a custom Phoenix PubSub adapter that doesn't rely on Erlang distribution?

Build a GenServer-based adapter implementing the Phoenix.PubSub.Adapter callbacks (node_name, broadcast/4, direct_broadcast/5) that appends messages as events to an EventStore stream instead of routing through the Erlang cluster. Nodes subscribe to the EventStore's "$all" stream and receive broadcasts through the shared PostgreSQL-backed event log, avoiding Erlang node connectivity configuration entirely.

_Explore daily.dev for more Elixir and Phoenix architecture patterns when weighing pubsub backend tradeoffs._

### Why does a custom Phoenix PubSub EventStore adapter base64-encode messages with erlang term_to_binary instead of storing them as plain JSON?

EventStore persists event data as JSON, and raw Erlang binaries would be invalid JSON, so messages first go through erlang:term_to_binary/1 and then base64 encoding. This round-trip through term serialization also preserves type fidelity, since JSON cannot distinguish atoms from strings the way Erlang terms can.

_Developers debugging serialization edge cases in Elixir messaging often compare approaches like this on daily.dev._

### How do you avoid double-delivering a broadcast message when using EventStore as a Phoenix PubSub backend?

Each adapter instance generates a unique ID at startup (via UUID by default, or a custom unique_id_fn) and stores it as source_id in the event metadata when broadcasting. When the event arrives back after being read from the subscription, the adapter compares the incoming source_id to its own id and skips local dispatch if they match, since that node already delivered the message locally when it called broadcast.

_Teams building resilient distributed messaging in Elixir track patterns like this on daily.dev._

## Similar posts on daily.dev

- [Code BEAM America 2025 - Learning Resources / Talks - Elixir Programming Language Forum](https://daily.dev/posts/code-beam-america-2025---learning-resources-talks---elixir-programming-language-forum-bagwzmtsq) · Elixir Forum · 0 upvotes · 0 comments
- [Build an Elixir App with Cowboy](https://daily.dev/posts/build-an-elixir-app-with-cowboy-cbg2oram6) · AppSignal · 3 upvotes · 0 comments
- [Exploring Distributed Elixir](https://daily.dev/posts/exploring-distributed-elixir-iyxsm4dkt) · ElixirStatus · 0 upvotes · 0 comments
- [How to Implement the Outbox Pattern in Go and PostgreSQL](https://daily.dev/posts/how-to-implement-the-outbox-pattern-in-go-and-postgresql-ygygbpymj) · freeCodeCamp · 9 upvotes · 0 comments
- [Listen to Database Changes through the Postgres WAL](https://daily.dev/posts/listen-to-database-changes-through-the-postgres-wal-4frkdnjmn) · Hacker News · 0 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#elixir](https://daily.dev/tags/elixir), [#distributed-systems](https://daily.dev/tags/distributed-systems)

[View this post on daily.dev](https://daily.dev/posts/erlang-solutions-implementing-a-phoenix-pubsub-adapter-with-eventstore--82cqqerek)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Erlang Solutions Implementing a Phoenix PubSub Adapter with EventStore %","url":"https://daily.dev/posts/erlang-solutions-implementing-a-phoenix-pubsub-adapter-with-eventstore--82cqqerek","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/erlang-solutions-implementing-a-phoenix-pubsub-adapter-with-eventstore--82cqqerek"},"datePublished":"2026-09-10T09:31:32.430Z","dateModified":"2026-09-10T09:32:03.200Z","description":"A walkthrough demonstrates building a custom Phoenix PubSub adapter backed by EventStore instead of the default PG2 or Redis adapters. The approach lets nodes...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/3100011da228d80fb5df3897fd238ee9?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/3100011da228d80fb5df3897fd238ee9?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Erlang Solutions","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Erlang Solutions","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/85a0fd34894e4a3d9b83d60d74572a48","url":"https://daily.dev/sources/erlangsolutions"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/erlang-solutions-implementing-a-phoenix-pubsub-adapter-with-eventstore--82cqqerek","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"architecture,elixir,distributed-systems","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Erlang Solutions","item":"https://daily.dev/sources/erlangsolutions"},{"@type":"ListItem","position":3,"name":"Erlang Solutions Implementing a Phoenix PubSub Adapter with EventStore %"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/erlang-solutions-implementing-a-phoenix-pubsub-adapter-with-eventstore--82cqqerek#faq","mainEntity":[{"@type":"Question","name":"How can I implement a custom Phoenix PubSub adapter that doesn't rely on Erlang distribution?","acceptedAnswer":{"@type":"Answer","text":"Build a GenServer-based adapter implementing the Phoenix.PubSub.Adapter callbacks (node_name, broadcast/4, direct_broadcast/5) that appends messages as events to an EventStore stream instead of routing through the Erlang cluster. Nodes subscribe to the EventStore's \"$all\" stream and receive broadcasts through the shared PostgreSQL-backed event log, avoiding Erlang node connectivity configuration entirely. Explore daily.dev for more Elixir and Phoenix architecture patterns when weighing pubsub backend tradeoffs."}},{"@type":"Question","name":"Why does a custom Phoenix PubSub EventStore adapter base64-encode messages with erlang term_to_binary instead of storing them as plain JSON?","acceptedAnswer":{"@type":"Answer","text":"EventStore persists event data as JSON, and raw Erlang binaries would be invalid JSON, so messages first go through erlang:term_to_binary/1 and then base64 encoding. This round-trip through term serialization also preserves type fidelity, since JSON cannot distinguish atoms from strings the way Erlang terms can. Developers debugging serialization edge cases in Elixir messaging often compare approaches like this on daily.dev."}},{"@type":"Question","name":"How do you avoid double-delivering a broadcast message when using EventStore as a Phoenix PubSub backend?","acceptedAnswer":{"@type":"Answer","text":"Each adapter instance generates a unique ID at startup (via UUID by default, or a custom unique_id_fn) and stores it as source_id in the event metadata when broadcasting. When the event arrives back after being read from the subscription, the adapter compares the incoming source_id to its own id and skips local dispatch if they match, since that node already delivered the message locally when it called broadcast. Teams building resilient distributed messaging in Elixir track patterns like this on daily.dev."}}]}
```

