Pistrie

Pistrie

How would you scale up an Elixir/Phoenix application if only a specific part is responsible for that requirement?

Hi everyone, I’ve got a question related to project architecture.

In the microservice sphere there is this concept where you can scale up individual services when needed. So imagine the following scenario:

     ┌────────────────────┐
     │RabbitMQ Message Bus│
     └────────────────────┘
       ▲            ▲
       │            │
 ┌─────┴───┐    ┌───┴──────────┐
 │Webserver│    │Expensive jobs│
 └─────────┘    └──────────────┘

The precise job doesn’t really matter, but let’s assume that we’re processing and/or modifying images or something.
The ‘expensive jobs’ box retrieves jobs from RabbitMQ and returns the result.
Let’s say that the expensive jobs get popular with our users, so we want to add another box that retrieves jobs from RabbitMQ.

     ┌────────────────────┐
     │RabbitMQ Message Bus│
     └────────────────────┘
       ▲            ▲   ▲
       │            │   └──────────┐
       │            │              │
 ┌─────┴───┐    ┌───┴──────────┐ ┌─┴────────────┐
 │Webserver│    │Expensive jobs│ │Expensive jobs│
 └─────────┘    └──────────────┘ └──────────────┘

We’ve now effectively doubled our capacity for handling these expensive jobs.

My question is as follows: how would you achieve something similar in an Elixir (Phoenix) monolith? We can use Oban to perform background jobs, but what if the amount of jobs becomes sufficiently large that the queue reaches its limit. We could theoretically scale up the entire server, but that doesn’t feel correct for some reason.

Most Liked

LostKobrakai

LostKobrakai

I’d argue at that scale the difference between a monolith and microservices becomes muddy. Because the remaining difference will just be “code organization” when you start to scale out a system (especially heterogenously).

Afaik both Oban Pro as well as the recently introduced FLAME library/pattern can help with adding more nodes (horizonal scaling) over adding more power to the current one.

dimitarvp

dimitarvp

The BEAM VM has work-stealing schedulers (among other goodies) so bumping up a single server’s specs will naturally lead to increase of capacity in processing the expensive jobs, because they’re the ones demanding more resources, and the runtime will give it to them.

Delay scaling out as if your life depends on it. New and extremely annoying problems await you there.

tj0

tj0

You could deploy a monolith 100 times and set aside 90 of those for jobs if you wanted. Don’t be bothered with whether there is one service deployed and running or many on a container / vm. There is a time for that, but not worth it early. Colocating services / data also is important if latency is there when scaling.

Scaling up is much easier than scaling out. Agreed with everyone else in the thread so far. You don’t want to be paying for giant machines to be idle 99% of the time though.

My preference would be deploy the monolith n-times and separate the usage / clustering. FLAME looks interesting also, but never tried it.

derek-zhou

derek-zhou

Why? The expensive jobs will take a bigger slice of all the available resource. I don’t see anything got wasted. If you can get away with scale up, why scale out?

Where Next?

Popular in Questions Top

pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New

We're in Beta

About us Mission Statement