I couldn’t find a good overview post of people’s experience in production with elixir. I’m also wondering if there are common adjustments that get made, which should be ported back into the base template. While researching going to prod for elixir, I gathered numerous links I figured would help the next person.
Here are some thoughts, discussion points, and questions:
Context
- Been using elixir/phoenix off and on for past 7 years, but all for hobby projects
- I now have an app with real customers
- Using LiveView, Ash 3.0, tailwind, and hosting on fly.io
- 20+ years running large sites in prod across numerous languages and frameworks (php, rails, node, .net)
The reconnecting flash of death for LiveView
- I have to assume every “big” company using LiveView overrides it?
- This very specific flash is why I have trouble believing anyone is really using LiveView, beyond hobby projects. Unless they are all customizing it, but if that is the case, should we just update the core one?
- The red is really scary to end users…
- Also, reconnecting will often get stuck, and simply not work. This is across browsers and devices. And on my laptop (Chromium and Brave), it will spike the CPU until I forcibly reload the page.
- This happens locally, and on my fly machines (with rolling and bluegreen strategies)
Logging
- Something as basic as the client ip should just work without googling. Shouldn’t need to find a plug for it…
- I found request_id somewhat useless, so I added an “id” to the session, and I log that instead which makes it easier to follow a single user in the logs.
- It is very useful to see basic user and tenant info in the logs, and this turned out to be a bit of a journey to get them in there.
- Mostly because I also wanted to see logs for navigation within a liveview that don’t require a page reload. (A customer would tell me they are on a page, but I didn’t see any log event. And then it clicked in my head that some of our navigations use LV)
- Very curious what others do to monitor their app early on…
- I have Sentry setup for errors, and amplitude.com for monitoring user sessions
- But good ol’ tail logs is still my goto
Drift from phoenix template
- As the base template changes over time, how do people bring in new best practices?
- Same with core_components. Mine are heavily modified, so any changes to the base will never get pulled in. The update to LiveView 1.0 looks like a bit of a pain.
Plugs
- Any plugs or response headers, beyond CSP, that people change or add for production?
Erlang flags
- Are there any erlang flags that are generally tweaked once an app is in prod with traffic?
- I spent a lot of time in the past tweaking node, ruby and java flags, but maybe erlang is close to “it just works”?
:erlang.system_flag(:fullsweep_after, 20)
is the only one I saw blogged about
hexdocs.pm search
- Search for
temporary_assigns
, Search — Phoenix LiveView v0.20.17 - No results? That doesn’t make sense.
- Now search for
:temporary_assigns
- Gotta get that fixed.
temporary_assigns for LiveVIew
- (I’m thinking out loud for this one…)
- Shouldn’t everything be temp by default to keep memory low?
- We should specifically have to say what is sticky instead, no?
- If developers are more likely to bloat their servers’ memory with assigns, should we instead be forced to specifically call out what we need?
- We would still be able to “move fast” coding, but the resulting code would be significantly more future proof
Ash Queries
- When writing Ecto queries, I would always (easily) specifically select only the attributes needed, even from joins
- But with Ash, it is a bit cumbersome to select attributes in a query, resulting in a “select *” query, which sends shivers down my back
- Are other people who use Ash in prod just selecting everything all the time?
Ecto pool_size
- Ecto.Repo — Ecto v3.12.2
- Ecto pool_size? - #4 by bobbypriambodo
- I would instead love a “pool_size_strategy” that sets the pool size based on best practices according to how many cores were available
- I scaled the machines my app was using and forgot to adjust the pool size
- “pool_size_strategy: :best_practice”
- Make me learn as little as possible about the nuances of your library when possible
Database connection didn’t reconnect
- fly.io recently had a network issue (Sept 1, 2024), and my app didn’t reconnect to the db once the issue was resolved
- I had to stop and restart, which seems like a default ecto setting is wrong?
CSS oddities
- This happens to me on fly.io occasionally (maybe once a month), as well as my site
- I will switch over to a tab with a site running phoenix, and it will look as if CSS never loaded
- Easily fixed with a reload, but it would be scary to end users
A bunch of sites i perused over the past few weeks
- LiveView deployment options in production
- Tuning Elixir/Ecto/Phoenix for production - #4 by keathley
- Ecto pool_size? - #5 by ashneyderman
- How are your LiveView production servers doing?
- ElixirConf 2022 - Ed Bond - Review of using Elixir for 4 years in production
- ElixirConf 2022 - Kevin Hoffman - In Production with Elixir, Rust, and WebAssembly
- Phoenix LiveView in production examples - #15 by neodevelop
- Any downsides of using LiveView in big production apps? - #2 by bdarla
- Can large SAAS applications be created in Phoenix?
- https://www.youtube.com/watch?v=XzAupUHiryg
- https://www.youtube.com/watch?v=kBU4v609DOU
- GitHub - beam-community/awesome-phoenix-liveview: A curated list of awesome Phoenix LiveView repositories, blog posts or other resources
- https://www.reddit.com/r/elixir/comments/11ljydy/would_you_still_choose_elixirphoenixliveview_if/
- Phoenix Blog Post: Failing Big with Elixir and LiveView - A Post-Mortem
- GitHub - h4cc/awesome-elixir: A curated list of amazingly awesome Elixir and Erlang libraries, resources and shiny things. Updates:
- Blog: Elixir in Production
- Elixir in Production: Venu
- 8 Companies That Use Elixir in Production
- GitHub - glific/glific: The Main application that provides the core interface via the glific APIs
- PlugSecex — plug_secex v0.2.0
- RemoteIp — remote_ip v1.2.0
- GitHub - papercups-io/papercups: Open-source live customer chat
- Recap of Elixir Usage in Production · Elixir Merge
- Elixir in Production: What Is It Used For? - RisingStack Engineering
- Elixir in Production: How Felt.com and SleepEasy.app Utilize Elixir Systems · Elixir Merge
- https://www.reddit.com/r/elixir/comments/ldy2yh/in_your_experience_what_have_been_the_downsides/
- On "Why Elixir?"
- logging - Elixir / Phoenix: How to customize HTTP request log format? - Stack Overflow