bengro

bengro

Let’s assume I have a massive frontend codebase based on the Jam-stack. The existing backend will be replaced with Phoenix to leverage real-time features such as Sockets and Presence.

How would you deploy the frontend and the backend?
Would you deploy the frontend in the Erlang VM with some sort of webserver?
Would you deploy the backend in the Erlang VM, but the frontend in a “traditional” way (e.g. nginx)?

I appreciate any links to projects or opinions/thoughts.

First 5 of 5 Posts Switch mode

vincer

vincer

I make heavy use of a similar stack and here are some solutions I’ve come across:

Backend options (option to store frontend with backend):

Gigalixir
A platform-as-a-service for Elixir. Very easy to use and I believe they have a free tier.
Their docs point to this helpful sample repo that includes assets that are compiled with Webpack. You can choose to store frontend here or not. I didn’t end up using them as I didn’t like the Python dependency.

Render.com
A sort of platform-as-a-service for all frameworks. No free tier, but the prices are reasonable. You basically just need to provide a build.sh file in your repo which handles building your app. If you wanted to store your frontend here, you would just need to add build instructions to the build.sh file. I tried their service and had no complaints, but in the end I found Kubernetes more flexible and easier for my use-case. I believe they use AWS or Google Cloud themselves.

Kubernetes on Google and Digital Ocean
This is what I use these days for all my projects (all are Vue 3 + Vite + Elixir apps). It’s the most productive recipe for me at the moment. I prefer keeping frontend and backend together as it simplifies deployment and testing. This approach is more complicated, but more flexible. I use Nginx in this setup. I maintain the details of this recipe in this repo.

Frontend options
If you want to host your frontend separately there many many options for that.

Free options
Render.com and now Digital Ocean let you host a few static frontends for free. The prices are very low even after the free tier.

Otherwise, there’s obviously Vercel, Netlify and soon Cloudflare Pages and probably a bunch of others.

Additional notes on storing frontend with backend
When storing the frontend with the backend, the Phoenix app serves the frontend content and assets. This Phoenix app may optionally also be behind something like Nginx. When storing the frontend separately with one of the providers listed above, the different services handle the serving of frontend assets for you mostly.

bengro

bengro OP

Thanks for your reply! Some really good tips and links in there.

One question that is still not clear to me is how a project structure looks like that say has an API component and a fully-fletched single page app as part of the same project.

In that sense, I’m still asking myself:

  • Would I keep two projects, Phoenix backend and Gatsby frontend, independent? I have full control over the front-end but it comes with an overhead of configuration (nginx, e2e tests become harder…)
  • Would I keep both backend and frontend together? If so how can you configure client-side routing, CDNs, and the webserver.

From a developer experience as well as a deployment point of view, what is an established pattern for developing backends and frontends?

Does this make any sense? Sorry, these must be very dumb questions :blush:

vincer

vincer

I have tried a few different structures and the one I like best is the one seen in this [folder](https://github.com/PotionApps/potionx/tree/main/packages/templates/src/project/potionx). Basically I keep all my Javascript apps in a folder called frontend in the same repository as the Elixir code and I serve the correct one based on the request’s domain or path. All requests go through the backend which routes the request to the right Javascript app. (Request → Elixir Backend → Controller → View → index.html containing the assets to a single page app)

I don’t think there is an established way of separating the two sides. At least if there is one, I haven’t found it yet. It all comes down to productivity. I’ve found that keeping the frontend apps and the backend together is the most productive for me in terms of ease of testing and speed of deployments.

In terms of configuring the client-side routing, I usually have Phoenix serve the right assets through a view like the one here. You can then use something like Cloudflare to serve the assets via CDN automatically if you’re worried about performance.

Your questions are definitely not dumb and I think many of us are still trying to find the best approach. There’s probaby no setup is going to suit everyone perfectly. I think you have to choose something that is most productive and least error-prone for you. In my case, I found managing only one project much much more productive than managing two projects.

bengro

bengro OP

Super helpful, thank you. I completely agree regarding the benefits of a “mono-project” for e2e tests and deployment.

In addition to what you’re describing, I found this article also very helpful:
https://medium.com/@resir014/a-phoenix-react-initial-setup-that-actually-works-c943e48f1e9e

It was incredibly helpful tuning the webpack configuration.

I ended up creating an umbrella project and serving my single page application through Phoenix (as you described).

vincer

vincer

I moved from Webpack to Vite myself (build times are too painful with Webpack), but thank you for sharing.

Glad to hear it all worked out!

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91561 914
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement