chris-menz

chris-menz

How to design a Phoenix application to leverage scaling features

I’m trying to plan my application structure and was wondering if someone who knows a bit more about how elixir works under the hood could give me advice on which of my two ideas are more scalable for the least amount of complexity. I am a beginner with Elixir and Phoenix and have really been enjoying it and want to learn more. I want to jump into a full project with it that I have been planning for a while

One thing I have learned about web sockets in other languages is that they have to be scaled in a different way that a simple crud api, so it might make sense to separate them into different services.

There’s three capabilities my backend needs to run. CRUD/HTTP Rest api, scheduled background task (fetching from external data source and writing to db multiple times an hour for about 15 hours every single day), and a real-time chat.

In the future, my application will need to fetch and serve live stream video that runs all the time during the day but won’t run at night.

With other tooling it would make sense to separate these into different services for scaling purposes. Do tools like Oban background jobs and Phoenix Channels solve this scaling issue under the hood? Or would a micro services design still provide scaling benefits?

Most example projects I see are mono repos. I am leaning toward this as it will make modeling relations across services much easier to manage. I’m more just interested in learning how things like Supervisor work. Is what the problem I described the use case for Supervisor / the actor model, or am I totally off base here?

Would love if anyone could point me to some resources on more advanced Phoenix/Elixir topics.

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

For a newcomer, I think you have a very solid grasp of how to get going. From a raw users standpoint I don’t think you’ll run into any streaming issues at all. Keep in mind the whole elixir package management system ran for a very long time on a single 512mb server. Your ECS + Docker idea sounds like a fine idea, but you could probably get away with simpler depending on whether ECS is something you are familiar with or not.

Live streaming and video work however is an area I know less about, so perhaps someone else can weigh in on that. I’m going to add a membrane tag to the post to see if we can help.

From a code management / maintenance standpoint I definitely think you have the right idea with a phoenix mono repo.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @chris-menz welcome! This is a potentially very large topic, but let me kick it off by providing some answers that I think reflect community norms, lay out the assumptions underlying those norms, and then you can see what may be different in your case.

Simple answers: A single Elixir application that has Phoenix for UI / chat / REST API, Oban for background jobs and postgres as your database would be the recommend place to start.

So, you haven’t actually talked about any scale, so it’s hard to say. But what can be said is that efficient use of Postgres, fronted by Phoenix, will easiliy scale to tends or even hundreds of thousands of concurrent users on a single server.

I would make a choice about separate services depending more on your team and the size of the team than the technologies. If you have just 1 small team, starting with separate services is likely to introduce a lot of complexity, because the boundaries between those services is unlikely to be very clear at the start, and the cost of refactoring is much higher. Deployment becomes significantly more complicated as well.

The way you are framing this is good. Building this to be the scale of youtube at the start is going to be super complex, and you can cross that bridge when you come to it. At the start simplicity is very important so that you can iterate quickly, and you just want to make sure the scaling will be good enough that it won’t cause issues prematurely. A traditional Phoenix app is pretty well tuned to give you what you want here.

To provide anything more concrete though you’d need to be more concrete about what you expect the application to need to do.

dimitarvp

dimitarvp

Then you can follow Phoenix’s tutorials and you’re already covered. A brand new app with zero optimizations and no caching will handle even 10k concurrent users just fine.

Though depending on database usage I’d tune some of your Ecto.Repo parameters e.g. queue_target can be a higher value (say 5000ms) so nobody gets the “request timed out” page even in loaded conditions.

And that still wouldn’t be on Elixir, it’d be your DB being the bottleneck.

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
jaysoifer
Is there a way to rollback a specific migration and only that one ("skipping" all the other ones)? Would mix ecto.rollback -v 2008090...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
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
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39247 209
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35953 110
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I'm a nov...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement