Skip to content

Instantly share code, notes, and snippets.

@nathanl
Last active October 31, 2019 16:48
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nathanl/71577b8482b56f2ecb3db358c1b2afc2 to your computer and use it in GitHub Desktop.
Save nathanl/71577b8482b56f2ecb3db358c1b2afc2 to your computer and use it in GitHub Desktop.
James Edward Gray II describing the ability to build *stateful* web application in Elixir

James Edward Gray II

Quote from Elixir Mix 63 - "063: Designing Elixir Systems With OTP with Bruce Tate and James Gray", starting at 01:03:13

"I've worked at a bunch of companies building web apps for a long time, and I keep seeing this same pattern, and it haunts me. In the web world, all we want is these long interactions with people, and we live in this stateless world. So what we do is, the first part of every request, we do thirty queries to re-establish the state of the world that we just forgot a few seconds ago after the last request. And then we go forward and make one tiny step forward, and then we forget everything again, so that when the next request comes in we can do thirty queries to put it all back and make one more tiny step. And I kept thinking, "there has to be a better way than this, right?"

And if you look at web advancements over the years, most of the things we're doing are to mitigate this problem, right? Redis, and things like that. "Oh, we don't have time to go to the database to do the thirty queries, so we'll put 'em in Redis, it's a lot faster, we'll do the thirty queries there instead", you know?

It's ridiculous! I wanted a way where I could have a sustained interaction with a user. And a buddy of mine I used to work with had told me years ago that Elixir could do this, and I ignored him. And then I went and finally played with Elixir, and there's absolutely a hilarious tweet exchange with us, where I go back and I'm, "did you know Elixir could do this!?", and he's like "yeah, I told you that many years ago". So, thank you Nathan for telling me about Elixir, and P.S., you were right. [1]

And my team at ICanMakeItBetter, we just built a new product in the last three months, and it is going live on Tuesday, it will see its first real usage, and this is the first time I've actually built with this model of we just have a sustained conversation with the user while we're having it. And I cannot impress on you enough how radically different it is to build a web application this way. The having to do the thirty queries to reestablish what's going on - it's gone! You don't have to do it! You just know. You can just remember what's going on, like you're having a conversation with somebody. It's amazing! It's incredibly liberating.

Also the sweeping effects it has through the system are mind-blowing. Like, when we use our old application, you go around to the various pages and stuff, you know it's, "let us do this billion queries so we can load this giant chunk of data and show you some snapshot of where things are." In the Elixir one that we just built, everything is live, because we're having to pubsub to get it over to a different channel anyway, so it's totally free to show a page, and just change the number on the page when we get some pubsub message or whatever. And it's all just live and immediate. And it feels different, it feels like just a live thing that's happening now.

So that's my quest and, and I think I have finally found what I'm looking for, and it's amazing.


[1] James is very kind to give me credit for telling him about this, but actually he just blew my mind by describing stateful web applications in this way. As the screenshot of our conversation in our 2016 ElixirConf presentation shows (which I think itself might have been a reconstruction of our actual conversation), all I said was that Elixir was good for building robust and concurrent applications, something I thought was cool because at the time, James and I worked at a place where we were using a cumbersome Ruby microservice architecture to try to get concurrency out of a system. What James describes above is his insight, not mine.

Also, I would like to add to his comments something that he left implicit, which is that the reason James can build a stateful application in Elixir so easily is that the Erlang VM lets you maintain millions of lightweight, concurrent, isolated VM processes within its single operating system process, so keeping the state of many simulataneous connections in memory is no problem. This is a distinctive property of the Erlang VM. I've written about the philosophy behind the Erlang VM on the DockYard blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment