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
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
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
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.







