When considering your Gigalixir replicas, the question often comes up whether you should scale up the number of the replicas, or the size of the replicas, so that your apps don’t OOMKilled in the middle of an important client presentation.
If your application is not under any particular load most of the time (for example, handling lots of requests), then if you have issues, it is because you likely hit a portion of your application where it needed more memory than you have provided for it.
If however, you are able to handle requests without a lot of load, but then you get issues when you have lots of traffic, you would want to consider scaling horizontally (i.e. adding more replicas).
The other guidance we recommend is to run at least two replicas for the redundancy.
If one of your replicas get’s killed for any reason, at least you will still handle requests.
Obviously, however, if you are hitting a memory issue, multiple replicas could still crash.
Why Multiple Replicas Before I Need Them?
Some people don’t add multiple replicas early enough and then when it’s needed, their app wasn’t developed with multiple replicas in mind and it takes longer to get there.
As your app grows, it can be a problem if you didn’t account for any sort of shared resources (database, memorystore, caching, CDN, etc) to be able to handle multiple replicas.
Libcluster is useful if you plan to have state (such as Process or GenServer state) cross replicas in Elixir, but not necessary if you are serving one off (stateless) requests.