Durable Objects - Everything Everywhere All At Once For Not Very Much Money

Cloudflare's Durable Objects are a new JavaScript runtime that makes building stateful, on-demand backend servers on the edge as easy and cheap as serverless functions. 

By colocating compute and state, Durable Objects melt complexity at scale, and allow you to focus on building your product.

In this fast-paced talk we'll live code a real-time backend from scratch, show how Durable Objects work, and explore how you can apply this versatile tool to a wide range of everyday engineering problems.

Rate this content
Bookmark
Watch video on a separate page
Video Summary and Transcription
The video focuses on Durable Objects, a technology by Cloudflare that enables the creation of stateful, collaborative applications. These objects provide a unique approach to storing and managing data globally without the need for traditional databases or Kubernetes clusters. By utilizing Cloudflare's infrastructure, developers can benefit from globally distributed compute and storage, which is both cost-effective and efficient. The talk highlights how Durable Objects can be used to build real-time applications such as chat rooms, games, and collaborative tools, where state consistency is crucial across multiple user sessions. The use of WebSocket connections allows for live updates, making it easier to push data to clients without extensive server provisioning. Additionally, the video discusses the limitations of Durable Objects, such as memory and storage constraints, and how billing is managed based on compute, storage, and memory usage. The potential of Durable Objects in creating scalable applications with high concurrency and stateful interactions is explored, showcasing their versatility in various tech scenarios.

This talk has been presented at React Day Berlin 2023, check out the latest edition of this React Conference.

FAQ

Durable Objects is a technology by Cloudflare that allows you to build stateful, collaborative applications by provisioning long-lived server environments which are uniquely addressable and can maintain state.

The main topic of the talk is Durable Objects, a technology by Cloudflare for building stateful, collaborative applications.

Durable Objects are unique because they offer strong consistency between memory and disk, can spin up instantly, and co-locate compute and storage. This makes them ideal for a variety of applications, including those requiring high concurrency and stateful interactions.

Billing for Durable Objects is based on three factors: compute time, storage, and memory used while the object is running. WebSocket connections are also managed efficiently to minimize costs.

Yes, Durable Objects can handle authorization by using HTTP endpoints that can validate tokens or other forms of authentication.

State management in Durable Objects is done by storing data in-memory and also backing it up to a built-in key-value store. This ensures that the data persists even if the object is temporarily spun down.

Benefits of using Durable Objects include the ability to create stateful applications that can scale globally, co-locate compute and storage, and handle high concurrency. They are also cost-effective and easy to manage.

Durable Objects have a memory limit of 128 MB per object and a maximum value size of 128 KB for each key in the key-value store.

Yes, platforms like Reflect, which provides state synchronization services, are built on Durable Objects. They are also commonly used in back-office capacities for session management and other use cases.

Durable Objects can be used to build collaborative applications such as chat rooms, games, whiteboards, and more. They are versatile and can be applied to a variety of use cases.

1. Introduction to Durable Objects#

Short description:

Let's get going. Thank you, Kevin, for this wonderful introduction. Today we're not going to do slides. We're going to do live coding. So today I want to talk to you about something called Durable Objects, which is a bad name for a really cool thing. Can I have a show of hands? Who here before coming to this talk has even heard of what Durable Objects are? We have about 10 hands. And I'll keep the hand up if you've actually run Durable Objects in production.

Let's get going. Thank you, Kevin, for this wonderful introduction. It's a thankless job to be an MC. Can we have a round of applause for Kevin and the MCs as well?

Yes. I do love being a part of these conferences. I've been part of almost every React Debrieve in the past. And it's my first time speaking. And I don't speak very often because I hate making slides. So today we're not going to do slides. We're going to do live coding. But because I did make the mistake of naming this talk everything, everywhere, all at once. I thought there might be some movie buffs in there. So I did put in one slide just in the beginning just so people don't get angry about me not, you know, putting in the slides. So this is the slide. It's a keynote animation. Look at it. It's beautiful. There. Wow. Look at that. Wow. Okay. Nice.

So today I want to talk to you about something called Durable Objects, which is a bad name for a really cool thing. So this year, like every year at the end of the year, I reflect what is it that I've been working on differently this year. What are some of the sort of new tools and new practices that have sort of, you know, improved my ability to do my job as an engineer. And Durable Objects is one of those discovered from this year I really want to share with you. Can I have a show of hands? Who here before coming to this talk has even heard of what Durable Objects are? Okay. We have about 10 hands. And I'll keep the hand up if you've actually run Durable Objects in production.

2. Introduction to Cloudflare's Durable Objects#

Short description:

Okay. So like two or three people. Great. This is exactly what I was hoping for. Durable Objects is a technology by a company called Cloudflare. It's a really cool technology company, but they're not really good at telling people how to use it or selling it or anything like that. So I thought instead of trying to explain it to you, I'm just going to show you how this works. Cloudflare is one of the biggest internet infrastructure companies, known for its CDN, cache, proxy, and bot defense services. They have a developer platform called Workers, where you can run serverless code. Cloudflare's workers run in every one of their 300 server locations, making services extremely fast. Durable Objects is a versatile programming paradigm, which I will soon demonstrate to you.

Okay. So like two or three people. Great. This is exactly what I was hoping for. And don't worry, this is not your fault. This is Cloudflare's fault.

So first, a little preamble. Durable Objects is a technology by a company called Cloudflare. I do not work for Cloudflare. I'm just an enthusiastic fan. I am not paid by them. They didn't even review my slides, so everything could be incorrect. But then on the other hand, I get to say anything I want about Cloudflare. And the thing about Cloudflare is that it's a really cool technology company, that there's really cool technology, and they're not really good at telling people how to use it or selling it or anything like that. So I thought instead of trying to explain it to you, I'm just going to show you how this works.

Okay, so this is Cloudflare. If you haven't heard of this company, it's one of the biggest sort of internet infrastructure companies. You might know them as a CDN provider, as a cache provider, proxy provider, bot defense, stuff like that. But more than that, they have a perfectly wonderful developer platform called Workers, where you can run serverless code, just like Lambda. But instead of like Lambda that usually runs in only one location or one availability zone, depending on how you configure it, Cloudflare's workers run in every one of their 300 server locations that they have around the globe. And they automatically in their network, basically just route your request to the closest one. So this means that thanks to these things being close, usually these services are extremely fast.

But so if we go to this developer platform website, behind here, below this Workers, there's this kind of well buried section called durable objects. And under here, if we go, we get to find out what durable objects are and what they do. And remember, I don't work for Cloudflare. And they tell us that we can build collaborative applications, like chat rooms, games, whiteboards. This is really cool. I love playing games, like building games and chat rooms and whiteboards. But in reality, most of us don't really get to build this type of software in day to day thing. And this is, I think, the biggest underselling of what durable objects are, is that they are really versatile programming paradigm, which I will soon demonstrate to you.

3. Building an App and Running Local Development#

Short description:

When exploring this technology, consider its potential use cases beyond the current topic. We'll build an app together and revisit our understanding at the end. Join us by scanning the QR code or visiting do-it.pages.dev. I'm running local Wrangler development and a background deploy. Let's start with a counter demo.

But when you do this, when we go through this, keep in mind, you know, what else you could use this technology for? And in the end, we'll discuss that. But, you know, don't get fixated on this.

But let's scroll down. So you get to maintain states. Well, that's something. Scale and demand sounds marketingy. Embedded compute, no idea what they're trying to tell me here. So I figure what we'll do is that we'll build a little app. We'll all get to play with it together. And then at the end, we'll come back to the same page. And then we'll see if we actually understand what this thing is. So good? All right. Let's do this.

So I have prepared us a little app. If you want to join us on this thing, you can scan this QR code. And you can basically play along on your phones. If you're joining us via live stream, you can also just go to do-it.pages.dev on your computer or whatever to join.

Okay. So let's get started. Here at the bottom, I am running two processes. One of them is my local Wrangler development environment. This is the CloudFlight development environment that allows me to run serverless workers, stuff like that. And then running a background deploy. Not logged in. That doesn't sound good. Let's run that again. And so every time I save any code, it will also deploy it to CloudFlare. So you will also get to enjoy the same code a few seconds later, maybe five seconds later. So let's start. I think the first technology demo that we always need to build for any app is a counter, a number that goes up.

4. Making the Number Go Up#

Short description:

Let's make the number go up. We set the value to zero and save it. The app turns into a button, and in a few seconds, your app should also turn into a button. The code runs in Frankfurt.

That's also the point of most crypto scams. But then the number keeps going down. I don't know what's wrong with that. But here we do like an honest to god number go up where we just say, let's say value is zero. And then if I save it here, I see that this app turns into a button. And in a few seconds, your app should also turn into a button. So I'm kind of controlling your phones from here. And what we see also that we're returning this colo. This is the location where the code runs. So if I go back to this CloudFlare end, we see that this code is currently running in Frankfurt.

5. Creating a Counter Class with Durable Objects#

Short description:

Let's make this counter application. We increment the number on a POST request and return the counter. The number goes up when the button is clicked. However, different devices show different numbers due to the nature of serverless execution environments. This is where durable objects come in. They allow us to provision stateful and uniquely addressable server environments. Let's create a counter class with an instance variable and a constructor.

So let's start. Let's make this counter application. So if I remember how to program, we have some kind of a variable. And let's say that is a number. And then let's say that if these requests up, that is not where that goes. If this request, for example, is a POST request, then let's increment that number like so. And then let's return that counter. And now, here in my end, I can hit this button and this number will go up. And on your phones, when in a few seconds, if you hit the button, the number will also go up. Can somebody give me a whoop when their number starts going up? All right, great. Sounds good. I can, by the way, see that there's 50 people currently on the app connected. I don't know if it's all in the room or if some of them are on livestream, but thanks for joining us.

Now, number go up is really cool. But if you compare the phone of the person next to you, you see a different number. Why is that? You are most likely probably connected to Frankfurt as well, but we are seeing a different number. Why is this and why is this a problem? Well, because the way serverless execution environments typically work is that for every request, we basically spin up a new, very short lived environment. In the case of durable objects or CloudFlight workers, it's a V8 isolate, similar to the WebWorker, where we can run JavaScript or Wasm code or stuff like that. But the problem here is that we all get a different execution environment, which is good for security and isolation, but not really great for collaborative applications. And you also see the number went zero here. Why did that happen? Well, this number happens to go up just by accident because CloudFlare optimizes resources and keeps the thing in memory for a while. But after 10 or 15 seconds of me yammering over here, they will spin it down. So how do we make it so that we can all see the same number? Well, let's start with that. So this is where durable objects come in. So instead of just having a function that takes in a request and a response, we're able to basically provision these short lived or long lived, for that matter, server environments that are stateful, then uniquely addressable, and we can all connect to them at the same time.

So let's start with that. So let's make a counter class. And if we remember our JavaScript, we can have a instance variable over here. And then instead of using that variable, we'll just increment that instance. And just before we go any further, let me also add this constructor here because we're going to need it in a little bit.

6. Implementing a Class and Instantiating Instances#

Short description:

Now we have implemented a class that allows us to make requests and instantiate multiple instances of it using unique IDs. Each request is forwarded to the corresponding durable object instance, resulting in the number incrementing. This can be improved to create a more exciting and versatile counter example.

Now we have implemented a class. I haven't saved it yet, so nothing will happen. This looks like pretty much normal JavaScript, except that you can make requests to this function. That's pretty sweet. But in order to instantiate this class, we also need to do something else, which is that we need to basically decide which instance of this class do we all connect to. And the way that we can do that is we can have like a normal standard... Oh, thanks, co-pilot. You got it correct. That's cool. So we can create an instance of this by a unique ID. So if we read this code line by line, we basically create an ID of an object. In this case, it's just a string that says counter. Then we get an instance of that durable object. If that durable object previously exists, we get an instance of it. If it doesn't exist, it gets created for us. And then we forward the request that comes in from the app to that durable object, and then that object will handle it. So now if I save, here on my end, number goes up. Well, we saw that already. That's not too exciting. But in a moment, hopefully, deployment has gone correctly. Great. Now, oh, look at that. That number keeps going up by quite a lot. I think that's because all of you are hammering it. And every time you hit it, you're incrementing the same number as the next person is, and then you're getting the increments of the previous person. So that's pretty sweet. That's cool. I think we can make this a lot better. And before we do that, let's make this more exciting. I think counter example, I think, is good for simple things.

7. Incrementing Two Numbers#

Short description:

But I think we can do something more fancy. Let's increment two numbers and make it a popularity contest. The app sends an ID or number with the request. We've built an application that increments two numbers and sparks arguments. This is a standard Vite React app that fetches deployed code and makes a post request to increment the number.

But I think we, as adult developers, I think we can do something a lot more fancy. So what is cooler than incrementing a number? I think I would posit that it's at least twice as cool to increment two numbers. So let's just do that. And while we're at it, let's make it interesting. Let's make those numbers mean something. So let's say we're a React conference, let's say a remix, or in Next.js. Let's make this into a popularity contest. And then here, let's see. We will take the request that comes in, and the app here will send an ID of the button or like a number of the button. And then let me just add this question here as well. Great. So now on my machine, we see this little voting application. And in just a second, you should be able to do that as well. That's great. All right, so we have built an application that increments two numbers. But by attaching names to it, now we're having an argument. Funny how that works. Okay, so that's okay. But before we go further, I think at this point, it would be good for me to explain what is it that is actually happening here. Because we're going to add a lot more functionality. And before we do that, I don't want anybody to be confused. So if we look at this project that I have here, this is a completely normal standard Vite React app that's running in a browser. And all of the application is really doing is it makes an HTTP fetch to this deployed code that we have. And then when you click it, it makes another request with a method post. So we increment the number. And so the reason the number goes up, oh, 2000 times you've pressed 4000 times. Great. Somebody's having their fingers busy, or somebody wrote a little script in their browser to hammer the button. Please don't do that. But if you must, go ahead, I think we can scale for that.

8. WebSocket Connection and Live Updates#

Short description:

We're making a WebSocket connection to the same address, allowing us to build push-based systems. The WebSocket constructor sends an upgrade request and establishes a connection. We can loop over the connected WebSockets and send the same state to each one. This enables live updates and displays the number incrementing in real-time.

So this is all that's all that's happening here. And then we render a button for each of the values that's coming in. So in this case, you know, two numbers, and you know, they get two buttons. But I'm also doing one more thing here, which is that I'm attempting to make a WebSocket connection to that same address. And if you don't know WebSockets, it's basically like imagine a tin can with a string in between them. You know, I hold one end of it, you hold one end of it, and then I can yell into it. And you know, I can send a message to you and back and forth. That over TCP is basically what WebSockets are.

So that allows us to build push based systems. So let's do that since our client is already prepared for it. So let me just go back to this contract here. And let's just do this. So if request headers, oh, thanks, Copilot. And then, oh, nice. Okay, so, so basically, what we're happening here is that the WebSocket constructor, the library that we're using is just a standard React wrapper over a WebSocket constructor. It sends this upgrade request. And in return, we give them, we hold one end of the tin can and we give the other end of the tin can to you. And then we can push messages to you.

And now, every time the messages, sort of the number is incremented, let me also then, oh, nice. We will, you know, loop over all of the currently connected WebSockets because we are, you know, having in-memory states. So we can basically just loop over them. And we can, you know, send the same state to you over that socket. And now I've saved. My end seems to be working. And so maybe in a second after your app refreshes, oh, we see the number go up live. And I don't know why that is changing the location between. Oh, I just made a bug. So that's basically the location through the first worker that connects you to this durable object. I am actually just made a bug here, which sends, you know, the location of each of those people to you. So we see where everybody is.

9. WebSocket Server and Data Storage#

Short description:

We've created a little WebSocket server that can hold the connection between me and all of you. Currently, 45 people, but this would scale up to 32000 if we wanted to be really ambitious about it. However, when I make any code change and save, the number goes back to zero. That's because we're using in-memory state, which is not realistic for long-term storage. Thankfully, DurableObjects provides a built-in key-value store for every object, allowing us to store information on disk and retrieve it when the object comes back alive.

Everybody is in Frankfurt, Vienna, Sheldagol, etc. But it's moving a little fast. OK, so does everybody understand more or less what's happening here? We've created a little WebSocket server that is able to hold the connection between me and all of you. Currently, 45 people, but this would scale up to 32000 if we wanted to be really ambitious about it. And we're able to broadcast messages to all of you. So we've created a little collaborative application. So far so good. Nice.

OK, but one thing that you might have noticed, and this is easier for me to demonstrate when I go here on my localhost. When I make any code change and I save, the number goes back to zero. Boo. That's not very useful. How do we how will we ever know which one will win? Remix our next JS if we keep resetting the number every time we deploy code. Well, the reason why that happens is that, you know, we are using in-memory state here. If we just kind of like recap really quickly. You know, this is all of the state management that we have. We have a counter in memory. Kind of cool, but at the same time, we can't really guarantee that an object will stay in memory forever. That's not really realistic. What we can instead do is we can store that information on disk. And so when this object comes back alive, in this case, it keeps resetting when I deploy new code. We can use some kind of storage system. Now, I could go to PlanetScale and I could provision myself a, you know, like a SQL database and I could contact that. But I think that would kind of defeat the purpose here. And thankfully, DurableObjects, you know, is actually a storage product. So we have a built in key value store for every object. So what we can do here is we can say, let me just write this code. So let's see. Let's make some kind of function that loads the data from... That's cool.

10. Implementing Storage and Dynamic Object Creation#

Short description:

We have implemented a storage-backed system using Durable Objects. It allows us to store any JavaScript object or data structure without converting it to JSON. CloudFly ensures the data is stored and retrieved when the object comes back. We can create multiple instances of these objects anywhere in the world instantly. Objects can be created dynamically based on HTTP paths. Each object can have its own unique properties and functionality.

So we have storage and that has, you know, a method called get, from which we can get data that we have previously put into it. In this case, we use the key value and we also type that the data is just the array of numbers. And then similarly, we can have a function to save that data into it at some point. So let's save the data every time we increment. And let's also load the data when we come to, when the object constructor runs, meaning that when we are loading the object after redeploy. And now we've basically implemented a sort of like storage backed system. So next time that this goes, redeploys, now it went to zero. But then if I know where to deploy again, hopefully let's say, save, I'll walk off and you keep pushing the button and hopefully when the redeploy happens, the number doesn't actually reset. All right. So this is interesting, right? Like if we recap again, we have just a normal JavaScript class that we can hold state in memory, we can basically, without serializing or without having to do any fancy things, we can basically store any JavaScript object or data structure without having to convert it to JSON. And CloudFly will make sure that that gets stored somewhere and then we can read it back when the object comes back. So we are essentially creating a fully functioning database-backed system in just a single JavaScript file that exists in our project right here among my frontend components. So that's pretty sweet, but it's not sweet enough. This I could have done very easily. I just made a node server and deployed that to fly.io or Heroku or something. But what's really extraordinarily interesting about this is that we can create any amount of these instantly, freely, anywhere in the world. So here, if we go back to where we create this object, we create a counter. And if I change this ID, for example, the counter two, and then in a few seconds now, the number will for you reset, because we're actually talking to a different object, right? Like we have provisioned a new database. There we go. New object, new database, new memory isolation layer where we can run this code. But you don't need to use static IDs. We can create objects dynamically. So for example, in this case, let's say that we send a path, you know, like a normal HTTP path into this request and we create an object for it for that. And to make that demo a little bit cooler, let me also change the question for every room so we kind of see what's happening here. So I've prepared a little code here. What is a good question from room ID? And this just basically picks like based on the room's ID, picks a random question from, you know, from a list of questions. And now, hopefully. All right. Semicolons or no semicolons. Do you see that on your phones also? Semicolons or no semicolons? Great.

11. Managing Rooms and Data Storage#

Short description:

Let's make a different room, like room Berlin or the wall room. We can spin up an infinite amount of these rooms by coming up with a new ID. However, we don't want to store the data forever. We can use alarms to schedule code execution and delete storage that is no longer needed. This allows us to run code in a scheduled manner and manage data storage efficiently.

Awesome. Let's make a different room. Let's say room Berlin. All right. Stickers or socks? This is, you know, classic conference question. Let's say a new room. Let's go to wall room. Office or remote? Ooh, remote. Employers take notes.

And then if we go back to the original room over here, you know. Oh, sorry. This is a bug on my client code. What was the one Berlin we had before? Great. So all of that data that we had in the previous room is still stored. You know, we are coming back to the thing. So we were essentially able to spin up an infinite amount of these rooms, you know, by just essentially coming up with a new ID. So that's pretty useful, I think.

One final thing I will do before we jump into the explanation part of this is I don't actually want to store this data forever. I think right now what we're doing is that for these rooms that we've created and any new rooms that we would create, we would basically keep this data around forever. But we don't actually need to invoke a durable object in order to run code there. We can also run code there in a scheduled manner. Durable objects has this thing called alarms where we can say, you know, this state storage set alarm. Let's say, OK, so for example, if my math is correct, in one week we want to run some code and then we'll make this function called alarm. There we go. And then this alarm will run basically one week from the most recent invocation of set alarm. And all we do here is we basically just delete the storage that we're no longer using because we don't need to store this data for longer than a week. If you wanted to, you know, save this somewhere else at this point, it would be a good time to send it to maybe some kind of like backup system somewhere like some long term storage R2 or S2 or S3 or something. But until then, the storage is all really storage that we need. In order to demonstrate this, I'm just going to shorten this time to a second just so that we don't have to wait here a week. And now the next time that we come to deploy, which will happen about now.

12. Exploring Co-located Compute and Data at the Edge#

Short description:

Now if I can all get you to co-operate and not push that button for one second. Then the next time we push this button, it will go to zero. Building collaborative applications is cool and fun, but hopefully you can sort of squint a little bit and think about like, so if you can create essentially compute capacity instantly, you can co-locate storage with it. You can push data from web sockets. You can open TCP connections to databases. You can call these as webhook endpoints from external systems. It's really interesting how you can like really think about computation differently. Because one of the big mistakes I think we've made in AIRA, and I happened to see a tweet about it just today, so I will just let this tweet speak for it. But like, I think we as an industry have been trying to reinvent distributed computing basically by just creating these separating compute and state. So like co-locating your compute and data at the edge, I think is a really powerful new sort of paradigm that we as industry should really explore more. And thankfully, it's not just CloudFlare that is doing this. So Azure has this durable functions, which is very different from an API perspective, but basically does the same thing.

Now if I can all get you to co-operate and not push that button for one second. Then the next time we push this button, it will go to zero. Oh, you did it. I was expecting some more resistance from you there, but this is good. All right. So I think that's all code I wanted to show. And I think that went pretty well. Can we have a round of applause for me? Thank you. Thank you. And Co-Pilot was behaving really well today. So thanks Co-Pilot as well.

All right. Now the timer is... How are we for time? We're already over, are we? Great. Well, I want to say just two things, and then I will go to Q&A and I'll let you go. So building collaborative applications is cool and fun, but hopefully you can sort of squint a little bit and think about like, so if you can create essentially compute capacity instantly, you can co-locate storage with it. You can push data from web sockets. You can open TCP connections to databases. You can call these as webhook endpoints from external systems. It's really interesting how you can like really think about computation differently. Because one of the big mistakes I think we've made in AIRA, and I happened to see a tweet about it just today, so I will just let this tweet speak for it. But like, I think we as an industry have been trying to reinvent distributed computing basically by just creating these separating compute and state. We create these little pieces of computation and then we create these really complicated hell machines where not only do we need to use a database for what database is good for, which is storage, but we also need to use database for coordination. Like if we wanted to make a number that goes up and we didn't have the ability to use in-memory state, we would have to have like a Redis database where that number keeps being incremented. And then you get into all kinds of like database isolation level issues, which you just don't want to deal with. And then if you think about where do you want to run your serverless workloads? Like either you want to run them close to your user, which makes the initial hop really, really fast, or you want to run it near your database, which makes your data fetching hop, but you can't have both. So at some point you're essentially saying if your database lives in one place, you are going to build a slow application if it depends on data. So like co-locating your compute and data at the edge, I think is a really powerful new sort of paradigm that we as industry should really explore more. And thankfully, it's not just CloudFlare that is doing this. So Azure has this durable functions, which is very different from an API perspective, but basically does the same thing.

13. Deno's KV and fly.io's Flame#

Short description:

Deno's KV and fly.io's Flame are innovative products that simplify program development by eliminating the need for provisioning databases, compute, and Kubernetes clusters. Instead, they distribute data globally and ensure code runs consistently.

Deno has this KV, which is a slightly different product in the sense that instead of just keeping the data in one place, they actually seek to distribute that data eventually, in an eventually consistent way globally, which gives you different constraints. But in this case, we don't need that. And also just this week, fly.io released this paper or this blog post called Flame, which is a new type of architecture where you can just wrap any code in a function and they will make sure that it runs exactly the same way as we've just demonstrated. So I think this is kind of like a path that has helped me simplify the kind of programs that I write, because I don't need to think about provisioning databases, provisioning compute, provisioning, like running a Kubernetes cluster. I can essentially just have the compute that I need available to me when I need it.

QnA

Exploring Everything, Everywhere All at Once#

Short description:

Everything, everywhere all at once. Compute, storage, globally distributed. Cheap to run. Q&A: Limitations of durable objects - 128 MB of RAM, storage limit of 128 kilobytes. How are they built? Billing based on compute, storage, and memory usage.

And yeah, I think that's it. If we now go back to the sort of the slides, I think maybe we've explained the title, everything, everywhere all at once. So everything as in, you know, it's compute, storage, everything you need to build something. It's everywhere. It's globally distributed. And all at once, you know, you can basically spin up any amount of instances. This scales to millions very, very quickly. I haven't really touched the for not much money. We can talk about that in the QA or over time. But basically, these things are also kind of cheap to run.

And for movie buffs, I did want to have one last slide here, you know, just to have something to look at. That's it. That was my movie reference. Thank you very much. My name is Janne. And let's do a Q&A.

What the limitation of durable objects? 128 MB of RAM, which is not a huge amount. But then again, I haven't really have a lot of use case where you exceed that. Storage as much as you want, but each value can only be 128 kilobytes. So if you have like massive singular values, you might need to chunk those up a little bit. Yeah, those are the big ones.

How are they built? This is the really cool thing. And now we can get to talk about costs. So billing is basically on three factors. So it's the compute. So every time we send a message, you're billed just like a normal function in a worker stack. Then you pay for the storage, of course. So that's why we want to clear, for example, the storage of seven days not to pay for something that we need. And then the memory used of the object while it runs.

Memory Usage, Authorization, and Commercial Apps#

Short description:

The WebSocket API offered by Cloudflare is interesting as it allows the object to be unloaded from memory when not actively processing connections, making it affordable. Authorization can be handled through HTTP endpoints, allowing the use of tokens and third-party services. Reflect, a multiplayer state sync platform, is an example of a commercial app built on durable objects. It is used in back-office capacities and is suitable for applications that require long-lived sessions and state storage. Cloudflare's existing billing relationships with companies and their free program for startups make it an attractive choice. Storing part of the state permanently is useful in scenarios like the Uber example.

And then the memory used of the object while it runs. But the WebSocket API that Cloudflare offers here is really interesting because what they do is that they on the platform stack level network level, they hold on the WebSocket connections, but they can unload the object from memory when it's not actively processing connections. So if you have, for example, a room that stays active for a day, but it only gets a few messages during the day, you only really pay for the brief millisecond that the object is alive while it's processing that message. So it's actually really, really affordable as well.

Nice. How do they handle authorization? So you handle authorization, right? So it's HTTP endpoint. So, you know, like you can send over a token, you can authorize that with any third party service or your own auth endpoint. It's completely this thing that I have is not authorized, but you could add a auth sort of ping back for just a few lines of code.

Do you know of any commercial apps or I may just say large applications running on durable objects? So there are a lot of platforms actually built on durable objects. So for example, Reflect, which is a sort of like a multiplayer state sync sort of package. That is it's an amazing platform. It really solves like a lot of the common sort of state syncs of problems that users might have. And it's built on durable objects. And, you know, basically it's cheap as well because the billing model is the same as the durable object one. But these things are actually used a lot of in a back office capacity. So if you think of, for example, a session that lives for a while, let's say you're building Uber and you have a taxi booking app. You need a piece of compute that is able to not only, you know, communicate to multiple different back-end services, but hold its state for the duration of the ride and then no longer. Like this is a perfect use case for it. I'm not saying that Uber is using it, but these are the kinds of like, you know, industrial back-office use cases where I feel like the pitch of collaborative apps and whiteboards and games is kind of underselling it. You can really build serious production scale things. And I will say this one thing. I don't work at Cloudflare. I am not trying to sell this shit in particular. You can also use the Azure one or you can use, you know, whatever. But the good thing about Cloudflare is that if you work in a decent sized company, you already have a billing relationship with them because you use it for, you know, DNS and caching and proxy and all of that. So it's not actually a hard sell to get this into into corporates as well. And if you're a startup, they have this program that you get it for free for a year. So. And I suppose the other interesting thing is the Uber example, I think, is a fantastic use case for when you would take part of that state and store it permanently. You don't need all of it.

Simplifying Feature Development#

Short description:

You don't need to store every step of synchronization. Just the key points are stored at the end. This technology simplifies building features like sharing rides in Uber without the need for provisioning numerous WebSocket servers. Pushing updates to clients is effortless, requiring minimal software engineering.

You don't need to be storing every step of the synchronization. Just these key points, we store that at the end. Exactly. And yeah, exactly. Yeah. And then you just send the metadata over that you needed to. But like, Uber now has this feature where you can, for example, share the ride with your friend, you know, safety feature. Right. So imagine building that, you know, without something like this, you need to provision a massive amount of WebSocket servers. You need to create this sort of like abstraction, like socket IO kind of thing. It gets really, really messy. But here, like making pushing into one client is as easy as pushing into all registered clients. So you don't really have to do any software engineering as such. Nice.

Jani Eväkallio
Jani Eväkallio
31 min
08 Dec, 2023

Comments

Sign in or register to post your comment.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Modern Web Debugging
JSNation 2023JSNation 2023
29 min
Modern Web Debugging
Top Content
This Talk discusses modern web debugging and the latest updates in Chrome DevTools. It highlights new features that help pinpoint issues quicker, improved file visibility and source mapping, and ignoring and configuring files. The Breakpoints panel in DevTools has been redesigned for easier access and management. The Talk also covers the challenges of debugging with source maps and the efforts to standardize the source map format. Lastly, it provides tips for improving productivity with DevTools and emphasizes the importance of reporting bugs and using source maps for debugging production code.
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Today's Talk discusses the future of performance tooling, focusing on user-centric, actionable, and contextual approaches. The introduction highlights Adi Osmani's expertise in performance tools and his passion for DevTools features. The Talk explores the integration of user flows into DevTools and Lighthouse, enabling performance measurement and optimization. It also showcases the import/export feature for user flows and the collaboration potential with Lighthouse. The Talk further delves into the use of flows with other tools like web page test and Cypress, offering cross-browser testing capabilities. The actionable aspect emphasizes the importance of metrics like Interaction to Next Paint and Total Blocking Time, as well as the improvements in Lighthouse and performance debugging tools. Lastly, the Talk emphasizes the iterative nature of performance improvement and the user-centric, actionable, and contextual future of performance tooling.
pnpm – a Fast, Disk Space Efficient Package Manager for JavaScript
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
pnpm – a Fast, Disk Space Efficient Package Manager for JavaScript
Watch video: pnpm – a Fast, Disk Space Efficient Package Manager for JavaScript
pnpm is a fast and efficient package manager that gained popularity in 2021 and is used by big tech companies like Microsoft and TikTok. It has a unique isolated node module structure that prevents package conflicts and ensures each project only has access to its own dependencies. pnpm also offers superior monorepo support with its node module structure. It solves the disk space usage issue by using a content addressable storage, reducing disk space consumption. pnpm is incredibly fast due to its installation process and deterministic node module structure. It also allows file linking using hardlinks instead of symlinks.
Beyond Virtual Lists: How to Render 100K Items with 100s of Updates/sec in React
React Advanced 2021React Advanced 2021
27 min
Beyond Virtual Lists: How to Render 100K Items with 100s of Updates/sec in React
Top Content
The Talk discusses optimizing rendering of big tables using Flipper, a new version that is ten times faster with improved user interaction and richer data. It explores optimizing rendering with React, virtualization, filtering, sorting, and windowing techniques. The introduction of the Flipper Datasource packet simplifies handling updates, inserts, and removals. The performance of the Flipper data source package is excellent, even in a debug build of React, with minimal CPU usage. The Q&A session covers incremental sorting, dynamic row height, and the potential for two-dimensional virtualization in the future.
Debugging with Chrome DevTools
JSNation Live 2021JSNation Live 2021
11 min
Debugging with Chrome DevTools
Here are some tips for better utilizing DevTools, including using the run command, customizing keyboard shortcuts, and emulating the focus effect. Learn how to inspect memory, use the network panel for more control over network requests, and take advantage of console utilities. Save frequently used code as snippets and use local overrides for easy editing. Optimize images by using a more optimized format like AVIF and track changes in the network panel to see the reduced data size.
High-Speed Web Applications: Beyond the Basics
JSNation 2022JSNation 2022
30 min
High-Speed Web Applications: Beyond the Basics
This talk covers the latest features in Chrome DevTools, including network tab analysis, performance tab optimization, and user flows. It discusses optimizing HTTP requests with fetch priority to improve loading time. The performance tab provides insights on frame drops, long tasks, and the importance of minimizing total blocking time. The talk also highlights the optimization of page rendering and introduces user flows in Chrome DevTools.

Workshops on related topic

React, TypeScript, and TDD
React Advanced 2021React Advanced 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Mastering advanced concepts in TypeScript
React Summit US 2023React Summit US 2023
132 min
Mastering advanced concepts in TypeScript
Top Content
Featured WorkshopFree
Jiri Lojda
Jiri Lojda
TypeScript is not just types and interfaces. Join this workshop to master more advanced features of TypeScript that will make your code bullet-proof. We will cover conditional types and infer notation, template strings and how to map over union types and object/array properties. Each topic will be demonstrated on a sample application that was written with basic types or no types at all and we will together improve the code so you get more familiar with each feature and can bring this new knowledge directly into your projects.
You will learn:- - What are conditional types and infer notation- What are template strings- How to map over union types and object/array properties.
Integrating LangChain with JavaScript for Web Developers
React Summit 2024React Summit 2024
92 min
Integrating LangChain with JavaScript for Web Developers
Featured Workshop
Vivek Nayyar
Vivek Nayyar
Dive into the world of AI with our interactive workshop designed specifically for web developers. "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" offers a unique opportunity to bridge the gap between AI and web development. Despite the prominence of Python in AI development, the vast potential of JavaScript remains largely untapped. This workshop aims to change that.Throughout this hands-on session, participants will learn how to leverage LangChain—a tool designed to make large language models more accessible and useful—to build dynamic AI agents directly within JavaScript environments. This approach opens up new possibilities for enhancing web applications with intelligent features, from automated customer support to content generation and beyond.We'll start with the basics of LangChain and AI models, ensuring a solid foundation even for those new to AI. From there, we'll dive into practical exercises that demonstrate how to integrate these technologies into real-world JavaScript projects. Participants will work through examples, facing and overcoming the challenges of making AI work seamlessly on the web.This workshop is more than just a learning experience; it's a chance to be at the forefront of an emerging field. By the end, attendees will not only have gained valuable skills but also created AI-enhanced features they can take back to their projects or workplaces.Whether you're a seasoned web developer curious about AI or looking to expand your skillset into new and exciting areas, "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" is your gateway to the future of web development. Join us to unlock the potential of AI in your web projects, making them smarter, more interactive, and more engaging for users.
From Todo App to B2B SaaS with Next.js and Clerk
React Summit US 2023React Summit US 2023
153 min
From Todo App to B2B SaaS with Next.js and Clerk
WorkshopFree
Dev Agrawal
Dev Agrawal
If you’re like me, you probably have a million side-project ideas, some that could even make you money as a micro SaaS, or could turn out to be the next billion dollar startup. But how do you know which ones? How do you go from an idea into a functioning product that can be put into the hands of paying customers without quitting your job and sinking all of your time and investment into it? How can your solo side-projects compete with applications built by enormous teams and large enterprise companies?
Building rich SaaS products comes with technical challenges like infrastructure, scaling, availability, security, and complicated subsystems like auth and payments. This is why it’s often the already established tech giants who can reasonably build and operate products like that. However, a new generation of devtools are enabling us developers to easily build complete solutions that take advantage of the best cloud infrastructure available, and offer an experience that allows you to rapidly iterate on your ideas for a low cost of $0. They take all the technical challenges of building and operating software products away from you so that you only have to spend your time building the features that your users want, giving you a reasonable chance to compete against the market by staying incredibly agile and responsive to the needs of users.
In this 3 hour workshop you will start with a simple task management application built with React and Next.js and turn it into a scalable and fully functioning SaaS product by integrating a scalable database (PlanetScale), multi-tenant authentication (Clerk), and subscription based payments (Stripe). You will also learn how the principles of agile software development and domain driven design can help you build products quickly and cost-efficiently, and compete with existing solutions.
Building Pinia From Scratch
Vue.js Live 2024Vue.js Live 2024
70 min
Building Pinia From Scratch
Workshop
Eduardo San Martin Morote
Eduardo San Martin Morote
Let's dive into how Pinia works under the hood by building our own `defineStore()`. During this workshop we will cover some advanced Vue concepts like dependency Injection and effect scopes. It will give you a better understanding of Vue.js Composition API and Pinia. Requirements: experience building applications with Vue and its Composition API.
Mastering 3D Web Development with TresJS ecosystem: A Vue.js Workshop
Vue.js Live 2024Vue.js Live 2024
119 min
Mastering 3D Web Development with TresJS ecosystem: A Vue.js Workshop
Workshop
Alvaro Saburido
Alvaro Saburido
Introducing "Mastering 3D Web Development with TresJS," a specialized workshop crafted for Vue.js developers eager to explore the realm of 3D graphics within their web applications. TresJS, a powerful custom renderer for Vue, is specifically designed to work seamlessly with Vue's reactive system. This workshop offers a deep dive into integrating sophisticated 3D visualizations and interactive experiences directly into Vue applications, leveraging the unique strengths of both Vue and TresJS ecosystems.
This workshop is designed for Vue.js developers looking to expand their skill set into the third dimension, UI/UX designers interested in incorporating 3D elements into web applications, and front-end developers curious about the potential of 3D graphics in enhancing user experiences. You'll need to be familiar with Vue.js to benefit from this workshop fully.
What You Will Learn- Introduction to TresJS: Discover the fundamentals of TresJS and how it integrates with the Vue ecosystem to bring 3D graphics to life.- Creating 3D Scenes with Vue: Learn to construct intricate 3D scenes utilizing Vue components, enhancing your user interfaces with dynamic and immersive visuals.- Interactivity and Animation: Master the techniques to make your 3D scenes interactive, responding to user inputs for a captivating user experience.- Integrating with Vue Features: Explore advanced integration of TresJS with Vue’s reactivity, composables, and the Vuex store to manage state in 3D web applications.- Performance and Best Practices: Gain insights into optimizing your 3D scenes for performance and best practices to maintain smooth, responsive web applications.