June 202457:0223.3k views

Migrating from Postgres to SQLite with Kent C. Dodds

About

In this episode of Database School, I interview Kent C. Dodds about his journey migrating from Postgres to SQLite with LightFS, simplifying his infrastructure while maintaining global performance. They dive deep into technical challenges, the benefits of SQLite, and how these experiences are shaping the development of the Epic Stack.

Transcript

Everything we said

00:00

Aaron Francis

All right. Welcome back to, uh, this is somehow the fourth episode, but the first episode that has a name, and the name is now Database School. So I, I've been doing these interviews with, with so far SQLite people and putting them on YouTube and thought, "Eh, this would... People would probably listen to this as a podcast." So I-

00:17

Kent C. Dodds

Yeah

00:17

Aaron Francis

... uh, take the audio now and strip it out, now it's a podcast. So you can find this on YouTube or I don't know if I have a Database School domain. But look for it on YouTube. You'll find it there. So today, uh, I have the great pleasure of being here with Kent C. Dodds, who probably needs no introduction, but I will introduce him anyway. Uh, Kent C. Dodds is the guy on the internet, um, that I kinda look up to, I'll...

00:42

if I'm being honest. He's, he's a, a prolific creator, he's all around a positive good guy, and he's creating Epic Web, the Epic Stack. He's just, like, the king of the React world. So that's as effusive as I can be. Kent, do you wanna... D- don't rebut anything 'cause it's all true. But do you wanna add anything?

01:02

Kent C. Dodds

Well, geez, that, you're making me blush. That's very nice, Aaron. I also look up to you a lot, uh-

01:06

Aaron Francis

Mm

01:06

Kent C. Dodds

... and the way that you interact with people online and, and your depth of experience in the database world and, and also, uh, on the Laravel side of web development. The, the web world is a very large place and has room for all of us. And, uh-

01:21

Aaron Francis

Mm-hmm

01:21

Kent C. Dodds

... I appreciate the varied perspectives that, uh, we have in, in web. So, uh, yeah. Other, uh, I also have, um, five children and, um-

01:31

Aaron Francis

Wow

01:32

Kent C. Dodds

... you might hear them in the background here. Um, but, uh, I live in Utah, and, uh, I have been doing web development... Well, I, I graduated from, uh, Brigham Young University in 2014, so it's been a decade since I graduated now. Um, and pretty much just JavaScript since then. Uh, so that is, um...

01:53

Yeah. And, and I do lots of stuff with React. I started with, uh, Backbone, and then got into Angular, and then, uh, React, and now I build full stack, uh, depending on your definition. According to Taylor- ... uh, I do full stack development, uh, with Next.

02:09

Aaron Francis

Yeah. I think, I think we settled, uh, or he settled on that being full stack and then a, uh, the other... What was the other differentiator? I don't remember. But we, we settled that, like, it runs on a server. It's full stack. Um-

02:19

Kent C. Dodds

Yeah.

02:20

Aaron Francis

Backing up a little bit, I forgot you have five kids. Y'all just had a new one, right?

02:24

Kent C. Dodds

We did, yeah. Yeah. Back in November.

02:25

Aaron Francis

Well, congratulations.

02:27

Kent C. Dodds

So, uh, he's seven months now, and just, like, totally wonderful, uh, adorable kid. Um, and, uh, yeah. Then my oldest is 11. Uh, so we've got-

02:39

Aaron Francis

Wow.

02:39

Kent C. Dodds

Um, yeah. We're, we're getting close to the teenage years, which is kind of, uh, gonna be... It's, uh, I, I'm already... I, I can already tell that my daughter is changing, uh, not just, like an- anatomically, but also, like-

02:52

Aaron Francis

Right

02:52

Kent C. Dodds

... in, uh, attitude and just, like, personality and everything. Uh, so cautiously optimistic about-

03:00

Aaron Francis

Yeah

03:00

Kent C. Dodds

... the direction.

03:02

Aaron Francis

Yeah. Well, I'm, I guess, if she's 11, I'm eight years behind you. My oldest are three. Um-

03:08

Kent C. Dodds

Mm

03:08

Aaron Francis

... so I'll, I'll be coming to you when mine start to enter that preteen phase with, uh- ... hopefully not too frazzled and frenzied. Hopefully, just some advice. But congrats-

03:18

Kent C. Dodds

Yeah

03:18

Aaron Francis

... on the fifth one. That's amazing.

03:20

Kent C. Dodds

Oh, thank you. Well, most of the, the cheers go for my wife, that's for sure.

03:25

Aaron Francis

I know. Yes. I know that to be true. Um, so tell her I said that as well. Um, so the reason, the reason you're on here at Database School, um, is I read a blog post of yours. Uh, I don't remember when you wrote it, but I read it recently, talking about migrating from a Postgres cluster to SQLite with LiteFS, and I thought it would be interesting because you, I think like me, are, um, or would consider yourself more of an application developer than, like, a DBA.

03:52

You might call yourself a framework author or something. But I think you and I both live on, like, more of the application side. Um, and so I thought it would be interesting to talk to you about from more of a user of a database perspective, kind of the journey that you went through, um, and what your experience has been so far, having moved off of this Postgres cluster.

04:14

Kent C. Dodds

Yeah, for sure. Um, very accurate to describe me as an application developer. I, I am, uh, if I am a DBA, it's reluctantly. Um, it's, uh, the infra side of things, uh, is, is never, uh, and, and ops has just never really, uh, gotten me very excited. Um-

04:32

Aaron Francis

Mm-hmm

04:32

Kent C. Dodds

... and I appreciate that there are other people in the world who are excited by that, um, especially Ben Johnson, who, uh-

04:39

Aaron Francis

Mm-hmm

04:39

Kent C. Dodds

... created Lightstream and LiteFS. You've had him on already. Uh, really, really awesome guy. Uh, love that guy. He makes my life a lot easier. Um, and so yeah. Pretty much the name of the game for me is, um, how do I, um, how do I make my application infrastructure and, um, uh, like the tools that I'm using as simple, uh, like, as possible, while still enabling the user experience that I'm targeting?

05:07

And so, like, um, I, I started building my app... Well, well, I guess I'll back up a little bit. When I built my website, um, uh, and, and actually, like, rebuilt it in 2021, um, it wa- it was motivated out of a desire to learn, um, how to do things in the modern age.

05:29

Um, so I, I worked at PayPal for a long time and, and, um, saw, okay, here's how you build at scale for millions of users all over the world. Um, and then I left PayPal to go full-time on my teaching. So I, I am a full-time teacher. Uh, testingjavascript.com was my first thing that got me into full-time teaching. Uh, and then, uh, Epic React was, uh, something I released in 2020.

05:54

And so in 2021, I said, "Okay, it's been, like, two years since I left PayPal. I need to get back into, like, building something real so that I can then teach people how I did it." Um-

06:04

Aaron Francis

Mm-hmm.

06:05

Kent C. Dodds

And so that was the, the guiding, uh, light for my website, was like, I don't wanna just build a developer portfolio, 'cause I'm not just teaching people how to build dev portfolios.

06:14

Aaron Francis

Mm-hmm.

06:14

Kent C. Dodds

I want to teach people how to build web applications that are, like, dynamic and, and, um, global and really powerful, all that. And so there was a, an important aspect of what I was building was, uh, that this scales very well, uh, and that it's global. Uh, in fact, uh, not a lot of people were talking about pushing things to the edge, uh, back then. There were definitely people talking about that.

06:36

Uh, but most people were on US East and whatever, and that's fine. And even still, lots of people are still there, and that's fine. Um, but I wanted to be on the edge because I felt like that was where a lot of things were going to go, uh, and, like, where the, the next level of performance, uh, can be achieved and all of that. And so, uh, that actually led a lot of my decisions.

06:58

Uh, I started out using Firebase for my data and auth and stuff-

07:01

Aaron Francis

Hmm

07:01

Kent C. Dodds

... and then I realized, oh, if I do that, now I can't be... Like, I technically d- can deploy my app anywhere, but now every request has to go talk to wherever Firebase is, and that-

07:11

Aaron Francis

Mm-hmm

07:11

Kent C. Dodds

... is just not great. Um, and so tha- then I started looking at, um, doing some sort of distributed data thing, and I found Fly.io did Postgres, uh, clusters, and, and they made it-

07:22

Aaron Francis

Mm-hmm

07:22

Kent C. Dodds

... like, really easy. Not just Postgres, but also Redis, uh, with read replicas all over the world. And I was like, "That's perfect. Uh, I'm gonna go with that." So I did, and I, I launched, uh, my website with multi-regional, uh, deploys. I, I think I chose, like, six regions, uh, deployed my application and Postgres and Redis clusters to all of those regions.

07:42

Aaron Francis

Hmm.

07:43

Kent C. Dodds

And, uh, my app was, was, like, super duper fast, and it was awesome. Um, I found a couple of problems with that though. Um, so first of all, like, I, I had no business doing any of this. Like, I, I... Doing, like, uh, managing services, and I-

08:00

Aaron Francis

Yeah

08:01

Kent C. Dodds

... honestly, Fly made it a lot of it-

08:02

Aaron Francis

Fly makes it so easy.

08:03

Kent C. Dodds

Yeah, yeah. Fly makes it pretty easy, so it wasn't actually too bad. Um, but, uh, if there was ever a problem of any kind, and, and, like, these were pretty early days for Fly, too. And so-

08:14

Aaron Francis

Yeah

08:14

Kent C. Dodds

... if Fly had a problem, I had, like, no idea how to give them enough information for them to help me. Um, and so occasionally, uh, Postgres and, or Redis would fall over. I would have no idea what to do. And, and the Fly folks were super awesome-

08:30

Aaron Francis

Mm-hmm

08:30

Kent C. Dodds

... um, and, and responsive and stuff. So, like, uh, there were times that I was like, "I think I'm gonna jump off of Fly and do something a little easier or whatever," but no, they were super great and, and I'm super happy to be with them. Uh, but another thing that bothered me was, um, the complexity of running things locally. Uh-

08:49

Aaron Francis

Hmm

08:49

Kent C. Dodds

... it's not really complex. We've got great tools, and I had Docker Compose and everything. It wasn't a huge deal. But, like, it was annoying, especially since my website is open source. Uh, if somebody wants to contribute, uh, even, like, text changes, just to run the app so they can see their text changes, it's a whole thing. And so-

09:07

Aaron Francis

Mm-hmm

09:07

Kent C. Dodds

... I just, I didn't want to have that friction. Um, and, uh, yeah, I, I would get multiple, uh... I'm looking at the post here, so people looking at the post- ... are like, "He's just reading the post." Yeah, that's kind of what I'm doing. But, uh, I would, I would get, uh, multiple people, um, send me, like, screenshots of my 500 page, because it's a little humorous.

09:28

Aaron Francis

Hmm.

09:28

Kent C. Dodds

Yeah.

09:28

Aaron Francis

Yeah.

09:29

Kent C. Dodds

Just, like, this grimacing, uh, uh, GIF of me, um, just because, like, there was a, you know, Postgres went down or, or Redis went down or something.

09:37

Aaron Francis

Mm-hmm.

09:38

Kent C. Dodds

Um, and so I kind of got bothered by this a little bit, um, well, quite a bit, uh, and-

09:44

Aaron Francis

Quite a bit, yeah.

09:45

Kent C. Dodds

Like, your, your website shouldn't be... Th- especially the thing that you're publishing free stuff on and whatever, I don't wanna babysit that. Like, I, I-

09:54

Aaron Francis

Yeah

09:54

Kent C. Dodds

... I'm happier babysitting the stuff that people give me money for. Like, that, that's great. I'll babysit a- that all day. But-

10:00

Aaron Francis

Mm-hmm

10:00

Kent C. Dodds

... uh, for the stuff I throw out there for free, um, no, I don't wanna deal with that. I wanna, like, just have it and, and go. And, and there are really great ways to do that. Like, you can use off-the-shelf, um, tools and stuff. There's, there's lots of other hosts that have really easy things that you can use, but they can't provide the user experience that I was targeting, um, with, uh, multi-region data replication and all of that stuff.

10:23

Aaron Francis

Yeah.

10:23

Kent C. Dodds

So-

10:23

Aaron Francis

So talk to me real quick about that. What is, what is that user experience that kept you, that kept you, like, slogging through this journey? Like, what is-

10:32

Kent C. Dodds

Yeah, I'm glad that you're-

10:32

Aaron Francis

... the thing you're after?

10:34

Kent C. Dodds

Yeah, so the thing I w- uh, th- there were a couple of things that were requirements for me. Uh, first of all, I wanted a dynamic front end. Uh, so I didn't-

10:42

Aaron Francis

Sure

10:42

Kent C. Dodds

... wanna have full page reloads on every navigation and, and things. Um, I wanted to have a... And, and so, like, you know, there are a lot of tools that can do that. I could even use Create React App for that, whatever. But, but I also wanted it to be server rendered as well-

10:58

Aaron Francis

Mm-hmm

10:58

Kent C. Dodds

... um, so that I can have the, um, like, no jank when the page loads.

11:04

Aaron Francis

Right.

11:04

Kent C. Dodds

I don't wanna have a bunch of unnecessary UI states as the UI is loading. So they land on the page, it is exactly what it looks like, and it doesn't change at all, unless there's, like, an animation, which I do have a, uh, like, a fade-in animation for some stuff. And that's, that's great. That's a good us- user experience.

11:18

Aaron Francis

Mm-hmm.

11:18

Kent C. Dodds

But nothing like text bouncing around or whatever. Uh, you can't always help with fonts loading and stuff. That's stupid.

11:24

Aaron Francis

Mm-hmm.

11:24

Kent C. Dodds

But you do the best that you can with that. Um, and then the other asp- or the other, uh, part of this, um, was the way that I like to build applications as well. Because it's not just, "Here's the user experience I wanna offer," but, "Here's also the way that I like to build applications and the way I want to teach people to build applications." And so, um, like I, I could do some of that with, like, just a WordPress site, but, but I-

11:48

Aaron Francis

Mm-hmm

11:48

Kent C. Dodds

... I wanted to, um, build my website in the way that I, I build full-fledged web applications. And so, yeah, it's gotta be React. Um, Remix was brand new on the scene, and I was very encouraged by what I saw there already. And so, um, I decided to use Remix. But, uh, yeah, the, the primary user experience I was looking for, uh, rendered on a server, uh, dynamic.

12:11

Uh, not just from like, uh, like an interactive thing on the browser, but also dynamic to the user.

12:18

Aaron Francis

Mm-hmm.

12:18

Kent C. Dodds

Um, and so that actually is kind of interesting. So every... You can log into my website. You can make your own account and everything, and you actually, when you log in, you choose a team, and, um, whatever, one of three teams. And, uh, when you read a blog post, you score points for your team, and whichever team has read- ... the most relative to how many members they have owns the blog post, and all the links are in your team's color and stuff.

12:42

Uh, so it's-

12:42

Aaron Francis

That's fun.

12:43

Kent C. Dodds

It's-

12:43

Aaron Francis

I didn't realize that.

12:45

Kent C. Dodds

Yeah, it's just kind of a fun thing. So this blog post-

12:46

Aaron Francis

What are the team names?

12:48

Kent C. Dodds

Uh, so they, they don't have names. They're just colors. It's yellow, red, and blue.

12:51

Aaron Francis

Okay.

12:51

Kent C. Dodds

Um, kind of like a Pokemon Go thing a little bit.

12:55

Aaron Francis

Mm-hmm. Okay.

12:55

Kent C. Dodds

Um, but, uh, yeah.

12:56

Aaron Francis

That's fun.

12:56

Kent C. Dodds

So this blog post right now is, is owned by the yellow team, um, so all the links are yellow, uh, which is kind of fun. Uh, and so-

13:04

Aaron Francis

Yeah

13:04

Kent C. Dodds

... like by doing this... And, and not only that, we also, because I'm keeping track of your blog posts that you're reading, I can give recommendations based on the one that you're looking at, the ones that you've read already.

13:15

Aaron Francis

Sweet.

13:15

Kent C. Dodds

I'm not gonna recommend those. All that stuff. And so what that means is that, uh, on almost every page, I'm recommending other blog posts at the bottom-

13:23

Aaron Francis

Mm-hmm

13:23

Kent C. Dodds

... and I don't want any jank or anything like that, so those also need, need to be server rendered. And so what that means is I can't use HTTP caching, uh-

13:32

Aaron Francis

Mm-hmm

13:32

Kent C. Dodds

... on a CDN for my pages, because every one of them is gonna be different for every user. Um, a- and it's-

13:39

Aaron Francis

Hmm

13:39

Kent C. Dodds

... in fact, it's even different and, and kind of randomized every time you load the page. So if you scroll down to the bottom and hit refresh over and over again, you're gonna see that those blog posts are changing every time. And as a result, um, like this, the performance characteristics actually, uh, are kind of interesting there too-

13:57

Aaron Francis

Mm-hmm

13:57

Kent C. Dodds

... because I can't use the platform, uh, caching. Uh, I need to do this dynamic on the server. And so that was part of what led me to saying, "Okay, I wanna distribute this globally." Um, and, and it's not just, like, let's distribute it globally, um, but also, um, the... Like at PayPal, we have many instances of our apps running over there, and so you need to have your app capable of running multiple instances, uh, which is fine.

14:25

But when you decide, "Okay, I'm gonna distribute this globally so that it's fast whether you're in India or Amsterdam or Chicago," um, that is where the data stuff gets a little bit more complicated.

14:37

Aaron Francis

Mm-hmm.

14:37

Kent C. Dodds

Because now you're like, oh, I need to make sure that my database is close to my, uh, instances of my app, otherwise my app is going back and forth between my database-

14:45

Aaron Francis

Right

14:46

Kent C. Dodds

... and what should take 100 milliseconds to load is now taking, uh, 1,000 milliseconds to load, um, which is not the user experience I was targeting. So, um, yeah. So there, there were some interesting constraints that I put on myself. I, I, I like to tell people it's not over-engineered, uh, when referring to my blog or my, my site. It's not over-engineered. It's over-scoped.

15:06

Uh, which is-

15:07

Aaron Francis

Okay.

15:07

Kent C. Dodds

Uh, I, I can accept that. Um So-

15:12

Aaron Francis

I like that.

15:12

Kent C. Dodds

Um, yeah.

15:12

Aaron Francis

Okay. So you're in this situation where you've got, you've got your website, uh, deployed all over the place with Fly, which is awesome. Makes it... Fly makes it super easy. If you're not familiar with Fly, it's like they run their own cloud, so it-

15:25

Kent C. Dodds

Mm-hmm

15:26

Aaron Francis

... it's, it's an insane thing to do. Um, but they're doing it, and I feel like they're doing well these days. Um, so they put servers, makes it easy for you to put your, uh, application on the edge. But then like you said, you gotta phone home to the database if you have a centralized database, so what's the point? You haven't gained anything.

15:43

Kent C. Dodds

Mm-hmm.

15:43

Aaron Francis

So to solve that, you're trying to run Postgres, which Postgres is great, but it is more complicated. I mean, I don't think that is, uh, that's not debatable. It is more complicated, and so you're hitting a few snags with maybe early Fly platform plus complicated server, client-server database. And so instead of giving up on that, you changed, you changed tack.

16:06

Is there anything amassing there?

16:09

Kent C. Dodds

Uh, that's, that's pretty much it. Um, I, I mean, uh, I could go into more detail on some of the other things that the application does, but as, as far as-

16:17

Aaron Francis

Mm-hmm

16:17

Kent C. Dodds

... the database is... And actually, there's one thing that I'll, I'll tell you about later when we talk-

16:21

Aaron Francis

Yeah, yeah. Tell me

16:21

Kent C. Dodds

... about SQLite.

16:21

Aaron Francis

Okay.

16:21

Kent C. Dodds

It's kind of interesting. But, but yeah, as far as the data is concerned, those are the constraints, um, that I had on. So a- any database that I chose needed to have replication as a first-class citizen. Uh-

16:32

Aaron Francis

Mm-hmm

16:32

Kent C. Dodds

... I needed to be able to, uh, have my database right next to wherever the instance of my app was running. Um, yeah.

16:39

Aaron Francis

And I think until this conversation, I had forgotten or was under the impression that your, your blog was... You were basically shipping content, static content out to the edge, but this whole, like, keeping track of who's r- who has read what, all of that, you're doing writes back to the database. It's not just like you're shipping off a, a sealed set of data.

16:59

Kent C. Dodds

Yeah, correct. A-

17:00

Aaron Francis

Okay

17:00

Kent C. Dodds

... and so, yeah, there's, there are mutations going on, uh, and of course we have, uh, user accounts and stuff. Uh-

17:07

Aaron Francis

Mm-hmm

17:07

Kent C. Dodds

... I guess I'll mention also that the, the blog post content itself is, um, all hosted on GitHub and MDX files. And-

17:14

Aaron Francis

Cool

17:15

Kent C. Dodds

... my application, it's not a static build either. So, uh, my application, um, makes API calls to GitHub to get those and then compiles them on demand-

17:23

Aaron Francis

Oh, interesting

17:24

Kent C. Dodds

... on the fly.

17:24

Aaron Francis

Okay.

17:25

Kent C. Dodds

And so when I... Uh, th- and this was actually another requirement-

17:28

Aaron Francis

Huh

17:28

Kent C. Dodds

... sort of interesting, was my previous blog was built with Gatsby, and so any-

17:33

Aaron Francis

Mm-hmm

17:33

Kent C. Dodds

... even like a typo change had to rebuild the whole site. It took like-

17:36

Aaron Francis

Sure, yeah

17:36

Kent C. Dodds

... 20 minutes. It was stupid. Uh, and so that was another thing I wanted to make sure I didn't run into here, was I wanna be able to make a typo change and have it reflected on the site in seconds. And so that's, that's the case now. When I-- I've got a GitHub action that will say, "Oh, you changed this MDX file. I'll go tell the application," and it goes and refreshes that content, um, in like-

17:56

Aaron Francis

Oh, cool

17:56

Kent C. Dodds

... less than 10 seconds.

17:57

Aaron Francis

So is it, is it such that, uh- Your application is listening or has an endpoint where GitHub can fire and say, like, "Invalidate that one," and fetch it again?

18:07

Kent C. Dodds

Yep, exactly.

18:08

Aaron Francis

Huh, that's kind of cool.

18:10

Kent C. Dodds

Yeah. And I, I built a whole caching, uh, system around, uh, around all that, uh, which is, yeah, it's, it's pretty neat. And it's now a, a library. A lot of people are using it. It's built into the Epic Stack. It's called Cachified on npm.

18:24

Aaron Francis

Okay.

18:24

Kent C. Dodds

Um, and, uh, yeah, it's very helpful f- And so I, I just hit that endpoint and it, um, it doesn't blow away the cache. It just says, "Okay, let me go revalidate that value-

18:34

Aaron Francis

Mm-hmm

18:34

Kent C. Dodds

... and then I'll update the cache." So, um, users are never waiting, uh, because all of this stuff is done dynamically on demand and stuff.

18:42

Aaron Francis

Mm-hmm.

18:42

Kent C. Dodds

Um, if I blew away the entire cache, then yeah, we'd, it would take a couple minutes to rebuild everything, 'cause it is a lot. Um, I've got over 200 blog posts on, or I think right at 200 blog posts on there.

18:53

Aaron Francis

Wow.

18:53

Kent C. Dodds

Uh, which have a lot of, like, interesting dynamic things in them as well, like, uh, I have my own Twitter embed. It's not actually embedding Twitter. I, I-

19:00

Aaron Francis

Mm-hmm

19:00

Kent C. Dodds

... hit the Twitter or the X API, um, to get that information, all that stuff. But, um, yeah, so it can be a little bit much, but, uh, when it's in the cache, uh, yeah, it takes all of, like, 10 milliseconds to-

19:14

Aaron Francis

Hmm

19:14

Kent C. Dodds

... to compo- get everything together, uh, for the HTML document. And in fact, if anybody is interested in the timings of all that, I also have a server timing header on the response for-

19:25

Aaron Francis

That's cool

19:25

Kent C. Dodds

... my blog post. So you can take a look at like, here are all the things that were done, and here's how fast they all happened. It's kind of interesting.

19:31

Aaron Francis

Hey, I hope you're enjoying this. Just as a reminder, you can learn more about SQLite at highperformancesqlite.com. I'll get out of your way. Back to the interview. Oh man, that is super cool. It sounds like, it sounds like, um, this is your, this is one of your long-running playgrounds. Is that right?

19:51

Kent C. Dodds

Yeah.

19:51

Aaron Francis

Yeah.

19:51

Kent C. Dodds

Yeah.

19:51

Aaron Francis

Okay.

19:52

Kent C. Dodds

And, and, and I go, I go hard on that too. It's, it's not just the content. I also have, uh, two podcasts, uh, from two different podcast hosts-

19:59

Aaron Francis

Mm-hmm

20:00

Kent C. Dodds

um, that, uh, are on there. I, uh, you have a, uh... One of my podcasts is called the Call Kent Podcast, where you can record a question in the browser. It will save that audio, uh, to the, my database, and then I record a response, and then I use FFmpeg to stitch them all together to turn it into a podcast episode.

20:19

Aaron Francis

Of course you do.

20:20

Kent C. Dodds

So-

20:20

Aaron Francis

That's awesome.

20:21

Kent C. Dodds

Yeah.

20:22

Aaron Francis

That sounds like fun. I wanna do that. I wanna have a Call Aaron podcast.

20:25

Kent C. Dodds

Yeah. I-

20:25

Aaron Francis

That seems like a lot of fun.

20:27

Kent C. Dodds

I'm actually, right now I'm, I'm in that phase where I just finished l- launching some educational stuff and I'm back into-

20:33

Aaron Francis

Okay

20:33

Kent C. Dodds

... okay, let's build some stuff and practice and whatever.

20:36

Aaron Francis

Mm-hmm.

20:36

Kent C. Dodds

And I'm gonna productize that eventually. Uh, I-

20:38

Aaron Francis

Cool

20:38

Kent C. Dodds

... I'm productizing another thing, uh, that I built, but yeah, eventually that's one thing I'll, I'll productize, and I'll let you know when it's ready.

20:44

Aaron Francis

Yeah, please do. I'm, I have seen rumblings on Twitter of you being like, "Hey, what, uh, what should I charge for out here?" And I'm like-

20:51

Kent C. Dodds

Yeah.

20:52

Aaron Francis

... "Kent, I want you to build some sort of product." Like-

20:54

Kent C. Dodds

Yeah. Yeah.

20:55

Aaron Francis

I, as an educator myself, I, like, enjoy education and I think it's a lot of fun, but I'm excited to see what you, like, what product you build. That's gonna be awesome.

21:03

Kent C. Dodds

Yeah. Yeah. It's, it's a lot of fun. I've got cool ideas.

21:06

Aaron Francis

Yeah. I'm sure you do. I look forward to seeing them. So, um, okay, so we have our, our heads around the scope of this. Uh, it sounds reductive to call it a blog, but the scope of this application, we'll say. Um, and so at some point you reach a breaking point with Postgres and you're like, "I gotta simplify." Is that kinda what it is?

21:27

Kent C. Dodds

Yeah. That, yeah, that's pretty much how it went down. So, um, what happened was, like, it's very difficult for me to justify spending time on my free stuff, as I talked about already. But I was also working on... Uh, like the, the reason I built the site was, okay, let's get some practice so that I can teach people how I did it. And so-

21:45

Aaron Francis

Sure

21:45

Kent C. Dodds

... I, like it is important there. So anyway, I, I finished building it and was like, okay, I, I feel pretty good about teaching people how to do this. But the database thing I was not super thrilled about. And also, um, getting, uh, teaching people how to build full stack apps if it also requires Postgres and Redis is just an extra bit of friction that I wanted-

22:04

Aaron Francis

Mm-hmm

22:04

Kent C. Dodds

... to avoid, uh, at least upfront. Eventually, like if this-

22:08

Aaron Francis

Yeah

22:08

Kent C. Dodds

... is the way to do it, then I'm gonna teach you the way to do it. I'm not gonna like, take shortcuts just to make my life easier.

22:14

Aaron Francis

Mm-hmm.

22:14

Kent C. Dodds

Um, but to, to get things started, I built a, a new app called Rocket Rental, which was like an Airbnb for rocket ships. It had to be like-

22:23

Aaron Francis

Love it

22:24

Kent C. Dodds

... real world enough that it was something you could learn from, but not so real world that people would think it's a real product. And so I thought-

22:30

Aaron Francis

Right

22:30

Kent C. Dodds

... "Okay, you're renting rocket ships from your neighbors." Um, but I, I was planning on, uh, using Postgres eventually, but I started with SQLite.

22:39

Aaron Francis

Mm-hmm.

22:39

Kent C. Dodds

And I thought, "You know what? This SQLite is like pretty dang nice. A, like very, very nice. I like this very much." The, the local development is very easy. Um, and like I've got a persistent volume on Fly that's really easy. And then I discovered, uh, Lightstream and LiteFS.

22:57

Aaron Francis

Mm-hmm. Mm-hmm.

22:57

Kent C. Dodds

And I, that was when I was like, "Oh wait, so my hard requirements on a distributed database can actually be satisfied with SQLite." That's when things got really interesting to me. And, and I, uh, connected with Kurt, the f- uh, CEO of Fly. He and I'd been in conversations a lot. And I, I joined Remix actually for, um, a little while before I, I start building, started building Rocket Rental.

23:21

Uh, and so yeah, we were in, in communication a fair bit and then he introduced me to Ben Johnson, who was the creator of Lightstream.

23:27

Aaron Francis

Mm-hmm.

23:28

Kent C. Dodds

Um, and, uh, yeah, started talking with Ben about, okay, so how do you use LiteFS, and got into that.

23:36

Aaron Francis

So your setup now, um, you, you stay, you stayed on Fly because of the, the servers being close, and I, I like the ease of deployment there. And then you started to poke around with SQLite and you're like, "Hang on, this is awesome." So describe, uh, for the, for the edification of the listener, the, the Lightstream, LiteFS, just kind of at a high level what the difference is, which one or ones you are using, and how you're finding the experience.

24:04

Kent C. Dodds

Yeah, so I never used Lightstream. Um, and I, I don't know, I don't think that LiteFS is built on top of Lightstream. I, I think it's based on the, the same, well, many of the same principles. Um, but, um, it... yeah, folks who, uh, don't know or haven't listened to Ben's e- episode should go back and listen to that. But high level, Ben built Lightstream so that SQLite could have a better disaster recovery experience, and so you just back things up to an S3 bucket, and-

24:32

Aaron Francis

Mm-hmm

24:32

Kent C. Dodds

... and things. It's really nice. LiteFS, um, had, like... I, I'm not sure if the, the primary goal of LiteFS was read replicas. Uh, the, the thing that they productized out of it was LiteFS Cloud, that is, uh, also a disaster recovery sort of thing. It's, uh, automatic backups built into Fly. Um, but, uh, yeah, a- as a thing that fell out of that, whether that was the original intent or not, was, uh, read replicas-

24:59

Aaron Francis

Mm-hmm

24:59

Kent C. Dodds

... and, um, the ability to have a primary, uh, where all the writes go to, and then, um, the, uh, read replicas all over the world. And so th- that's what I'm using, is LiteFS. I also have LiteFS Cloud, um, as for my backups, and, and that's... And I, I've never actually had to restore from one of those-

25:18

Aaron Francis

Mm-hmm

25:18

Kent C. Dodds

... because I definitely have had to restore, um, but when I needed to restore was before LiteFS Cloud. So I'm like, "Hey, Ben, do you think you can, like, restore my database for me?" Um, so yeah, that-

25:29

Aaron Francis

Per- perks of knowing a guy.

25:31

Kent C. Dodds

Yeah, exactly. Um, I- I'll... Yeah. Um, that, that was, that was kind of fun. But, uh, just as a high level what LiteFS is, uh, imagine, uh, you've got your application, and then you've got the file system. I'm using my hands. People listening won't be able to see this. But, so the application is writing to the file system. It's saying, "Hey, SQLite, do this thing." SQLite's wr- writing to the file system.

25:53

So what LiteFS does is it tricks SQLite into thinking that it's writing to a file system, but it actually isn't writing to a file system, and then, uh, LiteFS replays those, um, transactions into an actual database under the hood. And so what, because it's playing the middleman, it can go and replay those same transactions on the read replicas.

26:10

Aaron Francis

Mm-hmm.

26:10

Kent C. Dodds

Um, which is actually very similar, as far as I understand, to, um, what Postgres is doing. Uh, not, not so far as the file system is concerned, but you've got this, uh, ability with Postgres to say, "Hey, go replay those transactions over there."

26:25

Aaron Francis

Mm-hmm.

26:25

Kent C. Dodds

Uh, and so architecturally, from what I was already doing, it's very similar. Um, and SQLite is not so dissimilar from Postgres. Uh, they're, they're... I think the biggest change I had to make was, uh, I had enums for-

26:38

Aaron Francis

Mm-hmm

26:38

Kent C. Dodds

... my roles, and I had to, uh, change those to just strings, uh, which is, you know, it's whatever. I actually, i- in retrospect, I regret using enums in the first place, and- ... um, and so m- I, I, if you're-

26:53

Aaron Francis

That was a, that was a happy little coincidence there.

26:56

Kent C. Dodds

Yeah, exactly. Um, so yeah, that, that worked out really well. And what's really cool about SQLite, what I, uh, I didn't th- consider this when I was migrating, but what I realized was, uh... Well, let me back up. So on the blog post page, I show you this, uh, your, your re- read rankings of all the different teams. Um, but the way that I calculate that is kind of interesting, because I wanna make sure that it's fair.

27:20

So I'm not just saying the number of people from each team, and that's your score. It's, like, how many, um, people relative to how many people are on the team, and how many of those people are active. And so, like, I have to know-

27:33

Aaron Francis

Oh, yeah

27:33

Kent C. Dodds

... and, and they're active if they've read a blog post in the last year or something like that. And so I have to do a lot of, uh, calculations.

27:40

Aaron Francis

Mm-hmm.

27:40

Kent C. Dodds

And maybe if I were, uh, interested in spending a lot of time in SQL, I could do this in a single query, but I'm not.

27:48

Aaron Francis

Mm-hmm.

27:48

Kent C. Dodds

And so, uh, so I do this. I think it takes, like, nine queries to do all of the, uh, get all of the data that I need, and then I do a lot of calculations. And so, um, as a result, I was like, "Okay, I'm gonna just, um, cache all of this stuff." And, and it was really easy, 'cause I had my cache, uh, with Redis and everything.

28:04

Aaron Francis

Mm-hmm.

28:04

Kent C. Dodds

Uh, now I'm using SQLite instead of Redis as well, so I, I have two databases-

28:08

Aaron Francis

Love it

28:08

Kent C. Dodds

... for the cache. But, uh, what is interesting is I could probably remove the cache now, because queries with SQLite are just so insanely fast that-

28:18

Aaron Francis

It's crazy, right?

28:19

Kent C. Dodds

Like, yeah. It's, it's nuts. Um, and so I could probably remove that cache. Um, but that was one thing that I was very excited to, to find, is, like, when you don't have latency, it-

28:29

Aaron Francis

Mm-hmm

28:29

Kent C. Dodds

... it's not just that, like, oh yeah, these two boxes are in the same data center, and so they're, like, really, really fast. No, they're literally on the same machine.

28:37

Aaron Francis

Mm-hmm.

28:37

Kent C. Dodds

So there's no network latency at all. Uh, it's, it's outrageous how fast, uh, these queries were, so I was very-

28:44

Aaron Francis

Yeah

28:44

Kent C. Dodds

... excited about that.

28:44

Aaron Francis

One of the weird, one of the weird, like, um, advantages of SQLite is, uh, like, you don't have to worry about N+1 anymore. And, like, in my, in my bones, I'm like- ... "Well, I still wanna kinda worry about it." Like, it feels better to, it feels better to do it right. But yeah, when your, when your, your latency is microseconds instead of milliseconds, it's like, ah, I'm gonna spend my time doing something else.

29:07

Kent C. Dodds

That... And, a- Aaron, that's exactly the right attitude to have, and sometimes I forget to have that attitude. But-

29:12

Aaron Francis

Mm-hmm

29:12

Kent C. Dodds

... it's not just like, "Oh, this doesn't matter." Oh, it, it does still matter. Like, if you have-

29:18

Aaron Francis

Mm-hmm

29:18

Kent C. Dodds

... a lot of que- like, that, that could be a problem. But what, what SQLite enables for the N+1 problem is that, like, it matters, uh, or it impacts you less, and so you can focus on other things that matter more.

29:30

Aaron Francis

Mm-hmm.

29:30

Kent C. Dodds

Uh, and so it's just one less thing that matters, uh, as much as the other things. So yeah-

29:35

Aaron Francis

Mm-hmm

29:35

Kent C. Dodds

... I was very excited about that.

29:37

Aaron Francis

Yeah. Yeah, that's awesome. Okay, so Lightstream, um, not in use on your blog, is, uh... Lightstream is primarily single-point disaster recovery. So you have, uh, SQLite on a machine, and it's streaming out to S3 the changes, and nobody else is listening, just S3.

29:57

Kent C. Dodds

Mm-hmm.

29:57

Aaron Francis

LiteFS, you've got one, you've got one writer, and it's, like, sending out these changes to a bunch, potentially a bunch of different, uh, listeners who are the readers. Um-

30:06

Kent C. Dodds

Mm-hmm

30:06

Aaron Francis

... so then in-

30:08

Kent C. Dodds

And, and sorry to interrupt, Aaron.

30:09

Aaron Francis

Sure.

30:09

Kent C. Dodds

One thing I'll add to that also is, um, I... So I was able to get rid of the Postgres service and the Redis service.

30:16

Aaron Francis

Mm-hmm.

30:16

Kent C. Dodds

And so now I just have one, one web server, but I do still have the console service, which is the, the... A- and that's all managed by Fly. I, like, I barely-

30:26

Aaron Francis

Mm-hmm

30:26

Kent C. Dodds

... even know it's there, but- Uh, I do know it's there if, if things get out of sync. Uh, but that hasn't happened in a long time. I think they've really matured that, but-

30:34

Aaron Francis

Mm-hmm

30:35

Kent C. Dodds

... um, yeah, it i- it is another service that, like, is, uh, the primary election, um, thing. So I, I have, um, my, my primary database is where all the writes need to come into.

30:46

Aaron Francis

Mm-hmm.

30:47

Kent C. Dodds

So if someone wants to change their, um, their username or whatever, that's gotta come to the primary region. And so I put that in the region that is most central to most of my users. Um, and then I actually put two instances, we can talk about this more, but I, I put two instances in that region, which we can talk about later. Um, and then, um, yeah, and so when, uh, when my app is deploying, uh, the instance in that region just lets everybody know, "Hey, I'm the primary," and, and Console, like,

31:17

sends that out to everybody. So there is still another kind of service hanging out in the background-

31:22

Aaron Francis

Hmm

31:22

Kent C. Dodds

... uh, but that's managed by Fly.

31:24

Aaron Francis

Okay. That's super interesting. How is the, um... You'll have to forgive me, 'cause I don't know s- too much about Console. I know what it does, but I, that's about it. So how do you, as, like, the, the, the person orchestrating this, how do you declare what's primary? Like, 'cause you want it in a region that, of your choosing-

31:44

Kent C. Dodds

Mm-hmm

31:44

Aaron Francis

... so you can't just leave it up to the system to say, "Elect somebody else." So how do you constrain it to, let's say, DFW or what- whatever you've chosen?

31:51

Kent C. Dodds

Yeah, yeah. Uh, it's great question. So this is configured in the LiteFS configuration.

31:56

Aaron Francis

Got it. Okay

31:57

Kent C. Dodds

Um, and so you have a, this LiteFS YAML file, um, and it's, you know, got a bunch of options, but one of them is the lease type. And so you, you can, uh, just say static lease every time it's gonna be in DFW or whatever. Uh, and the, the, the benefit to that is it's really easy, really simple.

32:17

Aaron Francis

Mm-hmm. Sure.

32:17

Kent C. Dodds

But the drawback is that, um, if that region falls over, then you have no more primary. There's, nobody else-

32:24

Aaron Francis

Whoops

32:24

Kent C. Dodds

... can take over. Uh, yeah, exactly. So not great.

32:28

Aaron Francis

Bad news.

32:29

Kent C. Dodds

Yeah.

32:29

Aaron Francis

Yeah.

32:30

Kent C. Dodds

Yeah. Uh, and so, like, uh, one of the... Well, the, the primary benefit I was going after by doing multi-instance was for performance. Um-

32:39

Aaron Francis

Mm-hmm

32:39

Kent C. Dodds

... but another benefit to that is for failover. Uh, and so if one of the instances goes bad, then the others can handle it and it's fine. Um-

32:47

Aaron Francis

And so are you saying you run, let's say you run one in Sydney, one in Japan, one in California, and then two in DFW?

32:56

Kent C. Dodds

Yeah. Mm-hmm.

32:56

Aaron Francis

It's pr- Assuming DFW is your primary.

32:58

Kent C. Dodds

Yep, yep.

32:59

Aaron Francis

Oh, okay.

33:00

Kent C. Dodds

And-

33:00

Aaron Francis

Cool. That makes sense

33:00

Kent C. Dodds

... and there are two reasons that I do that. So one is if one of those regions falls over, then the other can take, um, primary.

33:06

Aaron Francis

Mm-hmm.

33:06

Kent C. Dodds

Um, and actually, before I say that, I should also mention you don't have to specify which region is your primary. You could just say, like, whatever, any instance can be primary, it's fine. And that would probably be fine for lots of applications. Um, people typically are okay with their writes taking a little bit longer than their reads. Um, that's, like, a pretty normal thing to hit save-

33:26

Aaron Francis

Mm-hmm

33:26

Kent C. Dodds

... and wait a second, like it's whatever. Um, but, uh, but yeah, it's important enough, uh, to me, so I, I do say my, um, in, in the LiteFS config, you have the lease, and then you can say the type is Console. Candidate is, uh, a Boolean of true or false, but you can put an expression in there. And so I say if the Fly region is equal to the primary region, these are environment variables-

33:49

Aaron Francis

Hmm

33:49

Kent C. Dodds

... um, then it can be, uh, a candidate for being, um, a primary. So-

33:54

Aaron Francis

Cool

33:54

Kent C. Dodds

... um, yeah.

33:55

Aaron Francis

Okay.

33:55

Kent C. Dodds

The, so there are two reasons-

33:57

Aaron Francis

So LiteFS handles that. It just happens to work super well with Fly, but that's part of the LiteFS configuration.

34:03

Kent C. Dodds

Yes, 100%.

34:04

Aaron Francis

Okay, cool.

34:04

Kent C. Dodds

Yeah.

34:04

Aaron Francis

All right, cool. Carry on.

34:06

Kent C. Dodds

So yeah. So there are two reasons to, to have two instances. One is if one falls over, then the other can, can take over. Uh, but then the other is during deploys, uh, the, the unique thing about, um... Well, let's, let's talk about doing deploys of, of regular applications that aren't using LiteFS and SQLite. They're, we're just connecting to a Postgres or MySQL, whatever.

34:27

Aaron Francis

Mm-hmm.

34:27

Kent C. Dodds

You can spin up a, a new instance of your app, and you've got the one that's already handling the traffic, and then, um, you say, "Okay, don't handle traffic anymore and send it over to this one 'cause now this is..." And, and they're both connected to that database at the same time, and it's fine.

34:40

Aaron Francis

Yep.

34:41

Kent C. Dodds

The problem is with SQLite is you, you have your volume that has a SQLite database, and that, that volume can only be attached to one VM at a time.

34:49

Aaron Francis

Hmm.

34:49

Kent C. Dodds

And so during the deploy process, uh, this one's coming up, but it can't actually come up until that volume has been moved over and attached to this new VM. And so what that means is during that process, like, okay, so we're gonna detach this volume from the old one, we're gonna attach it to the new one, and then, uh, we're gonna start the new one. Like, we can't even-

35:09

Aaron Francis

Mm-hmm

35:09

Kent C. Dodds

... start it until the volume's been attached. And so-

35:11

Aaron Francis

Mm-hmm

35:12

Kent C. Dodds

... there's, like, seconds, uh, depending on how fast that you, your deploy happens, but yeah, several seconds where your application's just not responsive to users.

35:20

Aaron Francis

Hmm.

35:21

Kent C. Dodds

Um, and some applications that's fine. Like, that's not a big deal for some. Um, but for, uh, the types of UX that I'm going for, it's not.

35:29

Aaron Francis

Mm-hmm.

35:29

Kent C. Dodds

And so that is why I have two regions so that, um, they, they kinda do it one region or one instance at a time. Uh, sorry, but that's why I have two instances, is, um, they'll take that-

35:40

Aaron Francis

Two instances

35:40

Kent C. Dodds

... primary and that's, that's still handling traffic, then they'll take that secondary and drop that one, then they'll bring up the new version, and then they can, um, transfer the volume over to that. And the old primary or the old, uh, old in... When... Sorry. When the primary drops- ... then it can transfer over to the other instance while this new primary shows up. And so, like, the, the blue-green deploy works a lot better-

36:04

Aaron Francis

Mm-hmm

36:04

Kent C. Dodds

... um, when you have those multiple instances and can just switch traffic over, switch the volume over inst- um, uh-

36:10

Aaron Francis

So let me-

36:11

Kent C. Dodds

Yeah

36:11

Aaron Francis

... let me see if I got it. You've got, um, you've got a bunch of regions, but one region is your primary. So in your primary region, you have two instances. We'll say primary A, primary B. And you're deploying a new version of the app, and so you need primary A V2 and primary A... or primary B V2.

36:33

So you've got these two primaries, um, or these two instances in the primary region where one of them is actually the primary SQLite writer.

36:42

Kent C. Dodds

Mm-hmm.

36:43

Aaron Francis

And so, um, what you're saying is you ... can't have no downtime if you just have one primary because that volume has to switch, which causes downtime.

36:54

Kent C. Dodds

Yes.

36:54

Aaron Francis

And so what I'm understanding you saying is you switch, you tell, uh, or someone tells LightFS that, "Hey, let's send all writes to primary B," and then primary A is gonna go through the V2 upgrade. And then do you switch all the writes to primary A V2, and then you bring primary B up to V2?

37:17

Kent C. Dodds

Yeah. That, that's pretty close. So, so the, the primary A, which is the actual-

37:22

Aaron Francis

Uh-huh

37:22

Kent C. Dodds

... primary V1, that's gonna-

37:24

Aaron Francis

Uh-huh

37:24

Kent C. Dodds

... stay primary. Primary B is gonna fall over, and we get a new primary B. This is the V2 now.

37:29

Aaron Francis

Uh-huh.

37:29

Kent C. Dodds

And so then this one says, "Hey, uh, I can be the primary now." And so then-

37:35

Aaron Francis

Got it. Okay

37:35

Kent C. Dodds

... primary switches over here, and now primary A V1 can drop, and we get a new primary A V2, but primary B-

37:41

Aaron Francis

Got it

37:41

Kent C. Dodds

... is now the actual primary.

37:42

Aaron Francis

And next time it'll switch.

37:43

Kent C. Dodds

Yep.

37:43

Aaron Francis

And so it kind of hops back and forth between A and B depending on the de- the deploys.

37:47

Kent C. Dodds

And, and you know what's super cool is it took me, like, forever to figure out that's how it worked, and it didn't matter that I didn't understand it. It just worked.

37:56

Aaron Francis

Oh, that's great. So the... I guess, the, the high level is you put two instances in one region and then tell LightFS either of these can be primary, and then you're, you're off. You, you don't have to worry about it.

38:09

Kent C. Dodds

Yep. Exactly.

38:10

Aaron Francis

That's great.

38:11

Kent C. Dodds

That's awesome.

38:11

Aaron Francis

I love that. That's cool. That's super cool. Very smart and very, very easy, uh, if you're not writing LightFS, which neither of us are, so we get to-

38:19

Kent C. Dodds

Yeah

38:19

Aaron Francis

... just benefit from it, which is great.

38:21

Kent C. Dodds

Yeah, yeah. There were a lot of interesting challenges that I came across as I was using LightFS, which had, like, this very clear warning. In fact, I started using it before they decided to add the warning, but they had a warning for a long time, "Not production ready."

38:35

Aaron Francis

Mm-hmm.

38:35

Kent C. Dodds

Um, and so I was-

38:37

Aaron Francis

And you're like, "I don't care, baby."

38:39

Kent C. Dodds

Yeah. No, exactly. I was just like, "This is the future. I can tell." "This is gonna be awesome, so I'm gonna bet heavy, and I'm gonna go through a lot of pain -

38:47

Aaron Francis

Mm-hmm

38:47

Kent C. Dodds

... to, uh, uh, to go through this." But, uh, yeah, it ended up being, uh, w- working out pretty well. But I can tell you a couple of the interesting challenges that I faced-

38:57

Aaron Francis

Yes, please

38:57

Kent C. Dodds

... uh, that LightFS is h- handling now. So, so first of all, like, the, the data migration was, was interesting. Uh, I did have enums and stuff, and I'm, I'm not smart enough to do, like, the, you know, the widen, the narrow... Well, no, I, I am smart enough. I know how to do that, the wide and narrow migrations-

39:13

Aaron Francis

I was gonna say. Yeah

39:13

Kent C. Dodds

... and zero downtime. I know how to do that, uh, and that's actually documented how to do that in the Epic Stack and stuff, but I didn't care enough.

39:20

Aaron Francis

Right.

39:20

Kent C. Dodds

That was what it really was. And so I, I, like... I wrote this little script locally, um, to, like, read all of the, uh, data from the PostgreSQL database and save it in a SQL file, and then I FTP, SFTP that up to my box. And, and that's how I did the data migration, which was kind of interesting.

39:36

Aaron Francis

Love it.

39:37

Kent C. Dodds

Uh, and, and most of the app code didn't need to really be changed 'cause I use ORM. I use, uh, Prisma.

39:42

Aaron Francis

Mm-hmm.

39:42

Kent C. Dodds

But a couple of things that were kind of interesting that I ran into that were a problem for, um, um, for LightFS, uh, is, uh, consider this scenario, and this actually, uh, was the case with PostgreSQL as well. But because PostgreSQL is, uh, a bit slower, uh, you never really ran into this problem.

40:04

But here, here's the scenario. So I'm in Amsterdam-

40:07

Aaron Francis

Mm-hmm

40:08

Kent C. Dodds

... and I want to update my name on your website. And so I say, "Hey, I'm gonna go update my name." What happens is that request comes into the Amsterdam, the AMS region, my instance-

40:18

Aaron Francis

Mm-hmm

40:18

Kent C. Dodds

... and that instance is like, "Oh, hey, hold on a second. I can't handle writes, so I'm gonna send a response that has this special header called Fly Replay."

40:27

Aaron Francis

Mm-hmm.

40:27

Kent C. Dodds

And Fly is gonna see that header on that response and be like, "Oh, you don't actually wanna send that to the user. You wanna send it to this instance that you wanna replay to." So I say, "Fly Replay DFW."

40:37

Aaron Francis

So cool.

40:37

Kent C. Dodds

And so Fly is like, "Okay, I'll, I'll throw away that, and I'm gonna take that same request that was sent before and send it to a- uh, DFW instead." And that way-

40:46

Aaron Francis

So that response never makes it out. It gets caught by Fly and says, "Hang on, send it to DFW, and we'll redo it."

40:53

Kent C. Dodds

Yes, exactly.

40:54

Aaron Francis

So cool. So cool.

40:55

Kent C. Dodds

Yeah, it is very cool. Yeah, it's super awesome. And that, that actually can, uh... It's a little bit tricky, uh, how to make all of that work because, like, I don't wanna do checks everywhere in my code to say, "Are you gonna write? Then let's do this."

41:08

Aaron Francis

Sure.

41:09

Kent C. Dodds

But anyway, that, that, that s- in some ways becomes a little bit of an application code problem, um, and, uh, sometimes. But anyway, what's, uh, what, what, uh, the problem arises is that, okay, so now we're replaying that request to a, uh, DFW. The write happens, and then the response goes back to the user, and so that write now is propagating to all the regions.

41:35

But let's say that the response gets back to the user, and the user makes a request for updated data-

41:41

Aaron Francis

Mm-hmm

41:41

Kent C. Dodds

... before that propagation happens. It, it typically will happen in 200 milliseconds or less.

41:46

Aaron Francis

Mm-hmm.

41:46

Kent C. Dodds

Um, but, like, this could be very fast. Like, this, uh-

41:49

Aaron Francis

Sure

41:50

Kent C. Dodds

... that response to the user from DFW back to AMS and then AMS back to its region close by-

41:56

Aaron Francis

Mm-hmm

41:56

Kent C. Dodds

... that can happen. Uh, I, I saw it happen. Um-

41:59

Aaron Francis

Hmm

41:59

Kent C. Dodds

... and so you end up with stale data, um, because you're reading an old replica, uh, data that hasn't re-

42:05

Aaron Francis

Mm-hmm

42:05

Kent C. Dodds

... um, replicated yet. And this, I, I-

42:07

Aaron Francis

So you're saying if, if the user in AMS sends a write to DFW and then hits a endpoint that's read-only, they're gonna read from the local AMS copy, and that write may still be propagating from DFW to AMS at, at sub-speed of light. And so they may, they may get some stale data if they refresh-

42:27

Kent C. Dodds

Yeah

42:27

Aaron Francis

... pretty quickly. Okay.

42:28

Kent C. Dodds

Yep, exactly. And, and the further you are away from the primary instance, the more likely this is to happen-

42:35

Aaron Francis

Mm-hmm

42:35

Kent C. Dodds

... um, give or take. Depends on how fast your internet connection is. But, um, yeah. So this is... A- and how close you are to the, the region that you're at. Um, but yeah.

42:43

Aaron Francis

Mm-hmm.

42:43

Kent C. Dodds

This definitely happens. Uh, and at scale, even edge cases become common. And so-

42:48

Aaron Francis

Mm-hmm

42:49

Kent C. Dodds

... uh, this is something that you wanna really think about. Um-

42:52

Aaron Francis

Did you come up with that? I love that. At scale, edge cases become common.

42:55

Kent C. Dodds

Yeah. I, I-

42:56

Aaron Francis

Is that you?

42:57

Kent C. Dodds

I think I came up with that specific phrase, but this is something that my brother-

43:00

Aaron Francis

That's great. I love that

43:01

Kent C. Dodds

... who... My brother works at- ... Microsoft, he's a, a director on the Azure team. He, he's in charge-

43:06

Aaron Francis

Cool

43:06

Kent C. Dodds

... of all memory, um, at, uh, on Azure, which is kinda interesting.

43:10

Aaron Francis

Wow.

43:10

Kent C. Dodds

Um-

43:10

Aaron Francis

Yeah, that's a lot.

43:11

Kent C. Dodds

But yeah, he said, "Yeah, Kent, at scale," um, you know, something, something, and I turned it into, uh, that phrase. So yeah.

43:18

Aaron Francis

Well, well, sorry to Brother Dodds, that's Kent's phrase now.

43:21

Kent C. Dodds

Yeah, now it's mine.

43:21

Aaron Francis

That's a good phrase, and we give all credit to Kent.

43:24

Kent C. Dodds

Yeah. Um, but, uh, yeah, so I, I don't wanna have this problem, and so I developed a, a little library that would, um, set a cookie when a, a write response was sent. And so it sets, uh, uh, SQLite or, or Litefs keeps a transaction, uh, record. This is something that it already did. There was a file that ha- was the transaction number or some identifier for that transaction.

43:49

Um, and that just auto-increments over time.

43:52

Aaron Francis

Mm-hmm.

43:52

Kent C. Dodds

And so I could say, "Okay, here's your transaction ID." It, it had, like, the, some hash of something, and then also the, the in- the number. So-

44:01

Aaron Francis

Mm-hmm

44:01

Kent C. Dodds

... anyway, I'd say, "Here's your transaction ID." Then when the request for, uh, from AMS going to that region went out, uh, AMS would say, "Do I have that transaction?"

44:11

Aaron Francis

Huh.

44:11

Kent C. Dodds

"Am I that far along?"

44:13

Aaron Francis

Yeah.

44:13

Kent C. Dodds

And if it's not, then it just makes the user wait until that, uh, replication happens, and then it sends, uh, y- it lets the request go through.

44:21

Aaron Francis

Oh, that's interesting. So you're not even doing, like, sticky sessions. So you're not, you're not forcing that AMS user to reconnect to DFW for some arbitrary period of time, which would be a best guess.

44:32

Kent C. Dodds

Mm-hmm.

44:33

Aaron Francis

What you're doing is you've solved it absolutely by saying, "All right, here's your, here's your high water mark, and until AMS user sees this high water mark in AMS server, just hang on a second 'cause I swear it's gonna be there." That-

44:47

Kent C. Dodds

Yes

44:47

Aaron Francis

... that's kind of your strategy? I love that.

44:49

Kent C. Dodds

Yeah, exactly.

44:49

Aaron Francis

That's great.

44:50

Kent C. Dodds

Thank you.

44:50

Aaron Francis

I, I am familiar with sticky sessions. This is not something, um, this is not something I had considered. I like that.

44:56

Kent C. Dodds

Yeah, so there are a couple things I wanna say about that. First of all, um, this is... You'll, you'll hear a lot of people say, "Oh, you don't wanna do distributed databases because, like, that's so complex. There's so many things-

45:08

Aaron Francis

Mm-hmm

45:08

Kent C. Dodds

... like, that can go wrong." I'm pretty confident this is the thing that most of them are talking about. And-

45:14

Aaron Francis

Mm-hmm

45:14

Kent C. Dodds

... um, I, I just figured that out and, like, that was it. I don't know. I, like, so when they say that, I'm like, it's actually n- it's not that hard.

45:22

Aaron Francis

Yeah.

45:23

Kent C. Dodds

Um, but the other-

45:24

Aaron Francis

You're like, "What a- what am I missing? 'Cause it's not that hard."

45:28

Kent C. Dodds

Yeah, exactly. I'm probably still missing something, I could be wrong. Um, but the other thing I wanted to call out about that is I'd never heard of sticky sessions until you just said that. A- and when you say that, I know exactly what you mean, and that makes total sense-

45:40

Aaron Francis

Sure

45:40

Kent C. Dodds

... to do it that way. But this is just, like, an interesting thing about, m- um, the world, is that, um, if I had known about sticky sessions, I probably would've just done that. But I like my solution better. Uh, and-

45:53

Aaron Francis

Mm-hmm. I do too.

45:54

Kent C. Dodds

I, I wouldn't have even come, come up with it if I had already known. And so, like, the curse of knowledge is a real thing. And-

46:00

Aaron Francis

Mm-hmm

46:00

Kent C. Dodds

... um, I think that, uh, it's useful to, uh, get new perspectives on problems. I'm not a d- database person. This is not-

46:08

Aaron Francis

Mm-hmm

46:08

Kent C. Dodds

... a problem that I'm faced with very often. That's probably why I didn't really know about sticky sessions.

46:12

Aaron Francis

Mm-hmm.

46:12

Kent C. Dodds

But, uh, um, I think that it's okay for people to try things that they have no business doing, because maybe you'll come up with something that's pretty awesome. Um-

46:22

Aaron Francis

Yes

46:22

Kent C. Dodds

... and, and-

46:22

Aaron Francis

And to keep, to keep it on theme, even the creator of SQLite said, "I didn't know I wasn't supposed to write my own database." Like, I just-

46:29

Kent C. Dodds

Mm

46:29

Aaron Francis

... I didn't know that, I didn't know you weren't allowed to do that, and so I did it.

46:33

Kent C. Dodds

Yeah.

46:33

Aaron Francis

And I feel, it feels like the exact same thing. Like, I'll sometimes get questions on videos of, like, "Why did you, why did you make a video about this?" And it's, I thought it was cool. Like, I thought it was cool.

46:42

Kent C. Dodds

Yeah.

46:42

Aaron Francis

And I thought, "This is really fun. I'm gonna do it." And I, I really, really like that vibe. Like, "Hey, I'm gonna try and see what happens, and maybe it'll work."

46:50

Kent C. Dodds

Mm-hmm. Yep. Uh, that, that is also why just yesterday I started implementing my own background job, um, service.

46:58

Aaron Francis

I saw that. Yeah.

46:59

Kent C. Dodds

Yeah.

47:00

Aaron Francis

I saw that. You wanna, you wanna talk batteries included framework? You're doing background jobs? Okay. This is awesome. I love it.

47:08

Kent C. Dodds

Yeah. I actually... So I, I'm not gonna give anything away, but I am, uh, it's going to be amazing. Uh, and I'm actually- ... not even gonna have to, have to build the whole thing myself at all, um, uh, which is why it's gonna be amazing.

47:19

Aaron Francis

I, I saw, like, three or four, three or four of the heavy hitters come out and be like, "Hey, I, I can help you." It's, like, the Redwood guy, the Ingest guy, somebody else. We're like, "Oh, well, we'll help you." It's like, "This is awesome."

47:30

Kent C. Dodds

Yeah, yeah. It's gonna be pretty sweet. Um, but yeah, so one other thing I wanted to mention is that, um, so I put this together in a library, uh, for Litefs that has, uh, on MPM, that has, like, information about, am I on the primary region? And if I'm not-

47:44

Aaron Francis

Cool

47:44

Kent C. Dodds

... what is the primary region? And, uh, or instance. And also, um, like, s- the, the utilities for setting the cookies and, and waiting-

47:52

Aaron Francis

Mm-hmm

47:52

Kent C. Dodds

... and all that stuff. I put that in a little library. M- but I inter- I talked with, uh, with Ben a lot about that, and he, they put it on the fly, uh, the Superfly, uh, GitHub org. So you can go find it.

48:03

Aaron Francis

Cool.

48:03

Kent C. Dodds

Um, and, uh, the Epic Stack actually does use this 'cause it can be useful to know whether you're in the primary or not. Um-

48:09

Aaron Francis

Mm-hmm

48:09

Kent C. Dodds

... but, uh, yeah, the, the cookie, uh, the eventual consistency problem-

48:15

Aaron Francis

Mm-hmm

48:15

Kent C. Dodds

... uh, was su- such a, a good solution that Ben built that into Litefs. And so now, he actually mentioned this in your episode with him, um, but, uh, yeah, there's a proxy server that handles that for you. So it, it handles, uh, setting the cookie and waiting on the request, and, uh, it just does this-

48:33

Aaron Francis

Hmm

48:33

Kent C. Dodds

... in, in kind of a simple, dumb way, uh, where-

48:36

Aaron Francis

Mm-hmm

48:36

Kent C. Dodds

... like, get requests are just gonna go straight through a- and those are gonna wait on the cookie. Uh, but any- anything other than a get request is going to set the cookie, and it's, uh, gonna... And, and also it handles replaying, uh, the request to the primary as well. Uh, so-

48:51

Aaron Francis

Oh

48:51

Kent C. Dodds

... most application ... developers don't need to worry about this or think about it at all. The only time that you'll run into a problem is if you need to do a mutation on a get request, which definitely does happen. You, you typically don't wanna do that, but, like-

49:03

Aaron Francis

Yeah

49:03

Kent C. Dodds

... examples of when you would is if you wanna keep track of, uh, user activity, like the, the, yeah, this user-

49:09

Aaron Francis

Sure

49:09

Kent C. Dodds

... is still doing stuff. Or, uh, even more common is, um, let's go and revalidate this cached value. So this u- user requested it, it's stale, we'll send it back, and we'll revalidate it in the background.

49:20

Aaron Francis

Mm.

49:21

Kent C. Dodds

Uh, and so there are still situations where you do need to think about this in your application code. Um, I've packaged up the caching stuff in, in, uh, the Epic Stack, and I'm gonna actually turn that into a library soon. But, um, yeah, for the most part, uh, this, this is probably the, the leakiest part of this LiteFSX-

49:38

Aaron Francis

Mm-hmm

49:38

Kent C. Dodds

... abstraction. And it's-

49:40

Aaron Francis

Mm-hmm

49:40

Kent C. Dodds

... uh, it's duct taped pretty well.

49:43

Aaron Francis

Yeah, it sounds like it. And just, just to put a fine point on it, it sounds like the non-database guy that pretends that he's a reluctant DBA, i.e. you, told Ben this strategy, and he was like, "This is awesome. I'm gonna build it straight in." So I don't know. You might- You might be a database guy.

50:00

Kent C. Dodds

I know.

50:01

Aaron Francis

I know. Welcome.

50:02

Kent C. Dodds

You gotta-

50:03

Aaron Francis

Join us

50:03

Kent C. Dodds

... you gotta be really careful what you get good at.

50:05

Aaron Francis

You do. You do. You wander down a dark alley, and suddenly you're a DBA. So you gotta look out, man. So how does this inform-- We've talked about the Epic Stack a, a little bit. Um, how does this inform some of the decisions you're making? Because would you say you're building a, a framework? Is that what you would say the Epic Stack is?

50:27

Like, is that the name you would give it?

50:28

Kent C. Dodds

Yeah. Yeah. I, I would-

50:30

Aaron Francis

Okay. So-

50:30

Kent C. Dodds

Uh, in, in, in the, in the front-end world, like the framework and library are kind of mixed.

50:36

Aaron Francis

I know.

50:36

Kent C. Dodds

Like, a lot of people say React is a framework, and other people will get mad at you if you do that. But then-

50:40

Aaron Francis

Mm

50:41

Kent C. Dodds

... uh, like Next.js, and Remix, and Redwood, they're all built on top of React, so are they the frameworks, or are they meta-frameworks?

50:46

Aaron Francis

But are they-- What's a meta-framework?

50:48

Kent C. Dodds

Yeah.

50:48

Aaron Francis

Who knows what a meta-framework is?

50:49

Kent C. Dodds

Yeah.

50:49

Aaron Francis

Okay. So, all right.

50:51

Kent C. Dodds

So, um, and-

50:51

Aaron Francis

Ver- verbi- verbiage aside, you're building, uh, Epic Web or Epic Stack. How does all of this experience inform, uh, inform some of the decisions you're putting, like you're baking in to the Epic Stack?

51:05

Kent C. Dodds

Yeah. That's-- So the Epic Stack is-- It, it's not quite, or, or it's certainly not close to the level of a Laravel or a Rails where, like, things are all built in. It's, it's all, um, a cohesive package. Uh, the Epic Stack is very much JavaScript, uh, sort of thing, where it's cobbled together dependencies and stuff.

51:26

Um, and-

51:27

Aaron Francis

We'll call it bespoke. I'll give you, I'll give you-

51:29

Kent C. Dodds

Yeah

51:29

Aaron Francis

... bespoke. Yeah.

51:30

Kent C. Dodds

Be- bespoke is, yeah.

51:31

Aaron Francis

Yeah.

51:31

Kent C. Dodds

Bespoke is good. Um, I think that, like, culturally, the JavaScript ecosystem actually thrives on that, uh, at least the React side of things. Like, the, there's Angular and Ember. They were all like, you know, batteries included type of framework, um, where React was like, uh, you bring your own batteries. And-

51:48

Aaron Francis

Mm-hmm

51:49

Kent C. Dodds

... and I think, um, we probably won't ever get away from that in the front-end ecosystem. We just like putting these pieces together. Um, so that, that's what the Epic Stack is right now. I do want to do, um, like swallow up more things. I don't wanna build an ORM. Prisma's a great ORM.

52:06

Aaron Francis

Sure.

52:07

Kent C. Dodds

Um, but uh, like, for the things that aren't put together, uh, nicely, I'm going to just do it myself. And, and so yeah, over time, more and more things in the Epic Stack will become libraries, like the caching stuff that I was talking about.

52:20

Aaron Francis

Mm-hmm.

52:21

Kent C. Dodds

But, uh, yeah, for right now, um, the Epic Stack is, um, a, a project generator, uh, and reference-

52:29

Aaron Francis

Mm

52:29

Kent C. Dodds

... uh, for people. And, um, yeah, and I-- pretty much everything that I've built up to this point with, um, my personal website, uh, all of the good parts are going into the Epics or have gone into the Epic Stack, um, and, and then, and then some. Uh, so it has, like caching, it has all the testing stuff you would expect, it has, uh, and it comes with, with tests already around the authentication stuff, two-factor authentication-

52:55

Aaron Francis

Okay

52:55

Kent C. Dodds

... uh, third-party, uh, uh, authentication, uh, which is like a hop, skip, and a jump to SSO. Uh-

53:01

Aaron Francis

Mm-hmm

53:01

Kent C. Dodds

... and there are examples of, of all of that stuff too. Um, a- as well as, like, your, uh, components and, and different things, and all of that, uh, themeable and stuff like that. So, uh, and yeah, uh, using LiteFS pre-configured, uh, you have a CLI that you can get, uh, something into production in just a few seconds, uh, onto Fly.

53:23

Uh, and eventually I will have like a, a deploy with Fly button that, like, you connect your GitHub, you connect your Fly, and, and it will get an app up and running for you. Uh, yeah. I got a lot of work to do.

53:35

Aaron Francis

Yeah. No, it sounds, sounds like you have a good vision for it, and I like-- One, one of the things, um, I talked to DHH about his usage of SQLite and kind of in the, the Rails ecosystem, and one of the things that stuck with me from what he was saying was, um, he wants to lower, he wants to lower the entry point as much as possible for people, in his case, getting into Rails.

53:57

And so he, he looked at it and thought, like, "You know what could be a blocker? Getting a freaking Postgres container or instance up and running, and I don't want people to not pick up programming or Rails," was his words, um, "because they got stuck on Postgres." There's a lot of things to get stuck on, and if we can remove any of them, well, that's all the better for the users.

54:19

And that reminded me when you said that, you know, your website is open source, and you want people to be able to pull it down and play with it. Um, just removing that blocker is, goes a pretty long way, and it sounds like you're trying to take that into the Epic Stack, where not only play with it locally, but get it all the way deployed to, like, a pretty good production setup with as few blockers as possible.

54:41

Kent C. Dodds

Yeah. I actually, I really appreciated when DHH said that, 'cause I, I think that is just so useful, uh, to-

54:48

Aaron Francis

Mm

54:48

Kent C. Dodds

... to think about the beginners. And when we think about the beginners, the, the experts also benefit, uh, as well.

54:55

Aaron Francis

Sure.

54:55

Kent C. Dodds

Because it's easier for us. Uh, another thing that the Epic Stack has is, is mocking third-party dependencies locally.

55:01

Aaron Francis

Yeah.

55:01

Kent C. Dodds

So that, y- you know, we have a third-party dependency for, uh, sending emails, um, and, uh, like other things, um, like that. So, like, your- if you do GitHub authentication stuff, all that is, is mocked, uh, locally. And so yeah, reducing the barriers to that development experience-

55:20

Aaron Francis

Mm

55:20

Kent C. Dodds

... um, it, it really helps everybody. Um, and so especially, yeah, you and I as educators care a lot about the, uh, newcomer experience. And so yeah-

55:29

Aaron Francis

Mm-hmm

55:29

Kent C. Dodds

... that matters, uh, a lot.

55:31

Aaron Francis

Well, I am just so thrilled that you took the time to come on here and explain all of this. This is, this i- I feel so much... W- when I'm, when I'm talking to Ben Johnson, I'm like, "Oh, man, I- ... I'm way over my head." But as application developers, as educators, I feel like, yeah, okay, we can jam on some stuff here. So thank you so much for, for coming on here and doing this.

55:52

Where can, where can people find you, and is there anything else, uh, you wanna cover before we, before we call it a day?

55:58

Kent C. Dodds

Yeah. So the, the thing I work on is Epic Web. Uh, you can find that at epicweb.dev. And, uh, if- the Epic Web is actually kinda like the, the s- um, premium docs for the Epic Stack. Uh, the, the first series of workshops that I released on there, uh, is basically Let's Build the Epic Stack. And so you-

56:16

Aaron Francis

Mm

56:16

Kent C. Dodds

... get a really, really deep understanding of authentication and database and, and optimization for that database. And, uh, there's even a free tutorial on there for deploying, um, to multiple regions all over the world, um, with SQLite, uh, so take a look at that too. Um, and, uh, yeah, then you can check out my website too, kentcdodds.com.

56:36

Let me know if it doesn't load fast for you.

56:40

Aaron Francis

And where can people find you on, uh, Twitter/X?

56:43

Kent C. Dodds

Yeah. I'm, uh, kentcdodds everywhere.

56:45

Aaron Francis

Perfect. Okay. Awesome. Well, thank you again for doing this. It's been a delight, and thank you for everything you're doing for the state of education on the web.

56:54

Kent C. Dodds

Well, thank you, Aaron. I definitely appreciate all that you're doing as well.

56:59

Aaron Francis

All right. We'll talk soon. See ya.

57:00

Kent C. Dodds

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