Brieuc

Brieuc

Infrastructure for a multi-tenancy Phoenix LiveView app

Hi!

I’m new here, happy to be part of the elixir community!

I have a few questions regarding infrastructure for a multi-tenancy Phoenix LiveView app.

But first here some context:

We’re building a ERP for a niche industry of 100+ customers, each customer can have from 5 to 100+ employees. Each customer will have a subdomain (e.g. {tenantName}.erpproject.com) and database (or schema).
It needs to be highly available and scalable, hence the choice of going with Elixir/Phoenix (even though I’m the only tech guy at the moment and I only started to learn Elixir, Phoenix and LiveView a few month ago, but I’m loving it btw).
I’m a full-stack developer, but mostly went frontend (vue, flutter, etc.) in the last few years. Not really an expert at cloud architecture or devops.

  • what is the benefit of running a Phoenix release on a DO (Digital Ocean) app vs running the server with mix on a droplet? I understand the that a release is precompile into a single unit and the benefit of it. But would running the server on a DO droplet would give me more control (in case of issues, debugging, etc.)?
  • I’m currently building the multi tenancy using triplex (it seems is has not been updated for quite a long time but so far so good on local). Running into a lot of issues currently to set it up on DO. But it makes me wonder if it would actually not be better to just assemble multiple releases instead and have a DO app per tenant. I’m having a hard time identifying the pro and cons with those 2 solutions beside the cost of having to pay a DO managed database and an DO app.
  • Actually I went with DO because I had some past experience with it, but given the context of the project, would another cloud solution be more appropriate? I had a look at fly.io and Gigalixir and I had an easier time setting up a dummy phoenix app with auth module on DO.

Most Liked

al2o3cr

al2o3cr

I love me some Elixir, but I need to call this out: it’s not magical scaling-sauce that will automatically solve your problems.

It’s easier to write available and scalable code on top of the BEAM, but there are still plenty of traps for the unwary that will produce flaky and/or slow code anyways. For instance:

  • using GenServers for code organization (like the docs say NOT to do) and forcing every web request to wait in line at a single process
  • misconfiguring supervision trees so that a part of the application that crashes stays crashed until the server is rebooted

Regarding multitenancy, I’d recommend unpacking your requirements in more detail before picking a solution. Some things to think about:

  • are the schemas for different customers intended to diverge? If they aren’t, how is your company going to deal with BigCo who needs “just a little customization to close the sale”? Picking a solution that doesn’t match this expectation will lead to a rough time in the future.

  • what are the different customers’ service-level expectations? Is your company going to be fine with telling BigCo #2 that the site is down because BigCo #1 sent too many requests? If not, you’ll need to pick a solution that can isolate failures and/or runaway resource consumption.

  • are your customers big enough to expect an on-premises option? You don’t have to have an already-writen solution for this, but different multitenancy approaches will make this more painful than others so it’s worth considering early.

10
Post #9
hlx

hlx

Not sure if you read the docs below already but my advise would be to skip libraries like triplex and just handle it yourself.

That said, if you are relatively new to Elixir and multi-tenancy, I would suggest you take a look at the last link, the foreign keys option. This option is the simplest which also means easier to scale.

krasenyp

krasenyp

Another thing which hasn’t been said in the thread already - Phoenix is NOT your application. You might be building a Rails or a Django app but in Elixir Phoenix is just the interface to your business logic. You might want to take a look at the book Designing Elixir Systems with OTP: Write Highly Scalable, Self-Healing Software with Layers by James Edward Gray, II and Bruce A. Tate.

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
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 43622 214
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New

We're in Beta

About us Mission Statement