Let's say you have an akka-cluster based application/REST API.
This application serves both CPU bound requests and memory bound requests.
Let's say you designed the app so that if a node joins with cpu
role, that
node will be used as a resource for the cpu bound requests (via a cluster aware router of some sort) and if a node joins with a memory
role, that node will be used as a resource for the memory bound requests (via cluster sharding with persistent actors for example).
What is required to implement autoscaling of such app? How would the cluster flag to "outside" that it requires more (or less) nodes of one type or another? I couldn't find any examples of such setups.
akka-cluster
does not "flag" to outside automatically unless you create some code for it. However, in a public cloud environments such as AWS
, the autoscaling concept works a bit differently. The regular approach is to have an alarm (external to your cluster) that monitor a metric (either CPU or memory). When the alarm triggers, you can do actions. One action can be launch a new instance of the required role (CPU or Memory).
Same kind of scenario would happen when you need to scale down, however you need to be careful of the in-flight workload you have running in the node you are about to shutdown.
Another important aspect is the service discovery when a new node comes up and wants to join the cluster, for that I would recommend using the module akka-management
: https://github.com/akka/akka-management
Long story short, akka-cluster
does not provide tools to autoscale automatically, you need to write some code or use some tooling around your cluster to achieve it.