Distributed SQLite with Litestream and LiteFS
Ben and Aaron discuss replication and backups in SQLite, Litestream and LiteFS, and future mad scientist projects Ben is working on.
Everything we said
Aaron Francis
Well, I am here with Ben Johnson, and Ben, I have something to show you that I did not warn you about.
Ben Johnson
Oh, man.
Aaron Francis
Do you, do you recognize-
Ben Johnson
Ah
Aaron Francis
... any of this?
Ben Johnson
Yeah.
Aaron Francis
Do you recognize-
Ben Johnson
I do
Aaron Francis
... these headers?
Ben Johnson
It looks better in color, though, gotta say.
Aaron Francis
It, it does look better in color. I printed out... So i- in a part, in part of my studying for this course, um, of, uh, of course, the first place I went was the Fly blog to print out all of your, uh, articles over there. And they are-
Ben Johnson
Oh, thank you
Aaron Francis
... super good, so thank you so much for writing all of those. Um, and it has that same, like, that's, I don't know if it's you or Fly, but it has that same kind of like irreverent, casual, fun, like conversational tone that I, I really like. So good job on all those.
Ben Johnson
Well, thank you. Yeah, I appreciate that.
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. So tell me, um, by way of introduction, where you're working. I, I just spoiled it, but where you're working, what you do, and how you ended up, how you ended up there.
Ben Johnson
Uh, yeah. So I'm at Fly.io right now. We do, you know, application hosting and, um, server host- Yeah, we put s- put applications everywhere kind of is our-
Aaron Francis
Mm-hmm
Ben Johnson
... our gig. Um, and I ended up there a couple years ago. Um, I did a project called Lightstream-
Aaron Francis
Mm-hmm
Ben Johnson
... which is essentially trying to make, like SQLite, um, make it work on basically a single node, so you can have like automatic backups. And like for a lot of applications, that's, it's probably good enough. I mean, unless you need some crazy like HA, high availability thing going on, then, um... Otherwise, I mean, like a simple SQLite can go a long way. Um, and then before that, um, yeah, did a lot of consulting work in Go.
I've done a lot of work on databases. Um, I did a database called BoltDB, um, that's in like the Go world.
Aaron Francis
I did not know that was you.
Ben Johnson
Yeah, I did that maybe 10 years ago.
Aaron Francis
Wow.
Ben Johnson
I was actually at Shopify at the time.
Aaron Francis
Okay.
Ben Johnson
Um, yeah. We were using LMDB at the time, uh, for like an analytics database. We'd kind of-
Aaron Francis
Mm-hmm.
Ben Johnson
I'd actually written an analytics database before that. Um, and that, that's why I kind of ended up at Shopify. We started doing analytics-
Aaron Francis
Yeah
Ben Johnson
... and we kind of wrote our own database there. And, uh, LMDB worked great, which is like another key value store.
Aaron Francis
Mm-hmm.
Ben Johnson
But we had some issue, and we could not ever track it down, but like every couple months, we'd have like one server that would just fill up the disk, and we had no idea why. And at the time, I had kind of been playing with like doing a port of LMDB to Go-
Aaron Francis
Okay
Ben Johnson
... but more just like an educational thing. And then, you know, it eventually got to the place where it was like we couldn't figure out this bug, and we had just spent forever on it. And, uh, we were like, "Hey, why don't we just try this, this little project you did on the side?" Which was, which was Bolt at the time. So-
Aaron Francis
Mm-hmm
Ben Johnson
... um, yeah, I d- did that. Uh, before that, um, I'd done a lot of work in like data visualization. Um, I was actually an Adobe Flex developer, if anybody is old enough to remember what the hell that is.
Aaron Francis
I, I feel like I've been around for a while-
Ben Johnson
Yeah
Aaron Francis
... but I don't know what Flex is.
Ben Johnson
Yeah. It's basically if you took like, um, like React, but like-
Aaron Francis
Yeah
Ben Johnson
... 15 years ago, and it was-
Aaron Francis
Okay
Ben Johnson
... on the, uh, the Flash platform essentially.
Aaron Francis
Oh, okay.
Ben Johnson
So it was back when, like before HTML and like browsers-
Aaron Francis
Yeah
Ben Johnson
... could really do a whole lot. So it was actually kind of cool, but yeah. Uh, Adobe kind of-
Aaron Francis
Yeah
Ben Johnson
... tanked with that, that kind of stuff in Flash.
Aaron Francis
Fla- Flash I remember. I was a, I was an ActionScript developer, but I don't-
Ben Johnson
Oh, nice
Aaron Francis
... ever know, I didn't ever know Flex. So-
Ben Johnson
Yeah
Aaron Francis
... most people, uh, most people would say you should never write your own database, and here you are having written at least two that we know of. And then some sort of virtual file system for other databases, and a little sidecar, and so you're just like, you're doing all the things that you're not supposed to do, and you're doing them very well it seems like.
Ben Johnson
Uh, I mean, I think the first ones weren't very good. That's kind of the, that's the trick is like-
Aaron Francis
Yeah
Ben Johnson
... make sure you get the bad ones out first, and then, uh... No, I mean, like I think that it's kind of one of those things where like it's like, you know, rolling your own crypto, like you shouldn't do that.
Aaron Francis
Mm-hmm.
Ben Johnson
But obviously there was somebody that rolled their own crypto first.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, and I think you just like kind of, if you find something, some little niche, and you just dig into it really deep and just keep going-
Aaron Francis
Mm-hmm
Ben Johnson
... um, you can just find fascinating little, little areas to dive into. So, um, I think I had a, like a little scratch I wanted to itch. I worked at a company that did like behavioral analytics, and I thought they could do it much better. I was actually the data visualization guy at the time at that place, not the database guy. Um, and this is back in like Hadoop, like when Hadoop first came out, and I was like-
Aaron Francis
Mm-hmm
Ben Johnson
... "Hey, we should use Hadoop for this thing. It'd be great." 'Cause we were spending forever like trying to actually run these reports. Um, and then I started just playing around with trying to make it faster and faster, and eventually I just wrote my own database. I think that's kind of where everyone ends up, right?
Aaron Francis
Yeah. Yeah, that is the end state for trying to-
Ben Johnson
Yeah
Aaron Francis
... make things faster, for sure. Um-
Ben Johnson
Yeah
Aaron Francis
... so I wanna talk to you about Lightstream first. So we got, we got, we have two light products, Lightstream and LightFS.
Ben Johnson
Mm-hmm.
Aaron Francis
Um, and we can, we can go super technical, so don't be shy. So I wanna hear-
Ben Johnson
Sure
Aaron Francis
... I wanna hear about, um, Lightstream and how you kinda, I guess, came up with the idea, and why you wrote this, and then we can talk about kind of how it works technically.
Ben Johnson
Yeah, sure. Um, so I think the basis for it was kind of the work I did with Bolt, um, way back in the day. I realized like-
Aaron Francis
Mm-hmm
Ben Johnson
... when you have a database right next to the application, it's really fast. Like-
Aaron Francis
Mm-hmm
Ben Johnson
... especially when you're used to using Postgres or... I mean, not that there's anything wrong with client-server databases, they're great, but there's just something about not having any overhead, like network overhead-
Aaron Francis
Mm-hmm
Ben Johnson
... that just like kinda blows your mind. And, uh, it's really simple too. Like there's no external dependencies. You just all, you bundle it all up, and it's right there.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, so I think for me it was more, um... I was trying to make like application development with Bolt try to work. Um, and it was just, there's a lot of nice things you get with, uh, like a SQL database, like schemas and like foreign keys and all that. You know, little things that-
Aaron Francis
Yeah
Ben Johnson
... you don't want to build yourself.
Aaron Francis
Little things like schemas, yeah.
Ben Johnson
Indexes, you know? Yeah. Um, so I just, eventually I was like, you know what? This is way too hard probably for- Anyone that's not a database developer.
Aaron Francis
Mm-hmm.
Ben Johnson
And, uh, I tried to look around for other, um, SQL databases that were embedded, and really it's just SQLite out there that's like the, the big one. Works on almost every language, and yeah, it's fantastic. So, um, I started developing with that, and I w- I kind of got this itch of like, what is... Like, for most applications, I think most developers, right, like, if you wanna deploy it out, it needs to have, you know, pretty good u- uptime, maybe like three nines or something.
Aaron Francis
Mm-hmm.
Ben Johnson
But like, you don't need like five nines, you don't need like crazy anything. You just want something that's simple, it's easy to run, it's cheap. Um, and the biggest thing I had an issue with was like the disaster recovery piece of SQLite.
Aaron Francis
Mm-hmm.
Ben Johnson
Where you could do like, you could do like a daily backup or even like an hourly backup, which honestly actually works great for a lot of people. We even, even have documentation on Lightstream about alternatives, and one of those is just back it up every hour, and that's-
Aaron Francis
Hmm
Ben Johnson
... that's fine.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, but if you wanna actually like track your changes so that you only have kind of this really small window of down- or of, uh, data loss in the event of like catastrophic, um, events, then, you know, something like Lightstream where you can continuously back up, like incrementally back up each little set of transactions every few seconds, um, you really like, you minimize your actual risk of data loss, and that was kind of the-
Aaron Francis
Mm-hmm
Ben Johnson
... the, the end goal. So yeah, I, I wanna make application development super simple. Run, it runs as a separate process, um, so you don't have to like, your application doesn't have to know about it in particular.
Aaron Francis
Mm-hmm.
Ben Johnson
Uh, that was kind of a big design goal as well.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, anyway, yeah, I'm just kind of rambling now, but that's kind of where it came from.
Aaron Francis
No, no, no, this is, this is great. And I think one of the things that, uh, was so fascinating to me about kind of the structure of it or the, the, the architecture of it, um, and forgive me if this is, uh, naive and/or wrong, it, it seems like you, um, the final product is you looked at SQLite and were like, "How do I do this without basically touching SQLite internals," right?
'Cause they're very, they're very like, "We're open s- we're source available, but we don't take PRs. We don't-
Ben Johnson
Yeah
Aaron Francis
... take anything. It's us three guys that have been doing it since the early 2000s, we're gonna keep doing it."
Ben Johnson
Yeah.
Aaron Francis
And so that kind of puts, um, that kind of puts an interesting constraint on, I wanna do something with SQLite, but I can't really like get inside it. And so I think the, the approach you took was kind of trick it to be this long-running, like it works, you know, it keeps like a transaction open and it hijacks the checkpoints or something like that.
And that to me is like, oh, that's in- incredibly... Like, that's very clever because then people still get to use like vanilla out of the box SQLite and then put your thing beside it. So can you tell me a little bit about like the, the architecture and the, the structure of it and how that like trickiness works? And I say trickiness-
Ben Johnson
Yeah
Aaron Francis
... in a good way 'cause I think it's-
Ben Johnson
No, yeah
Aaron Francis
... fascinating.
Ben Johnson
It, it's all hacks out there. Honestly, we're all, we're moving electrons around. I feel like-
Aaron Francis
Uh-huh
Ben Johnson
... everything's a hack, honestly. So, um, yeah, I mean the way that it works is there's b- basically two, um, journaling modes. So a journaling mode in a database, I don't know if you've covered this before, but like essentially it's how you safely like write changes to a database so that they all get written and they're durable and that if it needs to roll back, like everything can roll back. Um, so one is a journal mode where essentially you are copying out the, the previous version of the changes, like the rows, into a separate file called the journal file, and
then you'll make changes to the actual database, and then you write the changes. Like you, you basically delete the, the journal file after you're done. So at any point you can recover back, like if you need to roll back. So that's the journal mode, and that's like the old, old mode of SQLite. Um, it's, it has a lot of drawbacks. It's not very fast. You don't have like concurrency and all that. And kind of the better mode generally, I mean, there's a couple trade-offs, but by and large, like the WAL mode, which is write-ahead log, uh, that's kind of like the best mode to really run SQLite in.
You get a lot of concurrency. You can have a bunch of different readers at the same time, one writer, but they can all kind of intermix at the same time.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, so what, the way that the, the WAL mode works, uh, W-A-L, is that every transaction you make, you'll make changes to pages. So pages are kind of like blocks in your database. Um, and every time you make a change to a page, it'll kind of tack it onto the end of this file called the, the write-ahead log, and then it can reference those changes.
Aaron Francis
Can I, can I pause you right there?
Ben Johnson
Oh, yeah. Please do, yeah.
Aaron Francis
So the, uh, correct me if I'm wrong, but for the edification of the listener, the two trans- or the two, um, mode, the journal modes are rollback and write-ahead.
Ben Johnson
Yeah.
Aaron Francis
And write-ahead we call WAL 'cause it's write-ahead logging, W-A-L. So we've got rollback and write-ahead. Rollback is traditional-
Ben Johnson
Mm-hmm
Aaron Francis
... um, and still default because SQLite is super on about backwards compatibility.
Ben Johnson
Yeah.
Aaron Francis
They just love it so much.
Ben Johnson
They love it.
Aaron Francis
Which is great.
Ben Johnson
Yeah.
Aaron Francis
Love it. So we've got these two modes, rollback and WAL. WAL is the, um, WAL is the better one for better, higher concurrency. You can have a bunch of readers, um, still one writer, which is fine, but you can have a bunch of readers working. Um, rollback mode writes to the actual database file, and if you wanna roll back, it grabs the thing that it set aside and it puts it back in if you need to roll back.
Write-ahead, instead of writing to the actual database, um, file, it creates this new file that's like a dash WAL, and it writes there and leaves the database, uh, untouched until such a time where it takes the WAL, takes the, the second file and basically merges it back into the first file, and then we start all over again.
Is that fair so far?
Ben Johnson
Yeah. Yep, that's great.
Aaron Francis
Okay. Perfect.
Ben Johnson
Yeah, and then whenever it merges those changes back in, that's called checkpointing. And, uh-
Aaron Francis
Okay
Ben Johnson
... and the, the great thing about the WAL is that you essentially, you have every version of a page Until you checkpoint it back in. So you can have different, uh, readers kind of have a different snapshot of the database at every point in time when they started.
Aaron Francis
Mm.
Ben Johnson
So it has this nice, that nice property. It's called serializability. Um, so yeah, that's essentially how the WAL works. And the, the issue whenever you have like a, a kind of disaster recovery kind of streaming backup system like, uh, Lightstream, is that you essentially need to track the changes from the last time you, you sent an incremental backup.
Aaron Francis
Mm-hmm.
Ben Johnson
And like the checkpoint is where you kind of have a potential to lose that, where like the database could write some changes, and then it checkpoints and clears the whole write-ahead log, and then you never caught that last little transaction at the end before-
Aaron Francis
Mm-hmm
Ben Johnson
... it did that. Um, so-
Aaron Francis
And so at that point, your database has changed, but you don't necessarily know how-
Ben Johnson
Mm-hmm
Aaron Francis
... and so you can't send off that increment to, to some other place to store.
Ben Johnson
Yeah.
Aaron Francis
It's now become an amorphous blob again that is the database, and now your write-ahead log is empty. Is that right?
Ben Johnson
Yeah, exactly.
Aaron Francis
Okay.
Ben Johnson
And you don't really, you can't detect that necessarily.
Aaron Francis
Mm.
Ben Johnson
So you actually just... Even worse than like missing the transaction is like you actually corrupting your database, uh, potentially. So that's bad. You don't want that.
Aaron Francis
Mm.
Ben Johnson
Um, so-
Aaron Francis
That is bad.
Ben Johnson
Yeah. So the, the one nice trick, um, a little, this is the little hack, is that SQLite doesn't allow you to actually checkpoint if there's any open readers on the database, 'cause they might potentially have changes they're tracking within the WAL. Um, so what Lightstream does is essentially it keeps a, a long-running read open, um, on the transa- on the database, and then whenever it decides it's big enough to tran- like, to actually do the checkpointing, it'll kind of control that process of checkpointing and make sure it has all the data before the process happens, and then it just immediately clicks
back in and sh- grabs that, um, read again or read transaction again.
Aaron Francis
Mm-hmm.
Ben Johnson
So there's like-
Aaron Francis
Okay. So
Ben Johnson
Yeah. It's, it's very, yeah.
Aaron Francis
This is awesome.
Ben Johnson
Yeah.
Aaron Francis
I, I love this so much because this is a such a clever solution, uh, working from the outside in. Like, you didn't have to talk to anybody at SQLite.
Ben Johnson
No, yeah.
Aaron Francis
You didn't have to make any pull requests.
Ben Johnson
Yeah.
Aaron Francis
It's amazing. Um, tell me on a technical level how... So when you deci- who, first of all, who decides, um, in, in a Lightstream setup, who decides that a checkpoint is ready? Because I know in a traditional setup, SQLite decides, "Well, it's gotten big enough, checkpoint ready, let's write it." And a certain commit could take a little bit longer because it's doing the checkpointing as a part of that commit.
Ben Johnson
Mm.
Aaron Francis
In a Lightstream setup, who decides, all right, it's time to, it's time to commit, and then how do you... Are you literally plucking it out of the WAL file before you allow SQLite to commit, or how do you handle that, uh, that process there?
Ben Johnson
Sure, yeah. So what we ended up doing is, um, yeah, we essentially copied the, the same, um, settings as what SQLite defaults to.
Aaron Francis
Mm-hmm.
Ben Johnson
I think it's four megabytes, uh-
Aaron Francis
Mm
Ben Johnson
... for a WAL. Like, once it exceeds that, then it'll attempt to start, um, copying stuff back over. Uh, we essentially use the same settings and then kind of... We don't even, we don't implement the actual checkpointing process. We actually call-
Aaron Francis
Mm-hmm
Ben Johnson
... into the, the functions inside of SQLite to do the checkpointing. Um, so that's not implemen- implemented by us. They do document their whole WAL format.
Aaron Francis
Mm-hmm.
Ben Johnson
So it, it's pretty easy to read. It's basically the page data, and then it has some checksums, and like a, an incremental checksum and some salt and little-
Aaron Francis
Mm-hmm
Ben Johnson
... all those things as well. So-
Aaron Francis
Mm
Ben Johnson
... there's a lot of, like, little checks within there just to make sure that you're not, like, getting the wrong data or getting-
Aaron Francis
Mm
Ben Johnson
... uh, whatnot. So, um, yeah. So it essentially handles it on its own and just copies the, the settings.
Aaron Francis
Okay. And so when you reach that point, let's say it's four megabytes, when you reach that point, you have light, you, uh, being Lightstream, you have decided, um, all right, it's time to transfer this into the full on, the full on, um, .sqlite file. So then you presumably have some sort of internal state that says the last whatever checksum or the last page that you have sent off to S3
or S3 compatible, and so then you investigate the WAL file yourself, find where that is, send anything after that, and then let, uh, SQLite do the rest and put it back into the .sqlite file?
Ben Johnson
Uh, yeah, pretty much. And we actually have-
Aaron Francis
Huh
Ben Johnson
... one little difference is that we ac- have a, it's called, like, a shadow WAL. So essentially, we're copying stuff out to, like, a, a directory next to the database. Um, and that's, it'll store kind of the incremental things to send off, because you might not have connection to S3 or wherever you're sending to for some period of time. So it, it doesn't prevent you from checkpointing, um, without sending off.
Aaron Francis
Oh, that's interesting.
Ben Johnson
Yeah.
Aaron Francis
Okay, say that again. Say that again. Say that again.
Ben Johnson
Yeah, so-
Aaron Francis
So you have a shadow WAL-
Ben Johnson
Mm-hmm
Aaron Francis
... that when you let SQLite commit, in case you can't reach S3, you have put it aside such that when S3 is reachable again, that'll be sent off?
Ben Johnson
Yes. Yep.
Aaron Francis
Oh, that's clever.
Ben Johnson
And you can track stats of the stuff within, like, it has, like, Prometheus metrics you can attach, um, you know-
Aaron Francis
That's-
Ben Johnson
... Grafana or whatnot too
Aaron Francis
... super clever, because you wanna stay... Man, I'm just learning so much.
Ben Johnson
Yeah.
Aaron Francis
That's why I keep repeat, or I keep repeating it back to you, to make sure I have it. So you wanna stay, you need to be safe, 'cause you gotta stay out of the way of the database, and one place that could fall down is you're trying to send off changes and east one is down again. You can't reach it, and now everybody is trying to use this database that you are blocking because S3 is down.
And so to get around that, you've got a shadow WAL that you can just stash.
Ben Johnson
Yeah, exactly.
Aaron Francis
Huh. Did you, did you bake that in from the beginning, or did you have, did you-
Ben Johnson
Uh, yeah-
Aaron Francis
... kind of average
Ben Johnson
... it's pretty early on. I mean, part of it is that you kind of need to know the previous page that you read, um-
Aaron Francis
Mm
Ben Johnson
... just to make sure that it lines up, 'cause every page that's written essentially has-
Aaron Francis
Mm-hmm
Ben Johnson
... this rolling checksum that goes through the whole- Write a head log.
Aaron Francis
Mm-hmm.
Ben Johnson
And then the event that your, you know, Lightstream dies for whatever reason and comes back, it needs to be able to check to make sure that there's not new transactions written or there hasn't been a checkpoint.
Aaron Francis
Mm-hmm.
Ben Johnson
Uh, things like that. So it does a bunch of those checks, but it has to have the previous data in that shadow WAL to actually-
Aaron Francis
Yep
Ben Johnson
... check it against.
Aaron Francis
Okay. That makes a ton of sense. Okay. So then-
Ben Johnson
And then it just kind of worked out that it happened to be a shadow WAL and it, it's disconnected-
Aaron Francis
Yeah
Ben Johnson
... from S3.
Aaron Francis
That makes, that makes a lot of sense. So then you send-
Ben Johnson
'Cause you really don't want downtime, like, from your your-
Aaron Francis
No
Ben Johnson
... disaster recovery solution. That sucks.
Aaron Francis
No. You don't want... Then you are the disaster.
Ben Johnson
Exactly. Yeah.
Aaron Francis
And that's, that's the opposite of what we're looking for. Okay. So you send incremental, uh, backups off to S3 or S3 compatible, right?
Ben Johnson
Yeah.
Aaron Francis
Which would include, at this point, uh, Backblaze R2, Cloudflare something something.
Ben Johnson
Yeah. We also do GCS, uh, sorry, Google-
Aaron Francis
Okay
Ben Johnson
... Cloud Storage. We also do Azure. Um, I should know the other ones, but they're... Yeah.
Aaron Francis
Nah, that's all right.
Ben Johnson
Most, a lot of them are S3 compatible, so.
Aaron Francis
Okay. So then in S3, what would you find? Would you find a bunch of little files that are all, like, um, checkpoints, or what do you find in S3?
Ben Johnson
Sure, yeah. So it has essentially two subdirectories. You have one that is gonna be your snapshots.
Aaron Francis
Mm-hmm.
Ben Johnson
So you can configure Lightstream to snapshot every, uh, by default I think it's once a day, and then it'll, um... Next to that it'll have, like, a, a set of WAL files, and those WAL files-
Aaron Francis
Mm-hmm
Ben Johnson
... will essentially just keep incrementing up, and they can get replayed in order. Um-
Aaron Francis
Cool
Ben Johnson
... and then you basically can reproduce. It's nice 'cause you can actually reproduce the state of your database-
Aaron Francis
Mm-hmm
Ben Johnson
... at any point in time between the snapshot and now.
Aaron Francis
Mm-hmm.
Ben Johnson
So if you did do this, like, you know, delete table kind of business-
Aaron Francis
Mm-hmm
Ben Johnson
... and you need to get back to, like, five minutes ago, you can do that.
Aaron Francis
Man, that rules. Okay. Yep, that makes a ton of sense. Okay, and then what is the recovery story or, like, the restore story for Lightstream, and how far do you go to aid the developer to do that recovery?
Ben Johnson
Sure. It's just a restore command within Lightstream. So you say Lightstream space restore, and then you give it, um, yeah, the name of the database kind of or the replica where it's going up to.
Aaron Francis
Mm-hmm.
Ben Johnson
It'll pull it down, and then it'll essentially start with a snapshot and then just pull down a bunch of those little incremental changes and keep replaying those. And it actually uses SQLite to actually repro- r- replay them. Uh, that can actually take a little bit of time if you have, like, thousands of them.
Aaron Francis
Yeah.
Ben Johnson
So, um, it can be beneficial if you actually snapshot more often if you have a lot of changes, so maybe once an hour, uh, depending on your database size. But the nice thing about, like-
Aaron Francis
How do you-
Ben Johnson
Oh, go ahead.
Aaron Francis
No, no, no. Please.
Ben Johnson
Uh, the nice thing about, like, B-tree databases, um, which is what-
Aaron Francis
Mm-hmm
Ben Johnson
... SQLite is and VoltDB, is that, like, just by default they tend to have a bunch of space in them. Uh, you tend to, like-
Aaron Francis
Mm
Ben Johnson
... split trees a bunch-
Aaron Francis
Mm-hmm
Ben Johnson
... so you end up having... You never have, like, a, like, really tightly packed, um, database. Um, and that plus it's, like, all text data typically-
Aaron Francis
Mm-hmm
Ben Johnson
... is that you can actually just compress the, the crap out of it. So it's like, you know, you might have... Your database is, like, you know, 16% of the size of the actual-
Aaron Francis
Mm-hmm
Ben Johnson
... real thing. It's crazy. Uh, so it's not, it's not... We do, I think, uh, LZ4 compression, so we'll do that and send it up.
Aaron Francis
How do you, um, how do you make, uh, uh, how do you trick SQLite into replaying these, these incremental WALs? Do you just, like... I'm gonna guess and then you tell me why I'm wrong.
Ben Johnson
No. Go ahead.
Aaron Francis
Um, so you pull down a snapshot, which is, like, a, you know, .sqlite whatever, then you pull down a WAL file, and then open and close some sort of connection, and SQLite says, "Oh, there's a WAL. I'm gonna commit it."
Ben Johnson
Yeah.
Aaron Francis
Is that it?
Ben Johnson
There you go. There you go. Yeah. I mean, we'll pull down the, the WAL files in parallel behind the scenes.
Aaron Francis
Uh-huh. Yeah.
Ben Johnson
And then basically do a bunch of open and closes.
Aaron Francis
Control what shows up, what-
Ben Johnson
Yeah
Aaron Francis
... what's visible to SQLite with naming conventions and stuff, and then open and close.
Ben Johnson
Yeah. And we can actually improve the, the open time or, like, the, the restore time if we actually did it ourselves. It's not that complicated-
Aaron Francis
Uh-huh
Ben Johnson
... to replay the WAL, honestly. Uh, so I might do that in the future, but, um, yeah, it's not, it's not too bad.
Aaron Francis
But there's just... There's something so, um... I, if I were you, I would feel such great relief to know that you, that's, that's not your job.
Ben Johnson
Yeah.
Aaron Francis
Your job is just to, like, put the stuff where it goes and then let the, you know, the 25-year history of SQLite handle, you know, doing the right thing.
Ben Johnson
Yeah.
Aaron Francis
Which feels kinda like, yeah, I don't have to worry about that. That's a whole set of problems you don't have to develop for, test for, future-proof. That just feels, like, that feels kinda nice.
Ben Johnson
Yeah. I mean, there's definitely that benefit as well. Yeah. We got into a lot more of the, the nitty, greed- gritty details of, um, SQLite behavior when we did, like, LightFS next.
Aaron Francis
Mm-hmm.
Ben Johnson
And we can talk about that as well, but, um-
Aaron Francis
Mm-hmm
Ben Johnson
... so yeah, it's, that part's not too scary at this point.
Aaron Francis
Mm-hmm.
Ben Johnson
We actually had to do replays of WALs and things like that.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, but yeah, no, I, I agree with you. It's, it's nice. Just not, it's not my problem kind of thing. It's nice.
Aaron Francis
Yeah, it's not your problem. Ah, I love not having problems. Okay. So let's talk, um, unless there's anything else about Lightstream, I feel like the level of complexity, you were like, "That was too easy. Let's double up- ... and write something else." So unless you have anything else on Lightstream, I wanna talk about LightFS.
Ben Johnson
Sure, yeah. No. Sounds good.
Aaron Francis
Okay. So my, um, my understanding of LightFS is another it's like... This is so great.
Ben Johnson
Yeah.
Aaron Francis
I feel like I love your style. It's, it's, um- ... another approach of making SQLite do something without telling SQLite that it's doing anything. So-
Ben Johnson
Yeah
Aaron Francis
... so my, my take on LightFS is, um, SQLite has this layer that, like, integrates or, or talks to the operating system. Is it, like, uh, VFS? Is, is that what they, that the layer they call it?
Ben Johnson
So the, so you can h- do a VFS within, uh, SQLite, which is called a virtual-
Aaron Francis
Okay
Ben Johnson
... file system.
Aaron Francis
Uh-huh.
Ben Johnson
And it has its own API within SQLite. Um-
Aaron Francis
Mm-hmm
Ben Johnson
... but the problem with that is you actually have to Like SQLite has to know about your underlying-
Aaron Francis
Mm
Ben Johnson
... system.
Aaron Francis
Yeah.
Ben Johnson
Has to be loaded in manually and all that stuff.
Aaron Francis
Okay.
Ben Johnson
Um, and we really wanted to make it very invisible. Um, so we actually use FUSE, uh, which is like a file... Oh, God, I should know the name of-
Aaron Francis
Yeah.
Ben Johnson
... or what that stands for. It's a user-
Aaron Francis
Yeah
Ben Johnson
... level file system within Linux-
Aaron Francis
Okay
Ben Johnson
... basically.
Aaron Francis
Okay. And so I thought where this was going was instead of, um, you know, using the, the Windows or the Linux or the OSX, like VFS, it uses Lightstream or LiteFS. That's wrong. So tell me how, how LiteFS works because clearly I, I had- ... the wrong idea on this.
Ben Johnson
Sure, yeah. I mean, and this actually stemmed out of Lightstream. So Light, Lightstream, um, one of the versions... Like, one, two of the requests we got more than probably anything else was that people wanted to be able to have something to roll over to, like switch basically the primary node.
Aaron Francis
Mm-hmm.
Ben Johnson
Like have a failover when they do deployments-
Aaron Francis
Okay
Ben Johnson
... 'cause you can get down- downtime otherwise. Um, and there's things you can control with that or, like, get around with that. Uh, so people wanted to fix, you know, the downtime when you switch over, and they also-
Aaron Francis
Mm-hmm
Ben Johnson
... wanna read replicas.
Aaron Francis
Mm-hmm.
Ben Johnson
So you might have, like, your main server in Virginia, but you might, you know, it's 100 milliseconds to Europe or-
Aaron Francis
Mm-hmm
Ben Johnson
... 250 milliseconds over to Asia. So, like, you might wanna put read replicas over there and make them super fast for everyone in the world.
Aaron Francis
Mm-hmm.
Ben Johnson
And I originally tried to do that in Lightstream.
Aaron Francis
Mm-hmm.
Ben Johnson
And it, I kind of got something working. But there's just, like, since you don't have control over SQLite and, like, the actual-
Aaron Francis
Mm-hmm
Ben Johnson
... uh, the write calls and the reads and everything-
Aaron Francis
Mm-hmm
Ben Johnson
... you just have, you don't have quite enough control to really guarantee that you're not gonna get corruption or that you're not gonna send wrong files or whatnot. It's just, it's a really touchy thing, uh, when you get down to that level. Uh, so the idea was basically to kind of take over some control over that, so we made this essentially pass through, um, file system called LiteFS.
Aaron Francis
Okay. Mm-hmm.
Ben Johnson
And what it does is when SQLite does a write to, to the file system-
Aaron Francis
Mm-hmm
Ben Johnson
... it'll go through our file system, and so it can-
Aaron Francis
Mm-hmm
Ben Johnson
... detect it, and we basically pass-
Aaron Francis
Mm
Ben Johnson
... it off again to the underlying, the real file system. So we can track every single write call that goes through and-
Aaron Francis
Mm-hmm
Ben Johnson
... um, that gives us... Also, we can track our, the locks on the actual database too when they-
Aaron Francis
Right
Ben Johnson
... 'cause there's, like, a bunch of locks that they, they use.
Aaron Francis
Right.
Ben Johnson
So we can detect when a, a write starts, when it ends, and all kinds of things, just a lot, a lot of it's from the locks themselves. Uh, so we essentially can demarcate the start and end of all transactions, and then we can track all the writes that occur in between them, and then we can kind of read out those changes for each write-
Aaron Francis
Uh-huh
Ben Johnson
... um, and then stuff them into what we call an LTX, uh, LiteFS transaction file.
Aaron Francis
Okay.
Ben Johnson
And that's essentially like a little package of, like a change set for a transaction-
Aaron Francis
Mm-hmm
Ben Johnson
... uh, that we can ship off to other replicas. So they can replay that same transaction, and it's again just like page changes.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, so we can have essentially a primary, and that gets all the changes, and then it can ship them off to the other, uh, replicas.
Aaron Francis
So help me understand, and this is, this is my low-level systems knowledge, or rather my lack of-
Ben Johnson
Yeah
Aaron Francis
... um, low-level systems knowledge showing. How do you sneak in? I, I'll be honest, I don't know what a FUSE is. I know it's all caps-
Ben Johnson
Oh, yeah
Aaron Francis
... and, and I know that neither of us know- ... what it stands for. But how do you sneak in in between SQLite and the actual file system? What, what, what does that even mean?
Ben Johnson
Sure, yeah. So it's, so I did actually remember what it is. It's, it's file-
Aaron Francis
Okay
Ben Johnson
... system and user space. So you're essentially-
Aaron Francis
Okay
Ben Johnson
... writing an actual file system.
Aaron Francis
Okay.
Ben Johnson
Um, and it has calls for writes and, you know, make directory and all that stuff.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, and they're, they're actually kind of fun to build, honestly. I've, I built one- ... a long time ago where you get, like, you get, like-
Aaron Francis
Says the guy that builds databases for giggles.
Ben Johnson
Yeah.
Aaron Francis
So take that with a grain of salt, everyone.
Ben Johnson
Yeah. No, I made one, like, a long time ago where it was like I wanted to be able to see my GitHub, like look through GitHub, and, like, you can, like, basically look at GitHub as a directory tree. So you can, like, look at repos and users and, like-
Aaron Francis
Oh
Ben Johnson
... it's-
Aaron Francis
Sounds pretty cool, yeah.
Ben Johnson
Yeah, just a little throwaway kind of fun little project.
Aaron Francis
I agree. You got me. That's pretty cool.
Ben Johnson
Yeah. I think I was, like, mentoring some, some students one time on, like, some stuff, and we were like, "Ah, let's make a project," and that's just what we came up with, so.
Aaron Francis
Yep.
Ben Johnson
It was a random... Anyway.
Aaron Francis
Those, those... Yeah, those students are gonna be just fine if that was-
Ben Johnson
Those-
Aaron Francis
... their little, little project.
Ben Johnson
Poor-
Aaron Francis
They'll be okay
Ben Johnson
... poor students. Um, so we ended up, uh... Oh, yeah, so yeah. File system. So essentially, like, load it up as a file system, as you would-
Aaron Francis
Mm-hmm
Ben Johnson
... um, like another file system. I mean, there's a, there's a mount command within FUSE, so essentially, like, it's literally a file system.
Aaron Francis
Okay.
Ben Johnson
Um, and then you also give it the, a target for where you want it to write its data, which is on the-
Aaron Francis
Mm-hmm
Ben Johnson
... the normal file system that you're already using.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, so it kind of has its, its own data directory and whatnot behind the scenes on your file system.
Aaron Francis
Mm-hmm.
Ben Johnson
It's just it kind of makes a, a little shim in between the two, essentially.
Aaron Francis
And then for the user, uh, for the developer, how do they make SQLite aware of LiteFS?
Ben Johnson
Sure. So they just have to point it at the directory that comes up from that file system, and they can start making databases just in the way they normally write them. Like, you just open a connection, write your database. All the changes are happen invisibly-
Aaron Francis
Uh-huh
Ben Johnson
... and they get kind of shuttled off behind the scenes. So it looks exactly like a regular SQLite database-
Aaron Francis
Mm-hmm
Ben Johnson
... um, just on a different file system.
Aaron Francis
Man, that is super clever. Okay. So you have, uh, LiteFS is a custom file system that is basically like a, like a decorator or a proxy or something.
Ben Johnson
Mm-hmm.
Aaron Francis
And so you're listening, uh... You're not listening. They're ac- SQLite is actually writing to you.
Ben Johnson
Mm-hmm.
Aaron Francis
And then you're passing that through and setting it aside, and then when you reach a certain point, maybe the transaction closed or you've gathered a few transactions, I don't know. When you reach a certain point, you fire this, this custom packet off somewhere, and LiteFS is waiting on the other side to receive this, this unified tran- like, this file format that you both speak.
Ben Johnson
Mm-hmm.
Aaron Francis
And then you turn that- Back into SQLite on the other side and pass it through to the underlying file system over there?
Ben Johnson
Yeah, essentially it's, I mean, yeah, more or less. So we, we package up every transaction separately.
Aaron Francis
Mm-hmm.
Ben Johnson
And then it stores-
Aaron Francis
Okay
Ben Johnson
... on the primary node for some period of time, and then the other nodes actually connect up to the primary, and they'll just continuously stream down anything that comes in. So-
Aaron Francis
Oh, I see
Ben Johnson
... from the time you actually write the transaction, you know, it takes less than a millisecond to actually replicate-
Aaron Francis
Mm-hmm
Ben Johnson
... plus any latency, like physical latency.
Aaron Francis
Ph- yeah.
Ben Johnson
Um-
Aaron Francis
Plus the speed of light. Okay.
Ben Johnson
Yeah, that dang speed of light, yeah.
Aaron Francis
I know. We'll get it one day. So you have these other, you have these replicas, um, these other, these other servers have LightFS on it, and the other servers are aware of where the primary is, or rather I guess what the primary is.
Ben Johnson
Mm-hmm.
Aaron Francis
And it has some process there that is constantly polling or there's some- something fancier to watch for new transactions it needs to pull. Is that right?
Ben Johnson
Yeah, it's just a constant connection that's-
Aaron Francis
Okay.
Ben Johnson
Yep.
Aaron Francis
Okay.
Ben Johnson
Stream, yeah, streams them down, and then, um, yeah, it has a bunch of checksumming and all that stuff in there to make sure it's, uh, everything ends up in the appropriate state. We actually do, like, a, a rolling checksum, which I don't, I'm sure other databases have done this.
Aaron Francis
Mm-hmm.
Ben Johnson
I don't think we're novel by any means, but, like, it's interesting that we actually, we'll take the pages that are changed, and we'll essentially do an XOR checksum to remove the old version of the page from the checksum-
Aaron Francis
Mm-hmm
Ben Johnson
... and then put in the new version of the page as a checksum. So it can actually compute, like, a, a rolling, like an actual checksum for every single transaction in the database.
Aaron Francis
Mm-hmm.
Ben Johnson
Uh, so we actually can really clearly see if we have any corruption anywhere in the process, um, which has been nice. And we can actually, yeah, there's some-
Aaron Francis
Yeah.
Ben Johnson
Oh, go ahead. Yeah.
Aaron Francis
Uh, no, I was gonna say that seems like rule number one is-
Ben Johnson
Yeah
Aaron Francis
... you've gotta make sure that everything that's supposed to get there gets there, and nothing that's not supposed to be there gets there. 'Cause if you end up with, you know, a corrupted replica down in Australia, you're hosed. Like-
Ben Johnson
Yeah
Aaron Francis
... that's, that's a, that's the pur- that was what you were trying to solve here.
Ben Johnson
Yeah. And people, some people also wanted the failover piece, where, like-
Aaron Francis
Mm-hmm
Ben Johnson
... you could have multiple primary, or not primaries. You can have multiple candidates essentially, so you might have two that are in, um-
Aaron Francis
Hmm
Ben Johnson
... one region, and they can just flip-flop when you do a deployment. Um, we actually use Consul, like HashiCorp's Consul-
Aaron Francis
Mm-hmm
Ben Johnson
... uh, is one of the, the things we use for that. So it's optional. You can either have, like, a fixed primary, which one-
Aaron Francis
Mm-hmm
Ben Johnson
... machine is always a primary, or we can actually have it where it does a le- leader election, and then it can flip-flop over. Um-
Aaron Francis
Hmm
Ben Johnson
... but so we have some looser guarantees when you use something like Consul about who can actually, like, w- when a transaction's actually persisted and these actually get to the other candidate.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, but you can have a, a scenario where you get a write that's actually written down and not replicated to the, uh, the candidate yet. So when it does flip, like, you could lose that, you know, little sliver of time.
Aaron Francis
Mm-hmm.
Ben Johnson
Uh, we need to be able to check to make sure that the checksums, you know, if they do change between different nodes, um, that we can re-snapshot and send those down to the replicas.
Aaron Francis
Hmm. Okay. So talk to me about, um, how do you do... So you've got, uh, somebody, you got a primary in Dallas and a replica in Australia. Somebody in Australia does a write.
Ben Johnson
Mm-hmm.
Aaron Francis
How do you do write forwarding, um, inside of, of fly.io? 'Cause I understand this is, like, kinda y'all's, y'all's bread and butters. Put, put stuff on the edge, and we'll figure out the rest. And then is it possible outside of fly.io?
Ben Johnson
Sure, yeah. So, uh, like SQL, or sorry, LightFS isn't specific to, to Fly. We, we certainly-
Aaron Francis
Okay
Ben Johnson
... want people to use it on there. Um, but it's open source. It's all Apache 2, uh, so you can go do whatever you'd like with it. Um, and it'll work on any system really. Uh, there is some stuff we do in there. Um, so one, one issue we ran into after we got, you know, stuff working, was that, uh, we originally had, like, w- probably the best way to do it is to have the application send the write, like send all writes to the primary, and then you can read all your reads from the replica.
Um, but again, that speed of light thing where you might send a write-
Aaron Francis
Mm-hmm
Ben Johnson
... to the primary, but then you read from the replica before the write actually gets down to the replica. Uh, so you can get this out of order kind of appearance in the application. Um, and we spent quite a while trying to figure out the best way to, to manage that. And essentially, like, you know, we don't, we don't want everyone to have to, like, check for, like, a, a transaction ID on every single read they do, and do a bunch of, you know, playing around to make sure they have, like, a consistent view of the data.
Uh, so we actually have a, an optional, like, HTTP proxy you can run in front of your, um, application, so it'll actually check for the, um, essentially the, the write transaction when it went in and make sure that your reads are caught up before the next read transaction comes in, and does that kind of invisibly to the application itself.
Aaron Francis
Right.
Ben Johnson
So we kinda, like, sandwich, like your application's here, and there's like a proxy-
Aaron Francis
Mm-hmm
Ben Johnson
... here and, like, a file system-
Aaron Francis
Mm-hmm
Ben Johnson
... here, like s- you know, lovingly hugging your application
Aaron Francis
Yeah
Ben Johnson
... um, to give it consistency-
Aaron Francis
I like that
Ben Johnson
... and all that. So, uh, yeah, so right now it's, it's mainly on the application side we typically recommend. We did some-
Aaron Francis
Mm-hmm
Ben Johnson
... work with write forwarding within SQLite, um, but it was just, it was more of a pain than I would say it's worth typically.
Aaron Francis
Yeah. That sounds, that sounds pretty complicated. Um, so what's the, what's the story on, like, if somebody, somebody did wanna spin up LightFS, what is the, like, uh... How do you, how do you get it? How easy is it? It sounds-
Ben Johnson
Okay
Aaron Francis
... sounds like you've got it pretty nailed, but tell me. What would-
Ben Johnson
Sure, yeah
Aaron Francis
... what would one do?
Ben Johnson
Yeah. We have some, some docs on, on Fly, uh, you can check out as well. Uh, I think it's fly.io/docs/lightfs.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, you can go on there and essentially you, we have it all bundled up as a, as a Docker container or-
Aaron Francis
Mm-hmm
Ben Johnson
... Docker image. Uh, the funny thing is we actually don't use Docker as, like, the thing, 'cause you actually need to pull the binary in to your-
Aaron Francis
Mm-hmm
Ben Johnson
... your own Docker image. Um, so we just actually copy it out, which is... It's, like, a really convenient way to use Docker to, like, copy binaries if you're using Go, 'cause it's all static binaries. Um, and yeah, so essentially you can copy it down to your, your development or your, uh, your Docker image, and you run it, and then it kind of runs your application as a, a supervisor.
Aaron Francis
Mm.
Ben Johnson
Um, and then beyond that, there's... If you have an application where your, your writes all go through, like, POST and PATCH and all those kind of standard HTTP verbs-
Aaron Francis
Mm
Ben Johnson
... and then your reads all go through GETs, then it kind of just works more or less.
Aaron Francis
That's awesome.
Ben Johnson
Uh, you simply just point your, your application. You can actually do it with, like, uh, WordPress. I think we've done that before.
Aaron Francis
That is so awesome.
Ben Johnson
We just spin up WordPress, and, like, point it at LightFS, and it just magically does the right things, which is kind of cool.
Aaron Francis
I bet that felt pretty cool.
Ben Johnson
Yeah. Yeah, that was, that was a good one.
Aaron Francis
If you, if you can do it, if you can just make it work with WordPress, that's how you know- ... you've got it, you've got it sorted.
Ben Johnson
Oh, yeah.
Aaron Francis
That's pretty amazing. So what do you see for, um, what do you see for the, like, uh, philosophical demarcation between Lightstream and LightFS, and where do you wanna take both of them moving forward? 'Cause is this what-
Ben Johnson
Mm
Aaron Francis
... you do at Fly? Is this your full-time... You just, you just write SQLite stuff and talk about SQLite and build Lightstream and LightFS. Is that all you do?
Ben Johnson
Uh, no, no, it's not all the, it's not the only thing I do. I do that.
Aaron Francis
Oh, okay.
Ben Johnson
But I also do, we do a, a bunch of, like, back-end work, reliability stuff. We do a lot of, um-
Aaron Francis
You, you do that?
Ben Johnson
Mm-hmm, yeah.
Aaron Francis
Oh, okay.
Ben Johnson
So just kind of write a couple tests.
Aaron Francis
I thought you got to just, just play in the lab all day.
Ben Johnson
Sometimes, yeah. Sometimes I do.
Aaron Francis
Yeah.
Ben Johnson
Um, yeah, I mean... Sorry, what was the question again?
Aaron Francis
The philosophical demarcation-
Ben Johnson
Oh, yeah, yeah
Aaron Francis
... between the two things, and then what your vision for the future of them is.
Ben Johnson
Sure. So Lightstream was... I kind of realized, like, adding all the replication stuff and all that just made a lot of pieces a lot more complicated or a lot more-
Aaron Francis
Mm
Ben Johnson
... complex. And essentially, Lightstream is kind of a disaster recovery only solution. Like, that's all-
Aaron Francis
Okay
Ben Johnson
... it does. Uh, so if you have a single node and you wanna stream up, do a streaming backup somewhere to S3-
Aaron Francis
Mm-hmm
Ben Johnson
... it's great for that. Like, you can do that-
Aaron Francis
Yeah
Ben Johnson
... all day long. Uh, and then Lightstream's never gonna be more than that. Um-
Aaron Francis
Great
Ben Johnson
... that's kind of its, its goal. And then LightFS is kind of the distributed systems, like you need replicas, or you want replicas, and you need, you know, low latency and all that stuff-
Aaron Francis
Mm
Ben Johnson
... around the world. Uh, or you want failovers. All kinds of stuff like that. It's, has a lot more complexity. We also have a thing called LightFS Cloud, where you can stream your backups up to, to Fly, and we'll save them, give you, like, point in time, uh, recovery as well.
Aaron Francis
Cool. So, um, would it be reasonable to say that you could use LightFS to get embedded replicas everywhere, and also use Lightstream to stash all that away on S3?
Ben Johnson
Uh, you can. It gets a little more complicated, um, but it is possible. You can run it. 'Cause you might have multiple primaries. That's kind of where the issue comes in.
Aaron Francis
Oh, I see.
Ben Johnson
And you'd essentially have to replicate each separate primary.
Aaron Francis
Oh, okay.
Ben Johnson
Um, so it's not as much fun doing both.
Aaron Francis
Yeah.
Ben Johnson
But, uh, but LightFS Cloud is kind of the disaster recovery side of the-
Aaron Francis
That. Okay
Ben Johnson
... LightFS piece.
Aaron Francis
Okay. Okay. That makes sense. And what do you see, um, beyond or maybe inclusive of building out LightFS Cloud? What do you see for the future of LightFS?
Ben Johnson
Sure. I mean, I think we might... I mean, LightFS Cloud is a paid service. Five bucks a month, you can get backups up there. Um, and I think, you know, we have some work we wanna do around moving some of that stuff into, like, a simpler version into LightFS itself.
Aaron Francis
Mm.
Ben Johnson
So you can do streaming backups to S3. Um, it gets a little more complicated when you don't have, like, a single service that can kind of manage, um-
Aaron Francis
Mm-hmm
Ben Johnson
... like, leadership and things like that. Uh, so there's some of the little hairy problems to get in there. Um, but I would say as far as LightFS, I mean, a lot of it is, you know, I think improving performance is always a good thing. Um, optimizing and just squashing bugs, but-
Aaron Francis
Mm-hmm
Ben Johnson
... um, you know, I don't, I don't have, like... I wouldn't say I have, like, grand features. I mean, we have some things that people have requested, like having a, an HTTP query API, so you can actually query LightFS over HTTP, which I know Turso-
Aaron Francis
That's interesting
Ben Johnson
... actually, we, I think we talked to Turso actually to see what their format was for that to try to use the same one.
Aaron Francis
Mm-hmm.
Ben Johnson
So it's, um... Yeah. There's, there's been a handful of requests like that.
Aaron Francis
Yeah. That's, that's super interesting.
Ben Johnson
Yeah.
Aaron Francis
Um-
Ben Johnson
But I'd like to keep it mostly simple, though. I mean, I, I think a lot of database companies just tack on features all the time. I used to be an Oracle DBA, like, 20 years ago.
Aaron Francis
Oh, yeah.
Ben Johnson
And, like-
Aaron Francis
You come by it-
Ben Johnson
... the number of-
Aaron Francis
... honestly. I see.
Ben Johnson
Yeah.
Aaron Francis
Okay.
Ben Johnson
The number of books that you have to, like, read just to, like-
Aaron Francis
Mm-hmm
Ben Johnson
... understand the basics of Oracle is crazy.
Aaron Francis
These are just, these are just my SQL right here.
Ben Johnson
No. Yeah.
Aaron Francis
I mean, that's, you know, they just keep going. You gotta know a lot to-
Ben Johnson
Yeah
Aaron Francis
... run these things. Um, okay. I like that. It feels to me like, um, this is, uh, like Lightstream and LightFS are, um, spiritual cousins of SQLite in that way, that it's, like, small, fast, reliable, and kind of done. Like, there's, you know, SQLite will continue to add things as we invent-
Ben Johnson
Yeah
Aaron Francis
... you know, CTEs and window functions and all that stuff. They, they continue to push forward. But in terms of, like, hey, the, you know, LightFS is good at what it does. We'll make it faster, we'll make it more reliable, but we're not gonna just continue to bolt nonsense on there. It feels like, ah, it has a home with SQLite. Y'all are, y'all are-
Ben Johnson
Yeah
Aaron Francis
... twins.
Ben Johnson
Yeah. I really love projects that have a scope, and like-
Aaron Francis
Mm-hmm
Ben Johnson
... like, Bolt was kind of like that. At one point I just, I marked it as 1.0, and I was like, "This is done." And I mean, obviously, you know, bug thing, bugs can come up-
Aaron Francis
Sure
Ben Johnson
... and whatnot. Um, but essentially, like, I wasn't adding any more features. Like, it's a key value store. Like, you get keys and values.
Aaron Francis
Mm-hmm.
Ben Johnson
Like, there's not a lot more than that.
Aaron Francis
Yeah. It's pretty, pretty straightforward.
Ben Johnson
Yeah.
Aaron Francis
Yeah.
Ben Johnson
Um, so yeah, that's kind of where that... I, I like projects that are like that. I feel like-
Aaron Francis
Mm-hmm
Ben Johnson
... there's too many projects that just go way too deep and, like-
Aaron Francis
Mm-hmm
Ben Johnson
... add too many things, and... I feel like whenever-
Aaron Francis
Well-
Ben Johnson
... people talk about their favorite projects, it's never like, "Oh, I love this grandiose, complex thing." They're like, "Oh, I like rsync," or like, what?
Aaron Francis
Uh-huh.
Ben Johnson
Like, some, like, simple tool, does one job, it does it great.
Aaron Francis
Yeah.
Ben Johnson
So.
Aaron Francis
The same with, like, their favorite little Mac apps or whatever. It's like this random little thing you've never heard- ... that solves this one problem perfectly, and everybody's in love with it.
Ben Johnson
Oh, yeah. Yeah.
Aaron Francis
You know.
Ben Johnson
Monodraw. Have you ever used Monodraw?
Aaron Francis
No. What is that?
Ben Johnson
It's like a, uh, an ASCII art editor. Um, so you can draw-
Aaron Francis
That's cool
Ben Johnson
... diagrams in ASCII art. It's like, I mean, it's a good product. And-
Aaron Francis
Mm-hmm
Ben Johnson
... honestly, but they're not, like, adding crazy features. There's no, like, sharing to Twitter, I don't think, or like, you know, whatever-
Aaron Francis
Mm-hmm
Ben Johnson
... like every product seems to add.
Aaron Francis
Mm-hmm.
Ben Johnson
It's great though.
Aaron Francis
There's no AI in there?
Ben Johnson
Not, not yet.
Aaron Francis
Not yet. Yeah.
Ben Johnson
Yeah. No, God forbid.
Aaron Francis
Knock on wood. Yeah. Um, okay, I kind of want to finish by talking about, uh, this, like, SQLite renaissance, and like what is your... Uh, which I think you have helped drive with these tools. So what is your perspective on why now? You know, it's been around since the year 2000.
Um, but-
Ben Johnson
Hmm
Aaron Francis
... why now? What, what, what is driving it, and what, where do you think, like, its best and highest use case is?
Ben Johnson
Sure, yeah. Um, I think that, I think the renaissance is driven by a couple things. Um, I would say complexity is a big thing.
Aaron Francis
Mm-hmm.
Ben Johnson
Where it just seems like there's so many dependencies you need to add to a project just to do a Hello World at this point.
Aaron Francis
Mm-hmm.
Ben Johnson
And it's just, it's a little absurd for certain things. I mean, not for every- I mean, everything has its place, obviously.
Aaron Francis
Sure.
Ben Johnson
There are tools that are written for a reason, but you don't need to do some Google scale project when you just need it to do it.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, so I think complexity is a big piece. Um, just having one file.
Aaron Francis
And by that you mean, like, the, uh, the rage against current complexity, and you feel like this is part of swinging it back?
Ben Johnson
Yeah. Yeah, for sure.
Aaron Francis
Okay.
Ben Johnson
Uh, especially for certain projects where you don't need all that stuff. Like-
Aaron Francis
Mm-hmm
Ben Johnson
... when you have SQLite, you don't really need a cache, like Redis or something, or Memcache. Like, everything's right there, right next to you-
Aaron Francis
Mm-hmm
Ben Johnson
... in memory half the time.
Aaron Francis
Mm-hmm.
Ben Johnson
And like, um, adding a cache would be ridiculous most of the time. So I think that there's, um, a lot of pushback around that. I mean, also other tools like, you know, people use Elasticsearch, but you may not need that based on the full text st- search that's built-
Aaron Francis
Mm-hmm
Ben Johnson
... into SQLite. Or like you have JSON support within SQLite.
Aaron Francis
Mm-hmm.
Ben Johnson
And like, there's all kinds of little great tools within there that do a lot of the job. It's kind of like-
Aaron Francis
Mm-hmm
Ben Johnson
... I write in Go mostly, and like the Go standard library has, like, 90% of what I need for, like, most applications, surprisingly.
Aaron Francis
I, I've never used Go, but that is the thing that I keep seeing on Twitter. It's like, "Oh yeah, Go, Go has that. Oh yeah-
Ben Johnson
Yeah
Aaron Francis
... Go has that."
Ben Johnson
Yeah.
Aaron Francis
It's like, that seems cool.
Ben Johnson
It's, yeah, that's great. It's, yeah. So, um, yeah, I think there's a lot, I think there's a lot you can do with just a basic, uh, SQLite app, which is great.
Aaron Francis
Mm-hmm.
Ben Johnson
And I think the other thing, too, is just the, the speed of our machines is just-
Aaron Francis
Mm
Ben Johnson
... wild at this point, where, like, you can really... I mean, you can serve, I mean, again, I write Go, but, like, Go and SQLite, I can serve hundreds or thousands of requests per second with a, a fairly minimal setup-
Aaron Francis
Mm-hmm
Ben Johnson
... which is wild. Um, and you know, most people are getting maybe less than one request per second on their app. Like, you don't need some crazy deployment, um-
Aaron Francis
Yeah
Ben Johnson
... or at least not to start.
Aaron Francis
We are.
Ben Johnson
You know, you can always... What's that?
Aaron Francis
We are getting less than, yeah. It's like-
Ben Johnson
Yeah
Aaron Francis
... we get thousands of requests per month, and you're like-
Ben Johnson
Yeah
Aaron Francis
... "Oh, okay, you'll be just fine."
Ben Johnson
Yeah. Even per day, I mean, there's like eight- ... 86,000 seconds per day. I mean, like-
Aaron Francis
Yeah.
Ben Johnson
Um, yeah. So I think that there's, there's a place, I think, for SQLite, um, for, I would say the vast majority of a- applications. Um, and once you start to scale, there's reasons to scale, there's reasons to break things apart.
Aaron Francis
Mm-hmm.
Ben Johnson
Especially once you get to, like, a bigger organization. But a lot of times you're writing, you know, either, like, an internal app for somebody, or you're-
Aaron Francis
Mm
Ben Johnson
... starting a startup or those things, and those don't need to be crazy, I don't think.
Aaron Francis
Yeah.
Ben Johnson
I'm also a big believer that, like, whenever... I mean, I think it's been said where, like, every time you scale up, uh, like, an order of magnitude, you have to rewrite your application. Maybe that's not, like-
Aaron Francis
Hmm
Ben Johnson
... quite the exact, um-
Aaron Francis
I, I like it though. We'll go with it. Yeah.
Ben Johnson
Yeah. It's not the exact-
Aaron Francis
That's good to me. Yeah
Ben Johnson
... um, idea. Maybe every, you know, two orders of magnitude you gotta restart. But, um, yeah, I think it's, you eventually have to rewrite anyway, I would say, to some degree, and that may be that you move to a different database down the road-
Aaron Francis
Mm-hmm
Ben Johnson
... if you need to. But you don't need to plan for that at the moment.
Aaron Francis
Yeah. And I think one of the, one of the selling points of SQLite is that it's, you know, it's very powerful, but it's relatively constrained, and if you need to move onto Postgres or MySQL, you're gonna have a pretty easy time doing that. Like, you'll have to set up a bunch of stuff, but your actual queries and stuff most likely are gonna work, especially if you move towards Postgres.
I feel like they took a lot of inspiration from Postgres versus MySQL. Whereas going from Postgres to SQLite is gonna be a lot-
Ben Johnson
Yeah, that's a-
Aaron Francis
... harder.
Ben Johnson
Yeah.
Aaron Francis
That, you don't want it to go that way.
Ben Johnson
Yeah.
Aaron Francis
So it does seem like the graduation story, should you need to get there, is, is pretty good. It's pretty straightforward.
Ben Johnson
Yeah, no. Yeah, I think 100%. Uh, and there's a lot of cool stuff in Postgres. By all means, like, I don't mean to-
Aaron Francis
Mm-hmm
Ben Johnson
... knock any other database. You can use Mongo-
Aaron Francis
Me either, yeah
Ben Johnson
... if you want to. Like-
Aaron Francis
Mm
Ben Johnson
... there's a place for everything. Um, but yeah. Uh, yeah, the graduation stories. The, what's, what's the opposite of the, on graduation stories? Yeah.
Aaron Francis
Yeah.
Ben Johnson
It's, it's gonna be rough probably.
Aaron Francis
It's demotion-
Ben Johnson
Yeah
Aaron Francis
... or, yeah, getting held back, something like that.
Ben Johnson
Yeah. There's cool stuff like lateral joins in, um, Postgres. You know, that's cool.
Aaron Francis
Mm-hmm.
Ben Johnson
But you don't have that in SQLite.
Aaron Francis
Mm-hmm.
Ben Johnson
Although I would add, like, a lot of things you don't actually need when you actually have a database right next to you in memory.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, like, I, I feel like a lot of, like, complex, big, huge queries you could break up into small queries if you don't have any, you know, qu- per query overhead, like latency.
Aaron Francis
Right. If there's no 25-millisecond penalty to get, even get to the database, you're not having to do everything in one shot.
Ben Johnson
Yeah.
Aaron Francis
Yeah.
Ben Johnson
Yeah. You can do, like, hundreds of queries in a, a page, and that's not a big deal in S- in SQLite, which is nice.
Aaron Francis
I think, I think the SQLite docs show how many queries are run on a single-
Ben Johnson
Yeah.
Aaron Francis
... page. And there's-
Ben Johnson
It's like 200 queries or something
Aaron Francis
... it's like, yes. It's like 220 queries.
Ben Johnson
Yeah.
Aaron Francis
And then it says, you know, page generated in point, you know, 0.001 seconds, and you're like-
Ben Johnson
Yeah
Aaron Francis
... "Ah, okay." "That's kind of cool. I get it. I get it." So I like, I like that. Um, okay, so is there anything else you wanna cover about SQLite? This, I'll tell you what, this has been... I've learned so much, and this has been such a blast, and I'm very grateful for your time to, to educate me.
So is there anything else you wanna cover about SQLite, LiteFS, LiteStream, or Fly.io?
Ben Johnson
Uh, no, I think it was great. I mean, I think that there's still a lot of potential out there, like of things people can build on SQLite and tooling.
Aaron Francis
Mm-hmm.
Ben Johnson
And, you know, there's always, um... Actually, one, one thing I really wanna, like, make, and I kinda like half made it, um-
Aaron Francis
Here we go
Ben Johnson
... I just didn't actually, like-
Aaron Francis
This is what I'm talking about. Give it to me
Ben Johnson
... uh, so, like, I did, like, a proof of concept of this, and it works.
Aaron Francis
Okay.
Ben Johnson
I just didn't actually build it out, and it kind of needs to be written in something more low level, like Rust or Zig or C or something like that.
Aaron Francis
Mm-hmm.
Ben Johnson
Um, is that I wanted to make basically a, like a, a driver for SQLite that will run... How do I explain this? So, like, it connects over SSH-
Aaron Francis
Okay
Ben Johnson
... and then communicates with the SQLite 3 binary on the other side-
Aaron Francis
Mm-hmm
Ben Johnson
... to perform queries. So you actually get... It actually works, like, as a, um this is such a crazy idea. It's essentially-
Aaron Francis
Yeah
Ben Johnson
... like a, a remote connection for SQLite.
Aaron Francis
This is client server SQLite.
Ben Johnson
It's cli- Yeah, 100% client server SQL. So I actually called it, I think it was, like, Sheqlite. It was like a mix of like SSH and SQLite. And, um, but the idea is not-
Aaron Francis
Oh.
Ben Johnson
I mean, you could use this in something, you know, production. Like, if you have, like... A lot of times if you have, like, workers, they might be in separate nodes.
Aaron Francis
Mm-hmm. Yeah, totally.
Ben Johnson
And might, might need to connect up-
Aaron Francis
Mm-hmm
Ben Johnson
... to the database. But it was mainly for, like... I find the biggest hurdle people have is for, like, GUIs. Like, they need to ha- Like, they wanna have a GUI for SQLite, and it's hard-
Aaron Francis
Mm-hmm
Ben Johnson
... to do that when you have a remote SQLite database.
Aaron Francis
It is. Yeah, that is definitely hard. Um-
Ben Johnson
Yeah
Aaron Francis
... this is insane. And you should absolutely do it.
Ben Johnson
Okay.
Aaron Francis
This is a great idea.
Ben Johnson
Yeah. Oh, I think-
Aaron Francis
So-
Ben Johnson
There's potential
Aaron Francis
... go, go tell Kurt, go tell whoever you need to tell that some random person on the internet said you need to do this.
Ben Johnson
You need to do that. Okay.
Aaron Francis
And you should, you should devote all your time-
Ben Johnson
Okay
Aaron Francis
... to this now-
Ben Johnson
Dedicate now.
Aaron Francis
... 'cause that sounds, that sounds amazing. This is, like, this is that kind of, like, um, this is that kind of crazy where you're like, "Yeah, this is-" "... this is crazy. I'm gonna do it." I like it. That sounds-
Ben Johnson
Yeah
Aaron Francis
... that sounds awesome. You did a-
Ben Johnson
Yeah
Aaron Francis
... proof of concept. How far did you get?
Ben Johnson
Uh, I got it working. I mean, where it actually... So it does some stuff. Um, I, I actually made a request to, to SQLite to see if they'd make a binary format.
Aaron Francis
Uh-huh.
Ben Johnson
'Cause the biggest issue is actually connecting, and then you have to, like, um... You know how it'll say, like, SQLite and then do, like, a, a greater than sign-
Aaron Francis
Mm-hmm
Ben Johnson
... for the, uh, the prompt?
Aaron Francis
Mm-hmm.
Ben Johnson
Like, essentially for results and, like, for parsing out errors and stuff like that.
Aaron Francis
Mm-hmm.
Ben Johnson
I need to, like, remove all the prompting it does, and it has some, like, weird prompting rules. So it's actually not that-
Aaron Francis
Interesting
Ben Johnson
... not that hard.
Aaron Francis
Yeah.
Ben Johnson
It was really more just a bunch of weird-
Aaron Francis
It got pretty far.
Ben Johnson
... little things. Uh, yeah. But it actually does work. It'll actually communicate over and run a query and get the results back and yeah. So anyway.
Aaron Francis
This- Every, every now and then, there's a guy like this in the Laravel ecosystem, of which I'm a part, where it's like, you're a mad scientist.
Ben Johnson
It's just-
Aaron Francis
Like, the stuff, the stuff that you do, you know, this guy, the stuff that he does with PHP, it's like nobody should ever do that, but this-
Ben Johnson
No
Aaron Francis
... is awesome.
Ben Johnson
Yeah.
Aaron Francis
And I feel like you're the, you're the SQLite mad scientist. This is crazy, and I love it.
Ben Johnson
I mean, there's some cool people doing cool work as well, like, uh, Alex Garcia does, um... He's done a bunch of extensions. I think he did, like, a vector with database within-
Aaron Francis
Okay
Ben Johnson
... uh, SQLite. Um, Philip O'Toole did RQLite, which is basically-
Aaron Francis
I saw that one, yeah
Ben Johnson
... SQLite over... Yeah. Um, we used to work together, actually. It's funny, 'cause-
Aaron Francis
Oh, cool
Ben Johnson
... we didn't work on SQLite at all at the same time, but we separately just did our own paths.
Aaron Francis
That's-
Ben Johnson
And we're like, "Oh, hey, we're both doing this stuff." Um, but yeah, he does it as, like, a distributed system-
Aaron Francis
Mm-hmm
Ben Johnson
... over Raft, and, um, which is a consensus protocol.
Aaron Francis
Mm-hmm.
Ben Johnson
So yeah, there's a lot of cool stuff out there. And then I know that, like, Turso-
Aaron Francis
And somebody just wrote, uh... Yeah, there's, of course, Turso, and then somebody just wrote, uh, a, like... I don't know if it's Wire compatible, but somebody just wrote a reda- a Redis clone in SQLite.
Ben Johnson
Oh, I did see that. That's, uh-
Aaron Francis
Yeah
Ben Johnson
... Red- Redca or something? No, Re-
Aaron Francis
Redca, I think.
Ben Johnson
Yeah.
Aaron Francis
Yeah.
Ben Johnson
Yeah, I saw that.
Aaron Francis
I think, I think that's right. Um-
Ben Johnson
Yeah
Aaron Francis
... and-
Ben Johnson
I think Cloudflare does D1, and it's-
Aaron Francis
Uh-huh
Ben Johnson
... like, it's, it's nice. I like communities that are still pretty small, and I feel like-
Aaron Francis
Mm-hmm
Ben Johnson
... it's still kind of early days, where, like, everyone's not super competitive. So, like-
Aaron Francis
Mm-hmm
Ben Johnson
... some people will borrow ideas from other people, and, like-
Aaron Francis
Mm-hmm
Ben Johnson
... I borrowed some stuff from Turso for their HTTP API, and-
Aaron Francis
Mm-hmm
Ben Johnson
... um, yeah, I think their local replicas use some of the stuff from LiteFS, and so that's fun.
Aaron Francis
Yeah, it's fun. I, I, I do like the proliferation of, like, good options in this space. And funny, funny enough, like, one of the, I feel like one of the drawbacks that everyone is always talking about, at least on Hacker News, is like, "SQLite doesn't have types." And you're like, "Well-"
Ben Johnson
Yeah.
Aaron Francis
"... it's a long story." But-
Ben Johnson
Yeah
Aaron Francis
... if you're using it for a key value store, that suddenly is a great benefit.
Ben Johnson
Yeah.
Aaron Francis
'Cause you can put anything as the-
Ben Johnson
Anything you want.
Aaron Francis
... key for the value.
Ben Johnson
Yeah.
Aaron Francis
And so it's kind of fun to see people, like, do a, you know, a Redis reimplementation because it's like, well, you can just throw anything in there, and we'll hang on to it for you.
Ben Johnson
Yeah. Yeah. I used to work a lot in, like, key value stores, and really it's like-
Aaron Francis
Mm-hmm
Ben Johnson
... it seems like it has lots of types compared to that.
Aaron Francis
Mm-hmm. Yeah.
Ben Johnson
So yeah.
Aaron Francis
Yeah. I guess that's true.
Ben Johnson
Yeah. It's kind of fun.
Aaron Francis
Um, okay. Well, I really appreciate you doing this. Like I, like I said at the beginning, I've read all your work. I'm very, um... I'm a big fan, and so this is a delight for me. Where can people, uh, keep up with the stuff that you're doing? Um, and I guess, where can they follow you?
Ben Johnson
Uh, sure. Yeah. Uh, I'm on Twitter. I haven't been as active lately, but, um, I have some other work I'm gonna be doing soon, so I'll probably be a bit more active there. Um, yeah, the Fly blog is usually a good spot for, for content as well. Um, or just open an issue on GitHub or, yeah, just reach out. I'll say hi.
Aaron Francis
Okay. Well, thank you so much. This has been wonderful.
Ben Johnson
Yeah. Thanks for having me. Appreciate it.
Aaron Francis
Yep. See ya.