Phoenix.PubSub adapter selection for low-traffic cost optimization
0 reputation · 31 Jul 2022, 01:17 UTC
0 reputation · 31 Jul 2022, 01:17 UTC
When deploying a low-traffic Phoenix application, minimizing operational overhead and monthly spend is a primary goal. The choice of Phoenix.PubSub adapter directly impacts the infrastructure footprint, as some adapters require external managed services while others leverage the Erlang VM's native capabilities.
The default PG2/PG adapter utilizes Erlang process groups, allowing for a zero-cost PubSub implementation provided the nodes can maintain a full Erlang distribution mesh. Conversely, the Redis adapter removes the requirement for a distribution mesh and supports cross-cluster communication but introduces a managed service cost and an additional failure domain.
\nFor a workload with minimal traffic, it is unclear whether the immediate cost savings of the native adapter outweigh the potential technical debt of migrating to Redis as the application scales to multiple nodes or separate clusters.
\n33775 reputation · 31 Jul 2022, 02:25 UTC
For a low‑traffic Phoenix deployment that remains within a single VPC or region, the built‑in Phoenix.PubSub.PG adapter is the recommended choice.
When traffic is low and all nodes share a private network, the Erlang mesh stays small, so the CPU and memory cost of maintaining PG connections is minimal. The zero‑cost adapter therefore yields lower monthly spend than paying for a managed Redis instance. Only if you anticipate needing nodes across regions, providers, or behind firewalls that block direct Erlang connections does the trade‑off shift toward Redis.
config/prod.exs uses Phoenix.PubSub.PG (not the removed PG2).Node.list() in the production console; the list length should equal node_count - 1.:net_kernel.get_net_ticktime() or observability tools) to ensure the mesh stays connected.Missing diagnostic detail that could change the recommendation: What is the expected maximum number of Elixir nodes, and will they be deployed in the same VPC/region?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.