Complete Intro to SQLite

Replication Overview

Complete Intro to SQLite

Check out a free preview of the full Complete Intro to SQLite course

The "Replication Overview" Lesson is part of the full, Complete Intro to SQLite course featured in this preview video. Here's what you'd learn in this lesson:

Brian discusses database replication and discusses tools that can replicate SQLite databases like Litefs. Litefs simulates a virtual filesystem and then replicates it across machines. It makes SQLite think it's reading and writing to a file, while underneath it is replicating it out to other replicas.

Preview
Close

Transcript from the "Replication Overview" Lesson

[00:00:00]
>> Brian Holt: So we've been building locally with SQLite here, and I would say most people end here. This is the extent of their journey with SQLite that they build something locally, they get far enough in their tutorial, and they're like, cool, it's now time to move on to Postgres.

[00:00:15]
And again, I fully endorse that path. If we're being honest, it's still what I do. But I do want to shine a light on it is possible to continue scaling with SQLite, and the way you do that, if you don't wanna use any other paid service, is something called LiteFS.

[00:00:34]
>> Brian Holt: LiteFS is made by a company called Fly. So I'm sure many of you've heard of fly.io. It's a, that is the weirdest way to say that. Anyway, I'm sorry, I got pulled away by their marketing. Fly.io is essentially, I would consider them kinda the spiritual successor to Heroku.

[00:01:01]
Heroku, for me, is the OG, really cool developer product that took the cloud market by storm by just making a really good experience. And it was expensive, but it worked really well, and everyone still liked it and was happy to pay them because it was so good to use.

[00:01:18]
And then Salesforce bought them and just let them languish forever, right? So Heroku, in my opinion, is a shadow of itself. That's not even an opinion, that's just true. Fly kinda took up that mantle. It's like, we're gonna keep this idea going. And there's a bunch of them out there now.

[00:01:35]
There's Azure App Service, there's AWS Elastic Beanstalk, Render is another good one. They're all cool, I'm a fan of all of them. Fly is definitely a good user experience as well. Whereas a GCP App Engine is their version of it, there's a bunch of them. It's essentially autoscaling VMs, essentially, is what they are.

[00:02:04]
So, anyway, they invented this where basically you can do SQLite, and then you can have it be replicated to other locations. So let's say you're running on Fly, which auto scales, right? So let's say you have your blog, it gets front page of Hacker News, all of a sudden, Fly is gonna scale you up to ten servers running your blog at the same time, right?

[00:02:31]
What's the problem with SQLite in this particular situation? You can't write to those cuz they can't all talk to each other, they're not replications of it. They're just one copy of a file running on the particular location. You can have some maybe constant restores of Litestream, but that's a terrible idea, please don't do it that way, right?

[00:02:55]
>> Brian Holt: This is what LiteFS is though. You're gonna have one primary database that you're writing to, and then when you write to that one, it's going to replicate to whatever else is subscribed to it. And then if anyone ever on those kind of replicated versions try and write to their secondary, it's just going to pass it back up to the primary.

[00:03:14]
The primary is going to write it, and it's gonna be passed back down to all the various other subscribed versions. I don't know if this is fully based on Litestream, if it's not, it's strongly inspired by it, I think they even say that in here somewhere. But that's why they're named very similar things is because Litestream came first, then LiteFS copied a lot of the idea.

[00:03:40]
And it does this based on what it calls a fuse-based system. You can read more into that how it works, but it's basically a shared file system I think it's a primitive of Linux, if I'm not mistaken. I might be because I'm a little out of my depth when it comes to that law of level of Linux kinda stuff.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now