And this all happens over WebSockets, workers are able to forward a WebSocket connection that's been sent to the worker to the durable object that it connects to and all these grid tiles get passed over WebSocket. They reach the game room and the game room is actually running the actual Conway's Game of Life simulation. And it processes all the rules on a regular cadence and then it sends back the actual live tiles on every time a new generation has taken place and it sends those to all the connected clients.
And one can imagine this happening, wow, this map is hard to see, one can imagine this happening all over the world. The Durable objects can run in a pretty large subset of data centers that Cloudflare operates. Right now, this is mostly in the eastern and western coast of the United States, and eastern and western Europe, and in Asia and Southeast Asia, and there's no limit to the number of Durable objects you can create. So with this simple app that has a few lines of code, you can have thousands and thousands and thousands of people playing Conway's Game of Life with each other all in separate rooms.
And so, I actually have a demo of this. I'm gonna open this up. I think the Wi-Fi here has been good enough to allow people to connect and give it a try. So, here, let me move this window over. All right, so if you scan the QR codes on the screen, you should end up at the same page that I'm on. I'm gonna make a Node Congress room, and I'm gonna create a game, and we'll go ahead and join. And so, if you place a single tile on the grid here, it's not really gonna do anything. You need to place a few. The shape here is called a glider, and it should move across the grid, and so, if I click send cells here at the bottom, it's gonna send it across, and so, if other folks connect, and place some tiles and do them around, they should show up on the screen, and you should see the same simulation on whatever device you're using as what you're seeing up here. And all this simulation is taking place in a single durable object that's been created near us. Off the top of my head, I think the nearest durable object data center here is in Amsterdam, and so, this is running somewhere in Amsterdam on a machine in a concrete building. And, yeah, that's pretty much my talk, I'll have this run for a little bit and so folks can play with it. Yeah, I hope folks like this. This is my first talk ever, so I'm pretty excited about it. Yep, that's it for me.
So, I'm gonna ask the question verbatim and I might change it a little bit. So, the question is, can you go into the pricing model of using durable objects in production? What would be a good use case where durable objects are a cheaper solution? We don't need to go into the pricing model perhaps in great depth, but it is worth noting, where is this a really good viable solution? So, with durable objects, the real key use case is if you want to create all these objects around the world, and it would be really expensive for you to run the infrastructure yourself. The pricing model is based off of wall clock duration of when the durable object is handling an active request. And so, if your durable object's handling a request, you're being billed for that time, once it returns the response, you're no longer billed. So, yeah, that's how the billing model works. Are there any times where it isn't, you know, you think, this probably isn't the right solution for a given project. Each individual durable object is a single thread of JavaScript execution, and so if your individual durable objects need to handle a significant amount of load, it's probably not the correct use case for you. It's really best for when you can split your application to many durable objects, and in the aggregate, you have a lot of load, but the individual durable objects are not as busy.
Comments