Clarification on how PG2 Works?

Hi there,

Been looking at options for some smaller apps I wanted to build and I figured learning Elixir/Phoenix would be a good time for them. They aren’t huge things to start but I’d like to start with the ability to scale in the event one or both get popular. My question is though, I’m looking at using the LiveView stuff provided by Phoenix, but I don’t quite understand how PG2 works in a multi-machine scaling environment. All the examples I’ve found so far show needing to know the IP addresses of at least one other server already in the pool, which makes sense to me looking at the underlying methodology. My main question is how do people solve the scenario of scaling across multiple machines where they are spun up and down on demand and IP addresses change each time? Is this just where people move to the Redis adapter?

Any examples or links to information on this is appreciated. I prefer the idea of having server just talk to each other rather than through a single point of failure, but if that’s how you scale horizontally then I guess that’s it.

Thanks!

I use libcluster with the DNS strategy. My kubernetes config creates a headless service for all pods in the cluster and that allows me to DNS lookup the IP addresses.

I’ve used the Redis adapter on heroku where node to node networking isn’t possible, but have always used pg2 otherwise.

2 Likes

That a cool package I hadn’t found. Good to see there are good options. It gives me an idea of how to move forward now. Thanks.