# Variable Workloads and Elastic Elixir Deployments

**URL:** <https://forum.elixirforum.com/t/variable-workloads-and-elastic-elixir-deployments/14968>\
**Category:** Questions\
**Tags:** scaling, deployment\
**Created:** [July 2, 2018, 6:38pm UTC](https://forum.elixirforum.com/t/variable-workloads-and-elastic-elixir-deployments/14968 "2018-07-02T18:38:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben-pr-p](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ben-pr-p/32/6504_2.png) [@ben-pr-p](https://forum.elixirforum.com/u/ben-pr-p)\
**Post date:** [July 2, 2018, 6:38pm UTC](https://forum.elixirforum.com/t/variable-workloads-and-elastic-elixir-deployments/14968/1 "2018-07-02T18:38:02Z")

</div>

Hey all –

I have an application with predictably variable workloads. Hundreds of thousands of requests each evening, and no activity from after midnight through around 2PM.

To make matters worse, the application is stateful – making extensive use of GenServers, and it uses WebSockets.

Right now I’m paying for the full resources required to scale all day – however, I know that if this were a stateless service that didn’t need sockets (basically if it were structured the way I would have structured it if it were a NodeJS app), I could put it behind a dynamic load balancer or use a service like Google App Engine for auto-scaling, or use Lambda/GCloud Functions/Azure functions.

What is the best thing to do in this circumstance for an Elixir app?

---

<div class="post-metadata">

**Author:** ![wmnnd](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wmnnd/32/4985_2.png) [@wmnnd](https://forum.elixirforum.com/u/wmnnd)\
**Post date:** [July 2, 2018, 10:26pm UTC](https://forum.elixirforum.com/t/variable-workloads-and-elastic-elixir-deployments/14968/2 "2018-07-02T22:26:56Z")

</div>

If you don’t want to refactor your application to remove some of the statefulness, you could make use of Elixir’s distribution featues.  
If your application can handle keeping the Websockets alive with fewer resources, you could spin up a second node with more resources and make them take care of the requests.

---

<div class="post-metadata">

**Author:** ![ben-pr-p](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ben-pr-p/32/6504_2.png) [@ben-pr-p](https://forum.elixirforum.com/u/ben-pr-p)\
**Post date:** [July 4, 2018, 2:52am UTC](https://forum.elixirforum.com/t/variable-workloads-and-elastic-elixir-deployments/14968/3 "2018-07-04T02:52:39Z")

</div>

Yeah, the application is already running on multiple distributed nodes – I’m wondering what type of service and/or library would enable me to dynamically add and remove nodes in response to increases in traffic.

---

<div class="post-metadata">

**Author:** ![idi527](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/i/85e7bf/32.png) [@idi527](https://forum.elixirforum.com/u/idi527)\
**Post date:** [July 4, 2018, 5:40am UTC](https://forum.elixirforum.com/t/variable-workloads-and-elastic-elixir-deployments/14968/4 "2018-07-04T05:40:46Z")

</div>

I played with an idea of doing it from within the applications using the provider’s API to create / delete virtual machines. I didn’t really encounter any major problems with it, so maybe you could do something similar.

When some metric (resource utilization or users online count per node) goes above some threshold, send an API request to your provider to spin up an additional vm, and when that same metric goes below, do the opposite – destroy one of the nodes.

Since that scaling logic (thresholds) is written in an actual programming language, it provides enough flexibility to do almost whatever you want …

---

<div class="post-metadata">

**Author:** ![wmnnd](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wmnnd/32/4985_2.png) [@wmnnd](https://forum.elixirforum.com/u/wmnnd)\
**Post date:** [July 4, 2018, 9:12am UTC](https://forum.elixirforum.com/t/variable-workloads-and-elastic-elixir-deployments/14968/5 "2018-07-04T09:12:47Z")

</div>

> [@idi527](#):
>
> I played with an idea of doing it from within the applications using the provider’s API to create / delete virtual machines.

This is what I would have suggested as well. There are clients for all kinds of cloud services that allow you to spin up additional instances. Take a look here: [GitHub - h4cc/awesome-elixir: A curated list of amazingly awesome Elixir and Erlang libraries, resources and shiny things. Updates: · GitHub](https://github.com/h4cc/awesome-elixir#cloud-infrastructure-and-management)
