Live data from Hacker News

Build a real-time Twitter clone with LiveView and Phoenix 1.5

phoenixframework.org

31–40 of 249 posts

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#31

Earlier quoted context omitted.

You are running this on localhost but won't interactions be slow if a user is 200ms from the server? Re-rendering templates every time on things that require high interaction also seems very expensive and an easy way to slow down your server when you have multiple users correct? or what I'm missing?

LiveView does not re-render the template on every interaction. LiveView actually sends patches over the wire, which is typically smaller than a hand-written JSON response. The screencast linked above has a good example of this, where clicking the "retweet" button sends a minimal payload, since we know the exact position on the page. LiveView also uses a long-running WebSocket connection and that reduces the amount of…

This is the future of frontend development. Happy to see it making progress.

DHH was right about this stuff long ago in 2012 (mixing server side rendering with interactive JS frontends) even as the software wasn't quite there yet: https://signalvnoise.com/posts/3112-how-basecamp-next-got-to...

The other approach is SSR with React/Vue that hydrates on pageload with something like Next.js/Nuxt.js. https://nextjs.org/

But the Phoenix approach seems better for a more Railsy single framework approach (assuming you don't like writing the entire server side code in JS, which I do not). It's more cohesive and quicker to roll something out.

I currently do mostly Vue with Rails backends professionally but if it was from scratch or rearchitected with Elixir I'd seriously reconsider using full blown Liveview.

My only concern would be missing out on some UI libraries and pure size of community support. But I wouldn't miss getting rid of the super complicated JS tooling set ups I currently use (in addition to rails or trying to jam it through the asset pipeline via webpacker), in exchange for a more centralized approach. I've gotten a bit too used to maintaining the frontend almost separately from the server app and sometimes miss the simple days of being pure Rails.

One additional concern may be portability for mobile with React native. But that only applies to a subset of apps where reuse/cross platform makes sense. Still it was a big reason why these SPA style frameworks flourished like they did.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#32
I've been writing code for close to 10 years now and I see this and feel like what a beginner would feel trying to understand assembly code. Or someone hearing a similar but new language.

Looks to me hours of work and learning got abstracted as under the hood "magic".

It's like saying: Oh, so I've been weight training for the last 17 years and I should tell you Olympic silver is not too hard, see?

Am I right in my thinking? or is learning to be this proficient with the framework not as time taking for a novice developer as I think it to be?

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#33
post #14

I was a Rails user for almost a decade. I switched to Phoenix/Elixir 3 years ago. Elixir is a super simple language. It has no OO concepts and everything is functions first. In fact, it's so good that I started teaching it for universities. All my production web applications are now fully on Elixir. Elixir is one of those languages where everything has been done perfectly as of the time of this comment. When I say pe…

Can you explain in your own words for elixir where the balance between "joy" (productivity, flow, whatever you want to call it) and what you call "rethinking the way you write code". As another example of a functional oriented language that prides itself in the same thing look at Haskell. I wouldn't say most people think that Haskell is an easy or productive language (that is until after you have years of experience…

So as someone who worked in Erlang (and is familiar with Elixir), I can answer that a little bit.

They hit a sweet spot. Enough rigor, enough limitation, at the language level, to force you to do things "the right way" for a broad swath of problems (there are certain problems they're poorly suited for), but enough simplicity and freedom to keep a minimal learning curve, and minimal runtime complexity to figure out issues.

The focus on fault tolerance also means once you learn to use the app structure, with supervisors, you mostly have just one concern for reliability ("how do I start this into a known, good, consistent state?"), rather than hundreds ("what happens if -this- fails? Or that? Or that other thing?").

Haskell and Scala both have a huge surface area to learn before you're productive, let alone anything approaching fault tolerant, and even after years of use, there's still a lot of hidden gotchas with them. I've seen teams take Erlang, and their very first project just...worked. None of their lessons learned caused production issues, and no weirdness; the three issues that made it to prod I can even think of were, variously, one that wasn't user facing (just a log entry indicating something wasn't handled right; supervisor took care of it), one where performance started to slow (and it was due to having written an O(N^2) algorithm accidentally, and not testing at higher loads than production), and one where a low level C driver made an unnecessary reverse DNS lookup that, when the caches flushed, caused things to hang, which became an issue when load increased, and which should have been circuit broken (but which instead caused a failover to another node).

I've never had that experience with another language. The ramp up time to productivity was longer, the production issues caused by us missing something about the language were more frequent, the production issues caused by us failing to expect or handle a failure condition were more frequent, etc.

That said, Elixir and Phoenix do raise the bar a little. Elixir has a larger surface than Erlang (only a few concepts, but a lot of ramifications when it comes to macros if you haven't used them in other languages), and Phoenix is reliant on a fair bit of magic so you need to read the docs and it may take a little bit of work to feel happy with things. But even when I knew nothing about it, picking it was easy because of the experience I had with Erlang.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#34

Question to the former Rails devs out there: We mostly see threads fawn over Elixir and Phoenix, have you experienced any downsides to switching? Anything you miss from Rails? I'm convinced to give it a try after that demo!

I have ~6 years experience working in rails and ~3 years working with Phoenix. The only downsides I can think of are lack of official clients for APIs, and some missing packages. For example, if I wanted to do some PDF work I would really miss the prawn library. I don't miss anything from rails, Phoenix IMO is a superior web framework.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#35
post #14

I was a Rails user for almost a decade. I switched to Phoenix/Elixir 3 years ago. Elixir is a super simple language. It has no OO concepts and everything is functions first. In fact, it's so good that I started teaching it for universities. All my production web applications are now fully on Elixir. Elixir is one of those languages where everything has been done perfectly as of the time of this comment. When I say pe…

Are there any good tutorials to get started? What major sites are currently using Elixir?

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#36

I've been following this project for 5 years now, and I've really hoped it would take off. However, part of what made (and to some extent, still makes) the Rails framework so great is the surrounding ecosystem of well supported gems that makes building tedious things a breeze. I built a few things in Phoenix in the past, and while the core framework is very simple and elegant to use, I recall having to write my own f…

This happened to me with Clojure. You really get to appreciate languages with big ecosystems when working on niche languages. It's sad because these languages are more enjoyable to work with IMO. Thy are better cause they had the advantage of being created much later than the mainstream ones but that also means they had hard competition.

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#38

I've been writing code for close to 10 years now and I see this and feel like what a beginner would feel trying to understand assembly code. Or someone hearing a similar but new language. Looks to me hours of work and learning got abstracted as under the hood "magic". It's like saying: Oh, so I've been weight training for the last 17 years and I should tell you Olympic silver is not too hard, see? Am I right in my th…

Are you familiar with Ruby on Rails? Phoenix was built as a simpler equivalent, to leverage websockets, and to leverage the BEAM to be performant with high concurrency (i.e., what you generally want in a web server).

Is it encompassing a lot of magic? Yes. But the quick growth in mindshare that Ruby on Rails attained back in 2005-2010 (part of which it still retains) was due to how easy it was for a novice developer to pick it up and build something useful. Pick it up and understand all the pieces, no. Phoenix is less Express/Martini in nature, more Spring/Rails (but more pleasant than either of those to work with, I would contend, but again, that's opinion).

Re: Build a real-time Twitter clone with LiveView and Phoenix 1.5

#39
> On the heels of the official LiveDashboard release, Phoenix 1.5 projects now ship with LiveDashboard by default, for real-time performance monitoring and debugging tools.

and it uses uPlot [1][2] in the metrics panel :D

[1] https://news.ycombinator.com/item?id=21207132

[2] https://news.ycombinator.com/item?id=22567922

Post reply on HN