te_chris
Scaling LiveView for low latency in multiple regions
So we’re using LiveView in production and it’s mostly been fantastic. BUT, we’re UK based and serving the UK market - from GCP europe-west2, i.e. London. We’ve got devs in NZ currently, and they have said that the site is, as imagined, really slow from there.
What are peoples thoughts on scaling LiveView across multiple regions? It’s not an immediate problem for us, but it was a known since we decided to adopt it - thus far I think the productivity and quality of the UK experience has paid off. We’re currently using GKE, running stateless elixir pods, nothing shared or distributed between. This is working well for us and hasn’t given us any problems with the sockets. Given this, my first thought is just expand the Kube cluster into other regions and use node affinity and google’s global load balancer routing to sort it out…but I haven’t tried this or similar yet.
Has anyone had experience of this? It feels like the final hurdle for LiveView in some ways, so be good to know how people have handled it and whether it’s been smooth
Most Liked
josevalim
Correct. This is not a LiveView specific problem and it is going to happen on whatever app running between EU<->NZ. The LiveView specifics to this discussion are:
-
The initial request is rendered twice: once with a regular HTTP requests and another one over WebSockets
-
All upcoming live_patch/live_redirect happen on the established connection. This improves UX because we don’t send the layout again nor the browser has to load it again (this is similar to what you get with SPA, Turbolinks, unpoly, etc)
-
LiveView automatically caches and reuses templates in the client - so it sends less data than other server-rendered HTML solutions (similar to what you get with SPA)
-
LiveView runs on WebSockets, which means we don’t need to parse headers, authenticate user on the DB and so on on every request which improves response times (you can get similar with SPA if you are running on WebSockets)
So besides the initial request, LiveView should be helping with the user experience, but the discussion is definitely more general. So it probably makes more sense to open the discussion beyond the context of LiveView.
EDIT: Oh, you can also call liveSocket.enableLatencySim(200) in your browser console to have LiveView simulate latency so you can see which part of your app is not providing proper UX under high latencies. ![]()
te_chris
Interesting! Thanks for contributing, Jose.
Apologies for taking so long to reply, I got lost in a data engineering hole…
I think our problem is clearly that we’ve fallen too much in love with LiveView. We get away with it because we’re UK only, so latency is fine, but will need to refactor. We just really like the programming model.
For some context, we used to lean heavily on react, and now we’ve almost replaced all of our react with liveview, except for our main configurator (Stitched | Curtains and Blinds for reference). We’re doing some new UX though, and the intention is that this process will be modified and the new version will be LiveView. We definitely drank the koolaid. I feel a blogpost coming on, if someone on my team (probably me) ever finds the time ![]()
As a programming model, it’s unlocked a lot of productivity for us, even if we’ve clearly abused it by building things like our nav in it. I appreciate the points raised in this discussion, and can see an audit in the not too distant future where we assess how we’re using LiveView and move a few things back to the client. If anything though, this ability for progressive enhancement just shows the strength of the programming model and is reassuring me that we made a good choice. Thanks for taking part, everyone, has thoroughly answered my questions!
LostKobrakai
Imo this is not really a promise LiveView tries to make, exactly for that reason. It’s always been marketed to solve (primarily) those problems, where the server needs to be involved anyways. As mentioned before there is overlap (e.g. in pagination), but generally one should use client side tooling for purely client side interactions. Nobody wants latency in opening dropdowns or simple accordions.
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









