May 202559:3425.1k views

How Durable Objects and D1 Work: A Deep Dive with Cloudflare’s Josh Howard

About

Josh Howard, Senior Engineering Manager at Cloudflare, joins me to explain how Durable Objects and D1 work under the hood—and why Cloudflare’s approach to stateful serverless infrastructure is so unique. We get into V8 isolates, replication models, routing strategies, and even upcoming support for containers.

Transcript

Everything we said

00:01

Aaron Francis

Hello, my friends. Welcome back to Database School. We've, we've been having a lot of great episodes recently, and this is no exception. Today, I am joined by Josh Howard, senior engineering manager at Cloudflare, and I think we're gonna talk about a lot of things, databases included. But Josh, welcome to the show, and do you want to introduce yourself?

00:21

Josh Howard

Yeah. Absolutely. So my name's Josh Howard. I'm a senior engineering manager at Cloudflare. I'm responsible for the Durable Objects and D1 products at Cloudflare, and I've been working at the company for about 18 months now.

00:33

Aaron Francis

Oh, nice. Okay. So Josh, I'm gonna hit you with a question right up front, and you know, you'll have to forgive me. What exactly is a durable object? Can we, can we start there, or do we need to back up even further?

00:45

Josh Howard

Uh, no, I mean, I... It's a, it's a great place to start, right? Uh, the, the answer is probably gonna cause us to back up further immediately.

00:52

Aaron Francis

Perfect.

00:53

Josh Howard

But, um-

00:53

Aaron Francis

I love it

00:53

Josh Howard

... the, the durable objects is a primitive for building stateful serverless applications, right?

00:58

Aaron Francis

Okay. Let's slow down. It is a primitive for building stateful-

01:03

Josh Howard

Yes

01:03

Aaron Francis

... serverless-

01:04

Josh Howard

Yes

01:05

Aaron Francis

... applications. Okay. I like that. Those are important words. Stateful serverless applications. All right, keep going.

01:11

Josh Howard

Yeah. So I think, you know, to kind of unpack why that is important, you kind of have to think about like, you know, what other offerings are available at Cloudflare, right? And so the cloud's been around for a long time. Um, you know, the cloud kind of means that, you know, you're, you're running a server that somebody else is operating. Traditionally, serverless has meant that you're running a container that somebody else is operating.

01:34

Cloudflare has a different technique for obtaining a serverless application than any other company that I'm aware of. Um, they use a technology called V8 isolates to actually isolate-

01:46

Aaron Francis

Okay

01:46

Josh Howard

... customer code from, you know, customers' code from one another. And, um, that provides a much lighter weight serverless application than what any other cloud provider has. And so that's kind of the key differentiator of Cloudflare. And, um, you know, so that's, that's the serverless piece, but, uh, do you have a, a question there?

02:07

Aaron Francis

Yeah. So how... Help me understand, um, the difference between a V8 isolate and what I assume everybody else is doing, and is that Firecracker?

02:17

Josh Howard

Yeah. Firecracker is a newer VM technology that-

02:21

Aaron Francis

Okay

02:21

Josh Howard

... supports a lot of the other cloud providers. I think it came out of AWS, but I, I know of other places that are using it now.

02:28

Aaron Francis

Mm-hmm.

02:28

Josh Howard

Um, V8 isolates are actually the same things that isolate your Chrome tabs from one another, right?

02:33

Aaron Francis

Got it.

02:33

Josh Howard

Uh, it's, uh, predominantly thread level, or it, it's, the most important thing is it's thread level isolation. So, um, you don't have the overhead of doing a context switch between processes, um, whenever you're actually switching between executing different customers' code. You just have threads. And, um, each of those threads are given their own resources, um, and they're, they're effectively namespace, so they, they can't conflict with one another and can't ac- access state from each other.

03:01

Aaron Francis

Okay. And this, uh, did this come out of, did this come out of Chrome, or was this something that, uh, I guess, I don't know who the working body for JavaScript is. Where did this V8 isolate thing come from?

03:14

Josh Howard

Yeah. I believe it came from Chrome. Like, this is-

03:17

Aaron Francis

Okay

03:17

Josh Howard

... uh, I think it, it was around like the early 2010s timeframe.

03:21

Aaron Francis

Oh, wow.

03:21

Josh Howard

So definitely before I was involved working on this. But, um, I believe it came out of Chrome. It's a bit-

03:27

Aaron Francis

Okay

03:27

Josh Howard

... of my time though.

03:28

Aaron Francis

Okay. Thank you. That's helpful. So that, that is a little bit of the serverless side of it. So there is, there has existed a model which is Firecracker. Uh, in the browser, there has existed a model V8 isolates, and y'all took V8 isolates and took them out of the browser and put them more at the server level, even though it is serverless.

03:50

Josh Howard

Exactly

03:50

Aaron Francis

... so what is the, what is the stateful part of stateful serverless, a primitive for building stateful serverless app, uh, applications. What's the stateful part?

03:59

Josh Howard

Yeah, exactly. So, um, and, and, you know, Workers is that, you know, stateless, uh, serverless offering that's on Cloudflare, right? And the, the thing that Durable Objects really provides is state. And what you need in order to have local state is you need to be able to consistently route requests to a single place globally. So you can imagine with Workers, they run everywhere.

04:21

Um, you can submit requests to Workers. Um, different clients on different sides of the world can submit the same request. They can go to different workers. There's no effective mechanism to access, you know, a, a database or that, that's local to either of them. And so what Durable Objects give you an API to do is allow that worker to forward a request to a durable object, and that forwarding of the request will go to a single place globally, and that durable object can access its local state.

04:51

You can do things that make sense to only do once or only do in one part of the world, like access local disk, access, you know, a database, access a local container. Um, Durable Objects is kind of the API for coordination between Workers, and then once you have that coordination, you can do all types of cool things, so.

05:10

Aaron Francis

So are durable objects, um, are they kind of like Workers plus plus? Are they built on top of Workers and add in some other things, or is it a fundamentally... You said Workers can route to a durable object. Can you explain that, uh, process a little bit more? Hey, I hope you're enjoying this.

05:31

Just as a reminder, you can learn more about SQLite at highperformancesqlite.com. I'll get out of your way. Back to the interview.

05:40

Josh Howard

Yeah, exactly. So, um, they're essentially just all isolates. So Workers run in isolates. Durable Objects run in isolates. Workers differ from Durable Objects in the fact that we expose different APIs because, again, some things only make sense to do from one place, right?

05:56

Aaron Francis

Got it.

05:56

Josh Howard

So we're not going to expose like, you know, a SQLite interface to a worker directly because it doesn't really make sense if you can't return to the same place, you know, to access that same SQLite database, right?

06:09

Aaron Francis

Right

06:09

Josh Howard

So, um, that's kind of... They're essentially both isolates, but they have different capabilities. And, um, so that, that's, that's the way that they're different. The routing piece is actually super interesting. Um, so, you know, we can maybe double-click into how routing works.

06:25

Aaron Francis

Please.

06:26

Josh Howard

Um, but from a user perspective, what this looks like is you basically, you know, will get a durable object ID. You can think of it as like an instance ID or something like that. Durable objects are defined as a JavaScript class. And so you use the API to get an instance ID. You call get on that instance ID, and you get this thing called a stub, and that stub can be used to, you know, invoke methods on that remote object via RPC calls.

06:53

Aaron Francis

Okay

06:54

Josh Howard

... that's what it looks like for somebody who's actually writing durable object code.

06:59

Aaron Francis

Mm-hmm.

07:00

Josh Howard

Um, but the way the routing works under the hood is actually really interesting because, you know, that ID is globally unique, and we can get into how we kind of make that globally unique if that's interesting.

07:12

Aaron Francis

Mm-hmm.

07:12

Josh Howard

But once you have that globally unique ID, you get a stub and the routing for that effectively means that we have to say, where does this ID belong to? What region of the world?

07:23

Aaron Francis

Mm.

07:23

Josh Howard

Go to that region of the world, um, you know, figure out what individual metal is or server is- ... running that ob- that object, and either if there is one, then route to that metal, otherwise go wake up the object, uh, and then assign it to some metal for it to, to run. So, um, there's a lot of details in there, but, um, you know, that, that's, that's the high level of like how you interact with these objects and how you handle routing.

07:50

Aaron Francis

Okay. We need to come back to the globally unique IDs because of course that's interesting. You said if that's interesting. Obviously that one is interesting.

07:58

Josh Howard

Yeah.

07:58

Aaron Francis

But here's my question first. So with the, with the durable object, um, the part that makes it durable is the state. Is that right? Is that where the naming kind of comes from?

08:09

Josh Howard

Yes.

08:09

Aaron Francis

That's why it's called durable? Okay.

08:11

Josh Howard

Yeah.

08:11

Aaron Francis

Um, so the part that makes it durable is the state, and you all decided that instead of letting, uh, workers from anywhere access state in a single point, you decided the durable object's compute is gonna be right next to the state. Is that a fair characterization?

08:31

Josh Howard

Yes. Yes.

08:32

Aaron Francis

Okay.

08:32

Josh Howard

Exactly.

08:33

Aaron Francis

So instead of saying, uh, yeah, it's durable because you have some attached storage that's never gonna go away and you can count on it, you said, yeah, it's durable because you have some storage but it's also right next to the compute. So what was the calculus in making that decision? I understand there must have been dozens of trade-offs, but what pushed y'all in that direction?

08:53

Josh Howard

Yeah, I mean, it, it is a really great question because, um, th- there's... I, I mean, there, there's a whole lot of things that having... I mean, I, I kind of framed it upfront as like a coordination point, right?

09:05

Aaron Francis

Mm-hmm.

09:05

Josh Howard

And coordination is kind of a, a core capability that, you know, having state in addition to coordination is, is, is useful. But like you can imagine stateless durable objects that still do really cool things, right? Um, a great example of this is like, uh, if you want to have, you know, a chat room or something like that, and even if messages are ephemeral, right?

09:26

You still need to be able to say, you know, open a connection to some chat room, right? And be able to, um, you know, send a message to that chat room and even if you're immediately broadcasting it out and not storing anything, right? Um, being able to coordinate, you know, is, is still a valid, you know, capability. So our perspective is that, you know, you need that coordination point and that unlocks a whole host of cool applications that just are not really approachable, you know, with a

09:57

standard three-tier web app, right?

09:59

Aaron Francis

Mm-hmm.

09:59

Josh Howard

Um, but once, you know, once you have that you can layer in state. Um, it's no longer, uh, uh, an expensive operation to go back and forth to your database, you know, hundreds, thousands of times if you have compute that is local to your database, right? Um, we can get a little bit more into like how we make that incredibly performant because it is, I mean, I think like, you know, we can actually do storage operations on the order of microseconds which is like pretty awesome.

10:26

Um, so yeah, I mean like, you know, we, we can go however you want to go here but, uh, you know, there, there's a bit to, to unpack.

10:34

Aaron Francis

So, uh, you gotta help me understand a stateless durable object. What, what does that, what does that part mean? There are so many, there are so many things about durable object- objects that I've yet to wrap my head around. All I see is, uh, Sunil posting about them all the time and all the amazing things that they can do and I'm like, I gotta know what these things do.

10:55

So stateless durable object, t- tell me more about that. What does that mean?

11:00

Josh Howard

Yeah, I mean it's, it's just a, a... You can imagine writing an application, you know, referencing it where a worker references a durable object and that durable object never touches the storage API. Um, maybe that means that, you know, you want to, um, like, you know, the lifetime of a durable object is by default 10 seconds, right?

11:19

Aaron Francis

Okay.

11:20

Josh Howard

You could imagine that you have all the workers in the world, you wanna make sure that those workers are not individually like bombarding some upstream resource.

11:29

Aaron Francis

Mm-hmm.

11:29

Josh Howard

You wanna do some sort of like batching of operations. So you could say like all workers have this like, you know, reference to a batcher durable object, right? And every, you know, 10 seconds before it goes out of memory it's gonna say, "Take all those requests I got, dedupe them, do some operations to like, you know, streamline things and then send them to this upstream resource." That, you know, durable object is never going to touch storage in this case.

11:55

You know, you could make it touch storage if you wanted to do something else-

11:58

Aaron Francis

Sure

11:58

Josh Howard

... but like it doesn't have to, right? Um, there are simpler things that you can do where, you know, you don't ever have to touch storage and it can still do useful things, right? So, you know, maybe you want to batch on a longer timeframe, you don't want to rely on that in-memory state and then you save all these requests to local storage and then you, you wake the durable object up at some point in the future, you know, days, weeks, years later I guess and then you-

12:22

Aaron Francis

Mm-hmm

12:22

Josh Howard

... you know, send all those requests upstream. But you don't necessarily have to touch storage to make use of durable objects.

12:28

Aaron Francis

That makes sense. So, uh, in, in a stateless durable object situation, you're basically just keeping all that stuff in memory, and you have one unique point that everyone else can talk to that can coordinate everything.

12:43

Josh Howard

Yeah, exactly.

12:44

Aaron Francis

Okay.

12:44

Josh Howard

You, you can think of it as, like, connection pooling. Like, that, that's the-

12:47

Aaron Francis

Uh-huh

12:47

Josh Howard

... the common example we get, um, for, for stateless applications.

12:51

Aaron Francis

And when these things, when these things go to sleep, do they wake up in the exact same state, uh, that they went to sleep in?

12:59

Josh Howard

Yeah, that's a good question. So, so they do not wake up by default in the same state that they fell asleep in, right?

13:05

Aaron Francis

Okay.

13:06

Josh Howard

Um, whenever they wake up, the, uh, constructor of the object will actually run, right? And so you-

13:11

Aaron Francis

Got it

13:11

Josh Howard

... can have that constructor reconstruct whatever state you want, right?

13:14

Aaron Francis

Okay.

13:15

Josh Howard

But by default, you know, it's just you- whenever they, they wake up, they are assigned to an isolate. Um, you know, you can, you know, pre-populate from storage whatever in-memory state you want.

13:26

Aaron Francis

Mm.

13:26

Josh Howard

Um, but we don't like, uh, it's, it's actually, like, a, a common misconception. We've had several people, like, ask like, "Oh, will you repopulate, like, variables-

13:35

Aaron Francis

Mm-hmm

13:35

Josh Howard

... in memory?" And it's-

13:35

Aaron Francis

Right, yeah

13:36

Josh Howard

... we're, we're not, we're not, like, uh, trying to introspect on your code and, like, interpret it differently.

13:42

Aaron Francis

Right.

13:42

Josh Howard

Like, it, it's just JavaScript. It works the same way you would expect JavaScript to work, right? It's just that, you know, whenever we wake that up, we give you a hook, which is a constructor, to actually-

13:52

Aaron Francis

Mm

13:52

Josh Howard

... go and reconstruct whatever state you want.

13:54

Aaron Francis

Okay. Well, I'm glad, I'm glad I had the same misconception as the people. That means I'm still speaking for the people. That's a good thing.

14:00

Josh Howard

Cool.

14:00

Aaron Francis

So when it goes to sleep-

14:01

Josh Howard

Yeah

14:01

Aaron Francis

... does it have a hook for you can serialize all your important state into some storage, and then you can use it again in the constructor?

14:09

Josh Howard

Yeah, so that's, that's a good question. Uh, we do not have a destructor hook, right?

14:13

Aaron Francis

Okay.

14:14

Josh Howard

And the reason being is that it's very hard to guarantee in all cases that a destructor will run.

14:20

Aaron Francis

Hmm.

14:20

Josh Howard

Um, you know, you have things like runtime crashes.

14:23

Aaron Francis

Mm-hmm.

14:24

Josh Howard

Customer code can crash. Um, you know, it's just we cannot guarantee, uh, invariably that that destructor will always run, right? And so for that reason, we've avoided adding a, you know, destructor hook. Even if we can have, you know, if, if even if we think we have 12 nines of reliability for that destructor hook running, there's always gonna be some edge case where it didn't-

14:47

Aaron Francis

Yeah

14:47

Josh Howard

... run, right? And so we're very, you know, conservative on, like, the tools that we give our customers, especially with DO, because we wanna make sure that people can write code that they can reason about, uh, invariably. And so, um, you know, there are ways to write applications, though, to where, like, you know, for every in-memory state, you can do a write to local storage. As I mentioned, writes to storage are incredibly fast, right?

15:10

So, um, I would honestly, uh, a- avoid, uh, keeping things in memory and not syncing to local storage unless it becomes cost-prohibitive, like, which it can in some, some cases.

15:22

Aaron Francis

Okay, that makes sense. Uh, and I agree with you on the if we can't do it perfectly, let's not do it, 'cause somebody's gonna rely on it, and it's gonna go sideways, and y'all are gonna get y'all are gonna get in trouble for it.

15:32

Josh Howard

Th- there's some metric of like, uh, and I, I haven't... This isn't, like, fully, uh, well-defined, but, like, there's some metric of, like, preventing regrettable debugging experience.

15:44

Aaron Francis

Mm.

15:44

Josh Howard

And, and I think that's the actual thing that you wanna optimize as a developer platform. It's, you know, there's, there's a lot of things you can add to increase development velocity and things like that, but it's like the thing that just is going to completely railroad your day is whenever there's some concurrency bug that, you know-

16:00

Aaron Francis

Mm

16:00

Josh Howard

... is confusing and, like, you know, you spend 12 hours fixing this one thing because, you know, it, it just doesn't work the way you expect. I think those experiences are the things that you really want to prevent. Um-

16:12

Aaron Francis

Yeah.

16:13

Josh Howard

Yeah.

16:13

Aaron Francis

And, and doubly so when it's outside of my control as the developer. When the platform doesn't call my destructor, then I'm, I'm totally in the dark, and that's really frustrating.

16:22

Josh Howard

Exactly. Yeah.

16:23

Aaron Francis

So you said, uh, you said there for a second, uh, you would recommend writing to local storage. So local storage is both, uh, a term of art and a just generic descriptor. So in what, what way are you using it? Are you saying storage that is local? Because local storage is, like, a, a browser thing, so can you differentiate-

16:43

Josh Howard

Oh, yeah, yeah

16:43

Aaron Francis

... this for me?

16:45

Josh Howard

Yeah. Yeah, so in this case, I'm talking about the, the Durable Object storage, right?

16:48

Aaron Francis

Okay.

16:48

Josh Howard

So, um, we have two APIs for interacting with Durable Object storage.

16:53

Aaron Francis

Mm.

16:53

Josh Howard

And that's either through a KV API or a SQLite API, right? And so, you know, historically, we only had a KV API. We released a SQLite API last fall. Um, and, um, but that's, you know, you, you can interact with local storage. It's persistent. Uh, it's durable. It's replicated. Uh, we can get into how we do that efficiently, but, um, you know, that's, that's the, you know, way to actually make sure that, you know, whatever in-memory state you have, as long as you're flushing that to storage,

17:23

it's gonna be durable, and it's going to be available, you know, upon, like, after the Durable Object sleeps, and then you don't have to have complicated logic in your constructor.

17:32

Aaron Francis

Mm-hmm. So, uh, KV and, uh, D1 are both available as standalone offerings. Is that correct?

17:43

Josh Howard

Um, so Workers KV and Workers D1 are different products than Durable Objects. Um-

17:50

Aaron Francis

Okay

17:50

Josh Howard

... naming is hard. Um-

17:53

Aaron Francis

I'm glad you're, I'm glad you're laughing 'cause I'm like, wait, what? Okay.

17:56

Josh Howard

Yeah, yeah.

17:56

Aaron Francis

That makes me feel better.

17:57

Josh Howard

No, no, great, great question because we get this all the time, right? Like, naming is hard. Um, so, so Durable Objects have a KV and SQLite interface to their local storage. We have a separate product called Workers KV and D1-

18:13

Aaron Francis

Mm

18:13

Josh Howard

... which give a worker, uh, access to a distributed KV store or-

18:18

Aaron Francis

Mm-hmm

18:18

Josh Howard

... a, uh, SQLite database. So-

18:22

Aaron Francis

Okay

18:22

Josh Howard

... both of those, like, I would say both of those things predate Durable Objects in their own ways. I mean, it's, it's ... The actual sequencing here is that Workers KV came out in, I believe, 2019.

18:33

Aaron Francis

Mm.

18:33

Josh Howard

Um, D1 came out, or Durable Objects came out in '21. D1, which was the first SQLite backed product that we had, came out-

18:41

Aaron Francis

Mm-hmm

18:41

Josh Howard

... shortly after that, and then we brought SQLite storage to durable objects, um, you know, after, after D1. So, uh-

18:49

Aaron Francis

Okay

18:49

Josh Howard

... there's been a little bit of a confusing history. Um, you know, it, it is hard to parse what product you should use when.

18:57

Aaron Francis

Okay. Okay, that's helpful. So, um, when we're talking about durable objects and we're talking about SQLite storage, or I guess you called it as a SQL interface and a KV interface-

19:09

Josh Howard

Mm-hmm

19:10

Aaron Francis

... those are fundamentally local to the specific durable object, and therefore not reachable from, uh, workers KV. Like, they're completely, they're completely-

19:23

Josh Howard

Yeah

19:23

Aaron Francis

... separated.

19:24

Josh Howard

Completely separate. Yeah.

19:25

Aaron Francis

Okay. Perfect.

19:26

Josh Howard

Yeah.

19:26

Aaron Francis

Okay. That makes sense. So then your two storage options over in durable objects land are, um, a SQLite backed, I think you called it SQL, SQL interface, and a KV store.

19:39

Josh Howard

Mm-hmm.

19:39

Aaron Francis

Is that correct? Those are your two options?

19:41

Josh Howard

Yeah, so those are the two like APIs that we offer up. It's actually-

19:45

Aaron Francis

Mm-hmm

19:45

Josh Howard

... all of it's SQLite backed, right? So our, our KV-

19:47

Aaron Francis

Hmm

19:47

Josh Howard

... our KV interface, you can actually go and show tables on the, the SQLite instance that is backed or is backing the DO.

19:56

Aaron Francis

Mm-hmm.

19:56

Josh Howard

And you'll see a table that's like _CF_KV.

20:01

Aaron Francis

Mm-hmm.

20:01

Josh Howard

Um, that, that's the KV storage, right? So it, it's just-

20:04

Aaron Francis

Ah, SQLite. Just use it for everything. I love that.

20:07

Josh Howard

Well, it's, you know, we, we have this problem because, you know, we had a, a, a previous storage back end that was only KV-based, and it had a, a bunch of problems, right? And so we've essentially shifted to using this new back end, um, and encour- we're encouraging all new customers to use the SQLite back end. But in order to make that transition easier, we wanted to have API compatibility, right?

20:30

Aaron Francis

Hmm.

20:30

Josh Howard

So you can actually just deploy the same code using the SQLite back end, and it will run just fine. Um, it, it's backward compatible. Um, we just, you know, needed to maintain that interface, um, because, you know, believe it or not, some people like key value interfaces more than SQL. It's shocking, but-

20:48

Aaron Francis

The nerve. The nerve on these people. Okay.

20:51

Josh Howard

Yeah.

20:51

Aaron Francis

Um, how do you get these writes to be, or this communication, I guess, reads and writes, to be so lightning fast between this, this local storage for your durable objects?

21:03

Josh Howard

Um, yeah. So I, I think like one of, one of the things that's interesting is like people assume that, you know, writes need to be, you know, asynchronous because they're necessarily slow. The operating s- op- operating systems are great. They do a lot of stuff for us. Um, so if you're doing, you know, writes to storage, uh, most likely that write is going to be cache in memory, and it's going to, you know, work on the order of microseconds, right?

21:29

Like, so, so if I'm writing to disk without flushing, that write is going to succeed in, you know, in, in microseconds. Um, the issue becomes like it's not flush to disk, it's not confirmed durable, right? And so what we have to do there is we essentially replicate that write out to a set of followers, uh, through this service that we call, uh, the storage relay service.

21:52

So, um, whenever a durable object writes, and again, this is nothing that anybody, you know, has to worry about, but like-

22:00

Aaron Francis

Mm-hmm

22:00

Josh Howard

... it's fun.

22:00

Aaron Francis

But it's super interesting.

22:02

Josh Howard

Yeah, exactly, right? Like, y- you know, if you, if you, you know, i- if you, you know, don't care how this works and you just wanna use it, you don't have to listen to this, but like this is the cool part in my opinion. So, um, you know, basically we have this storage relay service where we have on the same metal that a durable object is running, we have this leader, which is going to be looking for writes to SQLite.

22:23

Aaron Francis

Okay.

22:23

Josh Howard

And whenever a write comes in, that leader is going to say, um, "I'm going to, you know, take that write. I'm gonna replicate it to followers." Okay? And then it will be confirmed durable whenever the followers accept that write. Okay? Um, and then so the application can go on and write, you know, do whatever it needs to do, and then, um, once all of those writes are confirmed durable, then it will be allowed to return, right?

22:52

We call this feature output gates. So it, it, it's kind of interesting. We get a lot of questions about it, b- but we don't have to wait for every individual write to be confirmed for the durable object to proceed.

23:06

Aaron Francis

Right.

23:06

Josh Howard

This is another benefit of having, you know, compute tied to storage. We just have to make sure that all writes are confirmed durable by the time the durable object has some side effect which is observable to the outside world. So you can think about that maybe from the perspective of if you're a worker requesting to that DO, everything is synchronously replicated.

23:28

You don't get a response back from that DO until everything has been confirmed durable.

23:32

Aaron Francis

Hmm.

23:32

Josh Howard

The DO itself can go ahead and optimistically write and do other things as long as it's not communicating externally, and that- ... replication from the DO's perspective is purely asynchronous, and you never have any side effects because we control all input and output to that durable object.

23:54

And so you can do, you can do things to where you have like, literally, you know, microsecond level writes and, you know, you can do other computation around that. As long as you're not causing side effects to the outside world, um, you know, there, there's no harm in going ahead and optimistically doing things without, without, uh, having those writes confirmed durable.

24:13

Aaron Francis

All right. Here we go. I'm gonna say it back.

24:16

Josh Howard

Okay.

24:16

Aaron Francis

And you're gonna be gentle with me. Okay? Um, all right. So what you're telling me is that a request can come in from the outside world, we'll say it's from workers, into a durable object.

24:27

Josh Howard

Mm-hmm.

24:28

Aaron Francis

And that crosses some sort of boundary, right? In-

24:31

Josh Howard

Yes

24:31

Aaron Francis

... we're inside the durable object now. Now, when, when we're inside the durable object, we can bounce around as much as we want, doing as many writes as we want, without waiting for confirmation that all writes have been replicated. But the moment that we try to go back across that boundary, back to, uh, what is the outside world from the perspective of the durable object, once we try to cross back out, then we're halted at the door until

25:01

all of that, all of those writes have been replicated and proved durable.

25:07

Josh Howard

Yes, exactly.

25:09

Aaron Francis

All right.

25:09

Josh Howard

Yeah.

25:10

Aaron Francis

Just a straight yes. That was great.

25:11

Josh Howard

It was easy.

25:11

Aaron Francis

No notes.

25:12

Josh Howard

It was-

25:12

Aaron Francis

No notes.

25:13

Josh Howard

The, the only caveat I would-

25:15

Aaron Francis

Ah, there's a note.

25:16

Josh Howard

It's, that was-

25:16

Aaron Francis

That was a note.

25:17

Josh Howard

No, no, no. Well, uh, uh, it doesn't really, uh, it, it's, uh, I did not cover this case, but, like, it's not just returning back to the worker, it's any side effect. So we will actually-

25:27

Aaron Francis

Any side effect

25:28

Josh Howard

... we will actually, like let's say that you, uh, read some data, write some data, um, and then you want to make a fetch request from that durable object. We'll actually gate that fetch request until the write is confirmed durable, right? Because it-

25:41

Aaron Francis

Got it

25:41

Josh Howard

... it's no side effects are allowed, right?

25:44

Aaron Francis

Got it. Okay. And what is the mechanism by which you're observing SQLite listening for those, listening for those writes? Is it some sort of virtual file system? Is it some sort of, you know, WAL thing? Like, what are y'all doing down there?

26:00

Josh Howard

Yeah. So, uh, we do hook into, um, we, we do hook into the WAL at, at the VFS layer, right?

26:06

Aaron Francis

Okay.

26:06

Josh Howard

So we're, we're replicating the WAL, um, and then, uh, we, we hook into SQLite at the VFS layer, which is, I guess, for, for your listeners, like it's the original interface for interacting with different operating systems, which has been, uh, used for far more than that, I guess. Uh-

26:24

Aaron Francis

Yeah

26:25

Josh Howard

It's, yeah.

26:25

Aaron Francis

It's like, it's like one of the only ways into SQLite, and so everybody takes over and does some wonky stuff down there.

26:31

Josh Howard

Yeah.

26:31

Aaron Francis

Okay.

26:32

Josh Howard

Yep, exactly. It's, it's one of the few ways that you can, um, you know, contribute, uh, or make, make meaningful changes to SQLite.

26:39

Aaron Francis

Mm-hmm.

26:40

Josh Howard

Yeah.

26:40

Aaron Francis

Unless you wanna fundamentally rewrite the whole thing, which people are doing, so this feels-

26:45

Josh Howard

They're doing, yeah

26:45

Aaron Francis

... this feels a lot easier to me. Um-

26:47

Josh Howard

Yep

26:48

Aaron Francis

... okay. So at that point, after, um, you know, the, the request comes in, bounces around, and then it's confirmed durable, how, like, what is the, um, what's the durability look like? So you're on a single, you're on a single machine with your compute and your storage, and then where are we replicating that out to?

27:10

Josh Howard

Mm-hmm. Yep. Um, so we do, uh, five-way replication to the five nearest data centers, uh, for any, every single durable object. And so, you know, if you're in, I, I'm in Austin, right? So we would just pick, you know, the five closest data centers, which are probably like Dallas, Houston, probably Denver, uh, and, and some other cities.

27:32

Um, you know, we'd pick the five closest data centers and replicate across those. And so that is for, you know, the, the standard like leader-follower loop. There's a second path here which we have for long-term durability, which is basically that, you know, all of these things are stored at, you know, Cloudflare's edge, right?

27:49

Aaron Francis

Mm-hmm.

27:49

Josh Howard

Um, the edge is just more expensive than large hyperscaler data centers, right? So I think like our cost for storing things, though they are incredibly cheap, um, it's, it's still like an order of magnitude higher than like blob storage, right? So, um, eventually, like the followers, uh, you know, they don't retain that data forever. Either the followers or the leader will eventually upload that data to cold storage for, for safekeeping.

28:13

Um, so-

28:14

Aaron Francis

Mm

28:14

Josh Howard

... that's, that's eventually where it ends up for durability. But, you know, we don't rely on, uh, cold storage confirming that for us to consider it durable. That, that's, the followers are actually ensuring that it's durable.

28:27

Aaron Francis

That makes sense. So you write it to the primary, then five other places get it.

28:33

Josh Howard

Mm-hmm.

28:34

Aaron Francis

And then does that, is that cold storage, uh, eventually R2?

28:39

Josh Howard

Um, ish. I would love for it to be R2. It, it would be great- ... if it could be R2. Uh, I hope that it is R2 one day. We have this problem today because R2 depends on durable objects.

28:50

Aaron Francis

Yikes.

28:51

Josh Howard

So, uh, yeah. Like, we, we can't depend on-

28:54

Aaron Francis

No

28:54

Josh Howard

... R2 for this because R2 depends on us. So we actually, we actually use Google Cloud Storage.

29:00

Aaron Francis

Okay.

29:00

Josh Howard

Um, but, you know, the reason for that is just to avoid the circular dependency. Um, there is a plan, you know, in the limit to have R2, uh, stop depending on durable objects-

29:10

Aaron Francis

Mm-hmm

29:10

Josh Howard

... so we can, you know, actually use R2 instead of, instead of GCS. Um, but for the time being, yeah, GCS is what we depend on for ultimate durability.

29:19

Aaron Francis

Yeah, that makes sense.

29:20

Josh Howard

Yeah.

29:20

Aaron Francis

That's like the time ... I, I forget what happened at Facebook, but Facebook crashed so hard that they couldn't badge in 'cause everything else required on everything else or depended on everything else, and it was like, "Oh, shoot, didn't really see this one coming."

29:33

Josh Howard

Yeah. Yeah.

29:33

Aaron Francis

So yeah, that makes sense to me.

29:35

Josh Howard

Yeah.

29:36

Aaron Francis

Um, okay. So what are, uh, what are the trade-offs of having durable objects tied to a single ... Do you call them locations or, or regions or data centers? What, what do y'all call them?

29:49

Josh Howard

Um, it, we call them colos internally, but, like data centers-

29:53

Aaron Francis

Oh, wow

29:53

Josh Howard

... is, is the-

29:53

Aaron Francis

Data centers.

29:54

Josh Howard

Yeah. Data center is the-

29:55

Aaron Francis

Since I'm external, I'll call it a data center.

29:57

Josh Howard

Yeah.

29:57

Aaron Francis

So y'all, y'all have this big, you know, um, most of your products are, you know, region Earth, and it's like, oh, that's kinda cool.

30:05

Josh Howard

Yeah.

30:05

Aaron Francis

And then durable objects are tied to a specific data center. So one, what are the trade-offs? And then two, what are, uh, what are the ways that people can reason about choosing the right one, given that they may have customers everywhere?

30:20

Josh Howard

Yeah. So, um, this is, uh, like durable objects w- would like to, uh, have our customers just think everything is region Earth.

30:30

Aaron Francis

Mm-hmm.

30:30

Josh Howard

Like, we, we don't want people to have to worry about individual data centers, and so we will try to make that as much of a reality as we can, um, you know, with varying degrees of success, right? So, um, durable objects are tied to a particular colo at any point in time. We can move durable objects Right. Um-

30:49

Aaron Francis

Oh

30:49

Josh Howard

... we can do that in the case of, like, colos going offline. That happens all the time, right? And so what we generally have is that durable objects belong to a certain region, and then if any colo within that region is experiencing difficulties, then we, it will automatically be adopted from another, from another-

31:06

Aaron Francis

Hmm

31:06

Josh Howard

... colo in the region, and users don't have to worry about that. It's just, you know-

31:10

Aaron Francis

That's good

31:10

Josh Howard

... they're, they're inherently regional, and they can bounce around within that region to, to deal with, you know, issues or maintenance or whatever, right? Um-

31:19

Aaron Francis

And sorry, when we, when we build a, when we declare a durable object, what are we declaring? Region level? Surely not colo level from the customer's point of view.

31:29

Josh Howard

You don't have to declare anything. By default-

31:32

Aaron Francis

Oof. Okay

31:32

Josh Howard

... it will be placed near where it is first requested, right?

31:36

Aaron Francis

Huh. Interesting.

31:37

Josh Howard

If that's not a good, if, if that's not good enough for you, right, uh, a lot of people will pre-create durable objects for certain reasons. I, I-

31:44

Aaron Francis

Okay

31:44

Josh Howard

... like, you know, maybe... I actually don't have a great example of why that, why you'd need to do that. But it, it has got-

31:50

Aaron Francis

But people are doing it.

31:51

Josh Howard

Pe- people have done it, right? Um, I, I think mostly, like, just because they thought they had to. But-

31:59

Aaron Francis

Yeah

31:59

Josh Howard

... uh, you know, it, you don't have to, but, but people do it. And so we do support, like, region hints to where you can say, like-

32:05

Aaron Francis

Got it

32:05

Josh Howard

... "I think this durable object is going to be best placed, you know, in, in APAC or in North America or, you know, wherever." Um, but so you, you can pre-create them and place them around the world, you know, however you like, but you don't have to, right? Um, and so, you know, what we want to actually focus on in the future is, like, improving our placement algorithms because-

32:28

Aaron Francis

Mm

32:28

Josh Howard

... um, you know, it, it's, like, right now, like, literally we place them where the first requester was or as close to that as we can get, and remarkably few people have complained about that. Like, that was my, like-

32:39

Aaron Francis

That's pretty reasonable.

32:40

Josh Howard

I mean, that was my first thing. Like, whenever I came in, it was like, "So how does this placement stuff work?" And somebody told me that, I was like, "No way. Like, we've gotta have like a million complaints about that. Like, that, like people have to be berating us on that." And, um, like it's maybe come up once or twice in like a year now.

32:56

Aaron Francis

Wow.

32:57

Josh Howard

Like, y- yeah. Like, and I don't know if it's, like, people just don't know to ask or what.

33:01

Aaron Francis

Mm.

33:01

Josh Howard

But like, you know, it, it is genuinely, like, just it seems good enough for everybody, surprisingly. So, you know.

33:07

Aaron Francis

Mm-hmm.

33:08

Josh Howard

Anyway, would love to improve that in the future, but, you know, uh, we'll wait until people, uh, complain. I'm hoping that, you know, please complain. Um-

33:15

Aaron Francis

Yeah. You want it changed.

33:17

Josh Howard

Yeah. I, I want, I want to go solve this problem, right? Um, so but yeah. So, so generally, like, you don't have to do anything. Um, placement should work, you know, for, for most use cases or has historically worked for most use cases. And um, you know, there are other things you can do. You can also specify jurisdictions if there are compliance reasons why-

33:35

Aaron Francis

Mm

33:35

Josh Howard

... you can't locate durable objects some places. Um, you can say that, like, "I need a durable object which stays, you know, within, you know, uh, the US for, like, FedRAMP or, like, within the EU for, you know, other compliance reasons." But, um, you know, so, so there are some controls, but, um, yeah, it, it's generally handled by default.

33:55

Aaron Francis

Um, can we as customers, can we move them? Is there an affordance for that? Can we say, "Whoops, it's in DFW, I actually wanna move it to, you know, Europe or something"?

34:08

Josh Howard

Um, there's not, like, a straightforward mechanism for that. Um, you know, you can effectively just, like, delete it, move the state somewhere else, create a new durable object in those re- regions, and move them. They're meant to be implicitly declared. Um, so-

34:21

Aaron Francis

Mm

34:21

Josh Howard

... so, like, you, you just, you know, by referencing a durable object and doing some operations and storing some state there, it is created. Um, as long as you delete your stored data, then it's effectively cleaned up for you, right? So you don't have to, like, ever delete durable objects, but, you know, if you want to make sure you're not charged for the, the bytes stored, then yeah, you, you will need to actually, like, you know, delete all your data in, in those durable objects.

34:46

So but once, once they're deleted, you can, like, you know, you can copy that data elsewhere. You can, you know, do whatever you want. It's just code at that point.

34:53

Aaron Francis

So is it that the, uh, extremely sophisticated algorithm is so good, or is it that everybody that's talking to durable objects are mostly talking over Cloudflare's presumably fat pipes, and so it's fast enough that nobody ever really complains that, like, the durable object is potentially far away?

35:13

Josh Howard

I think the people that are most successful actually have so many durable objects that the placement algorithm works for them, right?

35:21

Aaron Francis

I see.

35:22

Josh Howard

So if you, if you have your application which is supported by many durable objects, and so, like, we, we actually encourage people to shard their applications to where, like, every single user gets their own durable object, right? That means that user, y- you know, like, you know, Aaron's durable object or the, the durable object that's backing your user data in an application you use, it will be located always, you know, near where you are, right?

35:47

Aaron Francis

Then that algorithm is absolutely perfect. I hate to tell you that there's no improving on that algorithm then. If e- every user gets their own, it's gonna be close to them.

35:56

Josh Howard

Ex- exactly. And so I think that's kind of why it's not been a problem.

36:00

Aaron Francis

Mm-hmm.

36:00

Josh Howard

And that also solves the issues with scaling, right? Because durable-

36:04

Aaron Francis

Sure

36:04

Josh Howard

... objects are inherently a single, single thing, right? It's not like workers where, you know, if you overload a worker on a single metal, you can just, like, run, you know, run-

36:14

Aaron Francis

Mm-hmm

36:14

Josh Howard

... the same isolate somewhere else and so on and so on. I mean, like, you, you literally cannot overload Cloudflare workers. You can overload a durable object, like a single durable object. And you know, so by actually sharding your application, it makes the placement algorithm work quite well. It also makes sure that you're not gonna overload a single durable object.

36:32

Aaron Francis

What are people... Like, what are the, what are the common use cases that you're seeing people use durable objects for? Specifically, if you can, people doing a durable object per user, which sounds kinda crazy and kinda awesome.

36:47

Josh Howard

Yeah. Um, so there's, th- there are a lot of cases. I think there's a few different verticals that we're targeting, right? So I think agents has been, like, the one that-

36:56

Aaron Francis

Mm

36:56

Josh Howard

... we've been most vocal on Twitter about Um, where every single agent is an individual durable object. If you're using the agents framework, right?

37:04

Aaron Francis

Mm-hmm.

37:04

Josh Howard

Um, we've made the joke internally that, like, importing a- agents from, like, import agents is the same as, like, you know, import durable objects as agents. Um-

37:14

Aaron Francis

Hmm

37:15

Josh Howard

... so, uh, that's one use case.

37:16

Aaron Francis

I bet that one kills internally, doesn't it?

37:19

Josh Howard

Oh, what do you mean? Like-

37:20

Aaron Francis

I bet that joke, I bet that people just love that joke internally.

37:23

Josh Howard

I mean, maybe. Yeah. I, it like, it is kind of, we're very aware that, like, durable objects are abstract, and people-

37:31

Aaron Francis

Uh-huh

37:31

Josh Howard

... do love frameworks that, like, solve the exact problem they wanna solve, right? Um, so there is definitely a place for both. Um, and so, you know, durable objects is, like, meant to provide a, you know, abstract framework for building things, but, um, you know, special purpose, you know, libraries are always, always helpful.

37:50

Aaron Francis

Mm-hmm.

37:50

Josh Howard

So, um, you know, that's one. Multiplayer games is another. So, you know-

37:54

Aaron Francis

Hmm

37:54

Josh Howard

... if you're trying to, uh, coordinate between multiple players on different sides of the world, a durable object can be created in between those two players and, you know, can, you know, kind of, you know, manage game state and things like that.

38:06

Aaron Francis

Hmm.

38:07

Josh Howard

Um, we have, uh, chat rooms, uh, real-time applications. Uh, you know, w- any, any application that's built using WebSockets is probably using durable objects as a back end. Um, so built with WebSockets on Cloudflare, right? Sure.

38:22

Aaron Francis

Mm-hmm.

38:22

Josh Howard

You can use WebSockets elsewhere, you know. It just, um, but yeah. A, a great example is, like, we ha- we have a chat app which we published forever ago, which is, is, you know, pretty ful- fully fledged and, you know, works end to end. Um, we have a lot of people kind of experimenting with, like, local-first development and durable objects. That's, like, another-

38:41

Aaron Francis

Hmm

38:41

Josh Howard

... area that's, like, kind of, um, materializing. But, um, generally, like, you know, real-time multiplayer types of applications, um, those are the things that are really unique for durable objects. It's, it is the case that you can just, like, you know, build your, you know, standard three-tier web app with durable objects as a back end, and you can have more isolation, you can have lower latency.

39:05

It's gonna make it a better application. Um, but I think the things that you couldn't build, you know, with a basic three-tier web app setup are the things that are more interesting, right? It's like, you know, it, sure, you know, if Postgres works, just use Postgres. Like, you don't-

39:19

Aaron Francis

Mm-hmm

39:19

Josh Howard

... necessarily have to use durable objects for everything. But, like, you know, if you're building a, you know, document editing, uh, application and you're having to have every keystroke be an insert into Postgres, then, like, you know, your, your database is gonna fall over.

39:35

Aaron Francis

Mm-hmm.

39:35

Josh Howard

You can't build that type of application with just, you know, your basic three-tier web app setup.

39:41

Aaron Francis

Yeah. The example you gave about the, um, chat rooms was helpful, but I think the multiplayer game is, is more, that made it click for me a little bit more. So you've got a durable object per, like, a ongoing game, like per match, I guess.

39:58

Josh Howard

Yep.

39:58

Aaron Francis

And so-

39:58

Josh Howard

Exactly

39:59

Aaron Francis

... that's the place where the users, maybe two or more, are connecting, and that's the place where all the, the state is living. And then for each ongoing match or existing match, you've got a separate durable object.

40:12

Josh Howard

Mm-hmm.

40:12

Aaron Francis

And that is, like, you know, from the point of view of the durable object, it's, it's not a lot of compute. It's, like, two people doing a thing.

40:20

Josh Howard

Yeah.

40:20

Aaron Francis

But you could have thousands of them.

40:23

Josh Howard

Yeah.

40:23

Aaron Francis

And at that level, well, that's pretty, that's, that's a lot. But again, from the single point of view, it's barely anything.

40:29

Josh Howard

Yeah.

40:29

Aaron Francis

So that, that part makes a lot of sense.

40:31

Josh Howard

I mean, durable objects are like a row in our database, right? Like that-

40:34

Aaron Francis

Mm.

40:34

Josh Howard

That's, that's, like, people do not understand how cheap they are for us. And so, like, whenever we say, like, you can create millions-

40:42

Aaron Francis

Yeah, gosh

40:43

Josh Howard

... like, you can actually create millions. It's fine. Like, i- it's like the, the ramp-up is, like, you know, you can't create millions a second. Like, we will tell you to back off.

40:52

Aaron Francis

Mm-hmm.

40:52

Josh Howard

Right? But, like, you know, you can try and create them as fast as you want, and like, you know, we'll, we'll tell you if, like, you're, you're creating them too fast. But, like, you know, scaling up thousands per second is not a problem.

41:03

Aaron Francis

Okay. So you've got a bunch of customers. You, you being Cloudflare. You've got a bunch of customers. They're all creating thousands of durable objects a second, and you are, with 100% confidence, generating IDs that don't collide.

41:18

Josh Howard

We are, yes.

41:19

Aaron Francis

Tell me, what are we using to do that?

41:22

Josh Howard

Well, so you can think about, like, th- there's nothing, like, particularly creative here, right? Like, if you just assume that, like, the IDs are, you know, prefixed with the client, like, you know, the, the, the client, you know, uh, data center and, and, you know, server number, right?

41:41

Aaron Francis

Mm-hmm.

41:41

Josh Howard

Then, you know, and like, you know, you can have, like, the isolate ID or whatever, right? Like, y- you can ensure that the, the isolate which is requesting this and saying, "Give me a new unique ID," is, you know, never going to overlap with another one, right? Um, so that's, that's the simple case of like, you know, generating unique numbers because you've just, like, prefixed them in such a way that they, they don't collide is, like, that's the straightforward.

42:05

Um, the harder part is whenever you're trying to generate a named durable object. So, like-

42:12

Aaron Francis

Hmm

42:12

Josh Howard

... this is the one that, like, makes more sense of, like, you know, you're, you're not gonna like, you know, name a variable in your code like ABC123, you know?

42:20

Aaron Francis

Mm-hmm.

42:21

Josh Howard

Some long hex string, right? You're gonna have, like, a durable object named Foo or whatever, right?

42:26

Aaron Francis

Right.

42:27

Josh Howard

And so the way that that works is we actually have to go to a singular region in the world. And without loss of generality, like, you know, we, we've basically just picked North America because-

42:38

Aaron Francis

Mm-hmm

42:38

Josh Howard

... latencies are gonna be better for people in North America. You know, the alternative is, like, randomly picking a region and latency, latencies are, you know, randomly bad, right?

42:48

Aaron Francis

Mm-hmm.

42:49

Josh Howard

Um, another feature I'd love to build is actually making that configurable, 'cause, like, you can do that and it would work. But, um, again, nobody's requested this. Um- You know, a- anyway, um, so but, but we pick a region that we use for, for, uh, coordination and, uh, we, you know, we'll submit that request to that region.

43:09

And then the requester which wins, right? So imagine you've got two, you know, clients on either side of the world, but you're trying to create a durable object named Foo. Um, the client that wins is essentially going to have, uh, we call this, this strategy relocate on create. It's going to insert a record into our database and say, "This durable object is created.

43:31

It has, you know, XYZ ID, and it's being relocated to live next to, you know, the client that won," right? And so the, uh, the second requester that loses is going to, instead of creating that new durable object, it's just going to be told, "It's actually moved over here. Go make that request." And then this is actually scalable because subsequent requests for newly named objects or frequently requested objects, those ...

43:56

the locations get cached, right? So, um, if you have a durable object which is requested all over the world, um, you know, we will have in local cache in every, you know, client, uh, or every like, you know, every, like, edge data center in Cloudflare's network is gonna have a cache relocation record that that durable object lives here, so go request it there.

44:18

Aaron Francis

Okay. So two requests are in flight to create a durable object named Foo. Obviously, one wins, and the North America region that's doing the coordination says, "Okay. Foo is now in," we'll say, "DFW."

44:36

Josh Howard

Mm-hmm.

44:37

Aaron Francis

So the first one comes in, gets the lock or whatever on create. Foo is created, and it's put in DFW, and this coordinator keeps a record of Foo is now in DFW. The second request that was in flight reaches the coordinator, and it says, "Whoops, you're too late. Go to DFW," and it redirects it down to DFW.

44:59

Josh Howard

Mm-hmm.

44:59

Aaron Francis

Is that right so far?

45:01

Josh Howard

Yes.

45:02

Aaron Francis

And then more requests, uh, that were not in flight for Foo don't ever go to the central coordinator because at some point, that information is propagated to all of your edges that says, "Hey, Foo's in DFW. Don't even go try to create it because it already exists in DFW."

45:21

Josh Howard

Yeah. E- exactly. So let's say that, like, you know, the original, like, losing request came from, like, LAX.

45:27

Aaron Francis

Mm-hmm.

45:27

Josh Howard

You got subsequent requests that go through LAX. They're going to actually just see the fact, the cache result that this DO is actually, you know, in DFW.

45:36

Aaron Francis

Mm-hmm.

45:36

Josh Howard

And then they'll, uh, they'll know to go directly to DFW instead of, you know, uh, wherever the, the coordination point was previously.

45:42

Aaron Francis

Hmm. Okay.

45:43

Josh Howard

And if they can't find it there, then they can fall back to the same database, right? And, and then, like, you know, they, they can see where we've ... like, what, what the actual, you know, record is of, you know, what is the, uh, the data center which, you know, is authoritative for where that durable object lives. Um, you can, you know, track that down if, you know, the cache is for some reason invalid.

46:05

Aaron Francis

Okay. Yeah. Yeah. That makes a lot of sense to me. Um, so outside of, outside of durable objects, you've got ... I'm sorry. You'll have to tell me again. Is it Workers D1, or is it just D1 with no prefix?

46:20

Josh Howard

Um, D1 with no prefix.

46:22

Aaron Francis

D1 with no prefix. And that is the one, correct me if I'm wrong, that's the one that is, like, globally replicated everywhere?

46:32

Josh Howard

Um, no, no. So Workers KV is globally replicated everywhere. It-

46:35

Aaron Francis

Okay

46:35

Josh Howard

... it's, it's essentially like we have products that are, offer strong consistency and products that offer eventual, eventual consistency.

46:43

Aaron Francis

Okay.

46:43

Josh Howard

KV is eventually consistent but globally replicated.

46:46

Aaron Francis

Okay.

46:47

Josh Howard

Um, D1 is actually, it's strongly consistent, and, uh, it's effectively a durable object. So, um, that's- ... that's the thing. Um, so you know, the, the TLDR for D1 is that if this is confusing for you, you can use D1. Um, and it looks like a database. It, it-

47:04

Aaron Francis

Yeah

47:05

Josh Howard

... looks and feels like that database that you know and love, and, uh, it's easy to use, and you don't have to, uh, you know, worry about doing anything different. It just fits into your application. Um.

47:18

Aaron Francis

Okay. And is it accessible? So I, I played with it a while back, and it was accessible over, uh, HTTP API.

47:26

Josh Howard

Mm-hmm.

47:26

Aaron Francis

Is that still the way to access it from the outside world, not from-

47:30

Josh Howard

Yeah

47:30

Aaron Francis

... you know, Workers or something?

47:31

Josh Howard

Yeah, you can access it through an HTTP API as well as Workers. So, um, you do have to manage tokens where you don't have to do that through Workers. But yeah.

47:40

Aaron Francis

Mm-hmm.

47:40

Josh Howard

I mean, it's basically just like a database which is accessible over HTTP.

47:44

Aaron Francis

Cool. And you all, uh, I believe recently acquired the Outerbase crew. Is that right?

47:50

Josh Howard

Mm-hmm. Yeah, yeah. We did.

47:51

Aaron Francis

And so, so which they are, you know, I don't know what their team makeup is or whatever, but they have somebody on their team that has good taste because everything they do looks beautiful. So what is ... Now that they're in-house. Well, first, explain Outerbase, and now that they're in-house, how are they augmenting Cloudflare's offerings?

48:09

Josh Howard

Yeah. So, um, w- I, I would say, like, I, I think the entire team has good taste. It, it's-

48:14

Aaron Francis

Yeah. Somebody. I-

48:15

Josh Howard

Yeah

48:15

Aaron Francis

... I'm not surprised because they do beautiful work.

48:18

Josh Howard

Yeah. It, it's one of the things I, I realized whenever we were talking to them was like everybody kind of works on their own thing, and it's remarkably cohesive for that. Like, I mean, it, it's like there's, there's a shared design aesthetic. Like, you know, it's, um ... And that's, you know, across like Starbase and, um, you know, their actual like, you know, uh, like Outerbase application, I guess.

48:39

Um, Outerbase proper, not Starbase. Um, yeah, it all, it all looks great. Um, so they're essentially working across all, all of Cloudflare's storage products to-

48:49

Aaron Francis

Yeah

48:49

Josh Howard

... improve kind of the developer experience around those. And so they've started with D1. Um, you know, the, the UI got quite a glow up already. Um, that's kind of the, the first order of business And the, the goal is to actually bring that to all the other, um, storage products at Cloudflare. So, um, you know, including Durable Objects, but, you know, KV, uh, HyperDrive, all these other products that we have, um, we want them to, you know, be able to have, like, kind of a unified querying experience.

49:16

And that's basically what they did for Outerbase, where, I mean, they were effectively building a, a catalog for interacting with data stores. Um-

49:24

Aaron Francis

Mm-hmm

49:24

Josh Howard

... so.

49:25

Aaron Francis

So they, uh, they brought ... Is it the, the, uh, like, the table view or the browser, the GUI, um, into the Cloudflare dashboard so you can poke around with your D1? And can you also poke around with your Durable Objects D1?

49:42

Josh Howard

Yeah. So, um, so the goal will be to bring that to Durable Objects.

49:46

Aaron Francis

Okay.

49:46

Josh Howard

Um, the issue is, it, I mean, it, it's kind of interesting of, you know, the way D1 is architected is we basically have a worker. Like, Cloudflare builds, uh, we, we dogfood our own products quite heavily.

50:00

Aaron Francis

Mm-hmm.

50:00

Josh Howard

Right? So D1 is built using Workers and Durable Objects. And so we have our worker, which is effectively serving requests from our dashboard, right, to support that UI.

50:10

Aaron Francis

Hmm.

50:10

Josh Howard

Um, the problem with Durable Objects and why it does not have the same seamless experience is because it runs in the customer's account, right? So-

50:18

Aaron Francis

Mm

50:18

Josh Howard

... you know, D1 is a Durable Object running in our account, which is proxied by a worker running in our account. Um, we have built a lot of stuff, um, so that, that, you know, like, there, there's a more kind of interactive, better experience. Um, we don't have a way to, you know, kind of deploy a worker for our customers to sit in front of their Durable Object-

50:41

Aaron Francis

I see. Mm

50:42

Josh Howard

... um, and do that securely, and do that-

50:45

Aaron Francis

Sure

50:45

Josh Howard

... without incurring costs on behalf of users, and all the other, like, kind of finer details to get right before we, we did something like that. So, um, you know, it, it's, that, that's kind of the, the thing. We have some ideas of what we could build so that we actually, like, can bring as good of a querying experience to Durable Objects. But, you know, D1 is, you know, the thing that's, like, definitely, uh, easy to do out of the box with the architecture we have.

51:10

Aaron Francis

Hmm. That makes sense.

51:11

Josh Howard

Not easy. I mean, like, you know, it's just a small matter of code, building nice UIs. Um, you know.

51:15

Aaron Francis

Yeah.

51:15

Josh Howard

But yeah.

51:16

Aaron Francis

If it, if it was easy, everyone would do it. Um-

51:18

Josh Howard

Yeah.

51:19

Aaron Francis

Yeah. So, okay. Y'all just had your massive, uh, I don't know what you call it, launch week, developer week, you know, release everything week. Um, no lulls. Normally, there's a lull on these launch weeks where it's like, end of the week, we're just really scraping the bottom of the barrel, but y'all powered through all the way. So tell us, uh, here at the end, tell us the big things your team just released, and, like, in the next 12 to 18 months, what are you, like, what are you hoping to see, and what are you looking forward to on

51:49

kind of your side of the, the company there?

51:52

Josh Howard

Yeah. Um, great question. So, uh, the, the, the largest thing that we released was actually read replication for D1. Um-

51:59

Aaron Francis

Hmm

51:59

Josh Howard

... so D1 read replication essentially allows for you to, I mean, I mentioned, like, it's a, it's a Durable Object behind the scenes. Um, and so what this allows you to do is actually read from replicas of that database. Um, we have a sessions API which sits in front of, um, you know, that, that, uh, the, the Durable Object API, which allows you to basically say, you know, whenever I do a write to the database, get back a session which wraps a bookmark, and, um, as long as I, you know, have that session object present

52:29

for subsequent reads, my reads are sequentially consistent. Um, everything kind of corresponds to a total order, and, uh, you can always, you know, read your, your previous writes. So-

52:40

Aaron Francis

Cool

52:41

Josh Howard

... um, that's, that's, that's one piece, um, that will be coming to Durable Objects soon. Uh, the reason why we started with D- D1 is just because it is a more constrained API. There's a lot of surface area, and we wanna make sure that we get that right. Um, and so, uh, you know, the, it's working in Durable Objects today. We've used it with some other cool stuff. Um, but, uh, you know, there's, there's a lot of, of surface area to get right before we release it for DO.

53:07

Aaron Francis

So this is, like, this is, like, um, not only read replicas but also sticky sessions, read your own writes, all kind of as, like, a first party-

53:15

Josh Howard

Right

53:15

Aaron Francis

... uh, implementation.

53:17

Josh Howard

Exactly. Yeah, yeah.

53:17

Aaron Francis

That's nice. I like that.

53:19

Josh Howard

So, um, yeah. So that, that's what, uh, we released. Um, also a free tier for Durable Objects was announced. Um, and another thing that was teased and is kind of, uh, something that we'll be working on very soon, or w- we're, we're currently working on it, we'll be releasing very soon, is containers. So-

53:35

Aaron Francis

Hmm

53:35

Josh Howard

... you know, one of the things about the Workers platform is that, you know, it is all JavaScript and Wasm based because of the, the V8 isolate dependency, right? And so, um, you know, containers allow you to run, you know, code in whatever programming language you want. Um, it's just a container, right? Uh, as I mentioned, you know, Durable Objects are the way to reference in- individual resources.

53:58

And so the goal will be to actually be able to use Durable Objects to interface directly to containers. So instead of just, like, referencing a Durable Object, you can have an attached container, and that can be continually routable using the same Durable Objects API. So that's-

54:11

Aaron Francis

Okay. This is-

54:12

Josh Howard

Yeah

54:12

Aaron Francis

... this is supposed to be the wrap-up, but that's big. Hang on. So containers are, have to be fundamentally discreet from anything that currently exists because unless you've figured out a way to run them in V8 isolates, which is beyond me. So is this containers thing an entirely new, uh, engineering effort, or is it built on top of something that exists?

54:33

Josh Howard

Um, it's an entirely separate engineering effort, right?

54:36

Aaron Francis

Okay.

54:36

Josh Howard

We've got a dedicated team that is doing this, right? But, um, the question becomes, like, how do you route to containers from within the Workers platform, right?

54:44

Aaron Francis

Hmm.

54:45

Josh Howard

Um, and so because Durable Objects solves routing, right?

54:49

Aaron Francis

Mm-hmm.

54:49

Josh Howard

Um, what we can do is we can actually, um, route to a Durable Object and then have a container spun up locally so that it's, you know, they're co-located, so that you can, uh, request from a Durable Object into that container.

55:03

Aaron Francis

So the durable object acts as a sort of proxy in front of the container?

55:07

Josh Howard

Yes. And that means that you have kind of two layers of proxying for doing whatever type of, like, authentication checks or whatever. You have your, your workers proxy, which can do, like, request validation, that type of stuff.

55:19

Aaron Francis

Mm-hmm.

55:20

Josh Howard

Um, you have your durable object, uh, layer, which can do whatever you wanna do in JavaScript or just, you know, immediately delegate to the container. Uh, and then you have whatever's running in the container.

55:30

Aaron Francis

Fascinating.

55:31

Josh Howard

Yeah.

55:31

Aaron Francis

Okay.

55:32

Josh Howard

So yeah, I mean, like, you know, I- it's kind of like the thing of, like, if you wanna build something on AWS you have to understand, like, you know, IM and EC2.

55:42

Aaron Francis

Yeah.

55:42

Josh Howard

And it's like, you know, even if you're using higher order, like, services like SageMaker or something like that, you've, you've gotta know basic EC2 instance types, right? For, or they're gonna continually be referred to. I think workers and durable objects are, like, the kind of primitives that you just kind of have-

55:56

Aaron Francis

Mm-hmm

55:57

Josh Howard

... to know in order to make sense of the Cloudflare developer platform. Um, and so, you know, but containers are, they were teased for developer week. They'll be released this summer, uh, hopefully early summer. Um, and yeah, so that'll be kind of another thing. And then the, the follow-up is, um, really just making, um, you know, uh, removing asterisks from the things that I said.

56:18

So, like, one of the details that I kind of glossed over is, like, we don't run durable objects everywhere. Um, infrastructure-

56:25

Aaron Francis

Mm

56:25

Josh Howard

... for running durable objects is a little heavy, and so it's hard to run them in the global south. So you'll never notice this if you're running in Asia, Europe, or North America, but, like, if you're in Sub-Saharan Africa, like, yeah, you're still gonna see pretty bad latencies when using durable objects, and that's just because of, you know, uh, network connectivities is, is, you know, bad in some parts of the planet.

56:46

Aaron Francis

Mm-hmm

56:46

Josh Howard

... um, we are, you know, with our new storage backend, we're able to work around that. Uh, it's a lot lighter weight, and so we'll be deploying in more regions. Um, but that's a rollout that will be happening over, like, the next year.

56:59

Aaron Francis

Okay. Cool. Well, is there anything else you wanna leave, uh, leave the people with? If not, tell them where they can find you.

57:06

Josh Howard

Yeah. Um, so one thing I would say is, like, we are actively hiring, so, like, you know, I mean, and I am the manager of the team. So, um, you know, if this is interesting to you, um, you know, feel free to reach out. Um, we have a job posting. And also just feel free to DM me. Um, would love to talk to you. You know, maybe you're not looking for a job, but just find this interesting. I enjoy talking to engineers. So, um, you know, definitely-

57:28

Aaron Francis

What kinds of roles?

57:30

Josh Howard

Uh, mostly systems level roles. Um-

57:32

Aaron Francis

Okay

57:32

Josh Howard

... but, you know, um, I would say if, you know, w- w- if you are, you know, able to make it through a 45-minute database podcast, you're probably an interesting person, and I'd you know, uh, would love to, to talk to you. So, uh, you know just kidding. But, you know.

57:48

Aaron Francis

Oh.

57:49

Josh Howard

Um-

57:49

Aaron Francis

That's okay. I'm taking it as a compliment for some reason. I think, yeah, that's perfect.

57:52

Josh Howard

Oh, no. I mean, like, I, I-

57:53

Aaron Francis

These are my people

57:53

Josh Howard

... I love databases. Like, I mean, like, I, I'm- ... definitely, like, you know, in the database nerd camp myself. So, like, you know, it's, you know, probably-

58:01

Aaron Francis

Listen, if y'all, if y'all want a manager who is clearly very technical, you know where to go. So that's a good sign already. He knows, he knows the inner workings, so he's probably pretty good at his job.

58:12

Josh Howard

I, you know, I, I try to be, but yeah. And, like, you know, the other thing that I would say is, like, I, you know, to that note, I do support a large team, right? So I mean, there are plenty of people who are working on this. Um, you know, I mean, I kind of wanted to speak to it because it covers durable objects and D1, but, like-

58:28

Aaron Francis

Mm-hmm

58:28

Josh Howard

... you know, um, there's a, a large group of people that are contributing to this, um, both immediately on the team and then other people across Cloudflare that just think that this is cool and want to-

58:38

Aaron Francis

Mm-hmm

58:38

Josh Howard

... you know, want, want to contribute to it. So, um, yeah, definitely, uh, you know, reach out if you're interested. Um, but yeah. And then in terms of getting in touch, um, you can find me on Twitter. Um, my Twitter handle's @ajoshhoward, um, 'cause there are many of us. And, um, yeah, uh, also I guess my email is probably... I'm, I'm not very, like, social on the internet.

59:02

Like, you know, it's like I respond to DMs and, you know, talk to people, but, like, I don't, like, you know, broadcast stuff. So, um, but yeah, definitely happy to chat. Um, my email's jayhoward@cloudflare.com.

59:13

Aaron Francis

Okay. Perfect. We will leave those, uh, those links down in the show notes below. Um, thanks for doing this, Josh. This was, uh, a fascinating deep dive into some of, uh, how Cloudflare works, which I've always wondered. So thanks for doing this.

59:26

Josh Howard

Yeah. Yeah. Anytime.

59:28

Aaron Francis

All right. We will talk soon. Until the next time. See ya.

59:31

Josh Howard

Yep. Bye.

Databases

More videos on databases

All videos

Get the next one by email

I’ll send you some more. Not too many.

Join 7,500+ other readers.

Read past issues