From Prisma Founder to LiveStore: Building local-first apps with Johannes Schickling
Johannes Schickling, original founder of Prisma, joins me to talk about LiveStore, his ambitious local-first data layer designed to rethink how we build apps from the data layer up. We dive deep into event sourcing, syncing with SQLite, and why this approach might power the next generation of reactive apps.
Everything we said
Aaron Francis
Hey, y'all. Welcome back to Database School. Uh, today I have the other half of the Prisma founding team, I guess. Uh, so I have Johannes Schickling here, and he is the original founder of Prisma, and he's here to talk about, uh, his new project, which, uh, is still in the database space, but quite a bit different. So welcome, Johannes.
Do you wanna give a, a little intro for yourself, and then we can dive in?
Johannes Schickling
Yeah. Thank you so much for having me. Yeah. V- I can't, can't help myself gravitating back to the data space one way or another. It's sort of like in this loop of where I'm trying to build an app and then get frustrated by some part, typically frustrated by some- something in the data layer, and then I'm trying to build myself like a little data system that helps me build this app.
And I'm currently like in both phases of that loop. So I'm building Livestore, which is a local-first data layer, and I'm working on a music app called Overtone, which is s- supposed to be like a third-party music client, similar to how apps like Superhuman give you a really great m- mail experience, uh, where it can add Gmail, et cetera.
Aaron Francis
Mm.
Johannes Schickling
I want that for music. So we can talk about both. But, uh, yeah, this is all my like-
Aaron Francis
So you're, you're a, you're a classic developer in that you w- you're building, you're building a project, you're building a music app, and then you're like, "Man, I really need some better tooling," and then you go off and how long have you been building Livestore now?
Johannes Schickling
Yeah. Uh, so I moved on from Prisma in 2020 and started-
Aaron Francis
Mm
Johannes Schickling
... exploring various other things there. So I, I took a sabbatical, wanted to figure out like, "Hey, am I gonna, uh, is, is ... am I staying with this chapter or am I exploring something new?" And what I realized is like I wanted to be like going back in the shoes of a builder again. So-
Aaron Francis
Mm-hmm
Johannes Schickling
... and so many things have changed at that point in time, and I basically just started exploring a whole bunch of different things. And, and a friend of mine, uh, who's currently running the Ink & Switch research group, Pieter van Hardenberg, I've been staying in close contact with him, and, um, he kinda shared a lot about the ideas of local-first with me at that point.
And, uh, I started looking into that as well, and that really clicked for me. Um, I've been always like kinda on the, uh, lookout for big levers that help really make app development better, and so this is where ... And I'm also typically an early adopter of technology, so I was one of the earliest adopters of Docker back then and React.
And, um, and so s- this is where I fi- where I finally saw, okay, this is a kind of a interesting, different way to think about data management. Uh, I don't think it's just a totally better way. It's just a different way, and like in data, it's all about trade-offs. And, uh, this is where I started like poking around there, and one thing led to another.
I got then involved in a, a PhD thesis of a friend of mine who did- ... his PhD at MIT, uh, about this project called Riffle. And the premise of that was that you take SQLite, and that now runs everywhere, through WASM, et cetera. And taking SQLite and making that the foundation of a state management system.
So think about it like Zustand or Redux or MobX, something like that, but like an even more, uh, sophisticated state management found- foundation, which SQLite gives you. And Riffle was exploring adding reactivity, et cetera, and all of the good stuff you have from a modern JavaScript state management system, marrying that with SQLite.
So that was Riffle, and that I was involved in over, over two years, and that subsequently led to Livestore as the s- um, as the successor project. So I've been really working on this for, for more than four years at this point-
Aaron Francis
Wow
Johannes Schickling
... all by myself.
Aaron Francis
Okay. So, so let's back up. You're, you founded, you founded Prisma. You worked on that for a little while, and then you brought in Soren, who we've, whom we've had on the show. So now we get-
Johannes Schickling
Yeah
Aaron Francis
... the whole, the whole Prisma crew. Brought in Soren, y'all worked together for a while, and then you decided, "Hey, I'm gonna take a, take a little sabbatical." And then as one does, you went and helped somebody do their PhD thesis at MIT. Very normal stuff. Everybody's done it. And then you got kinda involved in this local-first syncing thing and started to ...
Well, I guess you wanted to build an app, and then you were like, "Well, let me first invent a brand-new piece of software, piece of technology, and then I can finish building my, my music application." So what is the, I guess, um, before we dive into what, what Livestore actually is, can you help me understand the landscape of local-first?
Because I feel like I've seen a lot of this local-first stuff popping up, and I've had a few, you know, I've had a few people on the show that have talked about local-first and sync engines and all of this stuff. Can you help me understand like the broad landscape and kind of where you and Livestore fit into that landscape? 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.
Johannes Schickling
Yeah. Totally. And speaking of landscape, I'm also running this, uh, podcast, Local First FM, and on that podcast page, we put together a resource called the Local First Landscape, so localfirstfm-
Aaron Francis
Ha
Johannes Schickling
... /landscape, where-
Aaron Francis
Okay
Johannes Schickling
... we tried to, uh, just provide a lot of information about all the various tools in that space. It's a very rich and broad space with many different approaches, many different, um- Trade-offs really, where it's like, it's mostly like apples and oranges, like a, and a whole gamut of like different fruit and vegetables. Uh, so two technologies are always like pretty tough to compare since they-
Aaron Francis
Yeah
Johannes Schickling
... often like try to, um, like cater to different use cases. So they're ... The Local-First space, I think there's kinda two camps, I would say. There's a, let's say, let's call them pragmatists who are coming to Local-First mostly for the syncing, and this is where you have great technologies such as Electric SQL-
Aaron Francis
Mm
Johannes Schickling
... or something like Zero. And tho- those are great technologies for folks who are kinda more traditional app developers who just-
Aaron Francis
Okay
Johannes Schickling
... want better building blocks to get stuff done faster. Um, which I also count myself to, to that camp. Um, and then there's another camp, uh, w- where more they're in Local-First more for the ideals. So Local-First-
Aaron Francis
Mm
Johannes Schickling
... um, uh, coined it, or the, the folks at Inconswitch coined the term Local-First, uh, in their essay where they outline the seven ideals of Local-First. And that is not just about like fast data, no loading spinners, but that also goes like all the way towards like the users owning their data, having agency over that data, that there's like no third party who kinda like locks everything in.
So that is more like for the idealist, which I also very much appreciate, and I would love all of those ideals to, to become real, but that's-
Aaron Francis
Mm-hmm
Johannes Schickling
... like a much bigger lift. So I see it basically as like, uh, those two groups. They probably want the same thing. Uh, some think a little bit more like galaxy brain, uh, decades in the future, and the other want fast apps today, uh, at the expense to maybe where, uh, it's still more centralized, et cetera.
So that, that is how I would broadly group up-
Aaron Francis
That helps. Yeah
Johannes Schickling
... the, the Local-First landscape. And there's many flavors and many variants of the technologies.
Aaron Francis
And why do you think, why do you think Local-First has, uh, become so popular in the past, we'll say, three to five years? Is there a technology enablement that happened? Is there something with the nature of browsers that happened, or is it just the zeitgeist move towards, well, if we're gonna go faster, we gotta get the data closer?
Johannes Schickling
Yeah. So I think the last point you, you've made, I think already is like a, is a really good proxy for that. Um, so I think there's multiple reasons. There's certainly technological advances where things are possible now. For example, browsers now supporting WASM, et cetera.
Aaron Francis
Mm.
Johannes Schickling
Everything has advanced, so there's cer- a certain unlock there. But besides of like the technological possibilities now, I think there's also a couple of like lighthouse app examples. Linear, for example, comes to mind, and Linear really falls into that pragmatist camp. They famously have built their own sync engine, which allows them as a company to mostly have front-end engineers.
They have a small team the, of the folks who are like building the sync engine, but most of the, the, the rest is really all about front-end developers, which allows them-
Aaron Francis
That's crazy
Johannes Schickling
... to build those like high-quality products that it's, uh, tho- those high s- high-quality experiences that their product is loved for. And I think that has inspired a lot of people. Like, one of Linear's like company values or aspirations is to inspire other builders, and, uh, I think they've, they're really succeeding at that, that they wanna set a high bar for what a product can feel like.
And, uh, I think the unlock to build those high product experiences is data, is fast data. And like when you're dealing with data, it's all about like how you click, you interact with the app somehow, and it should do- give you the, the thing that you want from it. And the longer this needs to round trip to a server, et cetera, the worse the experience is.
And I think they've kinda like understo- understood this very early on, that they said like, "Hey, to give you the snappiest experience, we gotta have that data all local." And I think that as a lighthouse example has really shed a, a big light beam on that space. And then it's, I think another one is that, um, like we've kinda running to a point where we've kinda tried out like most permutations of like what a web framework can be like.
And like overall, things have come a long way. Uh, I've been, uh, I, I know you're, you're a big Laravel fan. I've been like-
Aaron Francis
Mm
Johannes Schickling
... part of the early Laravel community as well, and that has really shown me, uh, like how a great developer experience can be like. But, uh, there's just like, uh, a lot of API improvements, like ergonomics, et cetera, but the underlying architecture was not really challenged or rethought-
Aaron Francis
Mm
Johannes Schickling
... for, at this point, like one to two decades really. And, um, this is I think where Local-First is so much bolder, and what spoke to me in 2020 that I more or less dropped everything and thought like, "Okay, there's really something there that provides a interesting, attractive, different take on this."
Aaron Francis
Mm.
Johannes Schickling
And, uh, that is fundamentally about like let's bring the data as close to the user on the user's device, and if we start making trade-offs all around this, there's some really attractive user experience possible from this. Won't work for all apps, but for certain kinds of apps. And I think particularly now also with AI apps, where everything is so personal and contextualized, I think that's another really interesting trade-off.
Aaron Francis
So it sounds like a, a, a multitude of factors. The WASM stuff and SQLite being around for, since forever, and then being able to run in the browser. But what I'm hearing is that Linear did it, and everybody was like, "Oh, this is better. Let's like build the tooling to make this available to the people." And so that's kind of the explosion of the ...
the local-first tooling. So a combination of technological, somebody showing what's possible, and then, like you said there at the end, rethinking the traditional decades-old, uh, web app paradigm. That makes, that makes sense to me, and it does seem like, um, it does seem like these things happen where, like, three or four factors come together at once in different areas, and then something becomes incredibly obvious, and it sounds like that's what happened here.
So you're building-
Johannes Schickling
Yeah
Aaron Francis
... you're building Overtone, you're building this music thing, and you're looking around and you're like, "Well, boy, this needs to be better, faster, more responsive, snappier." And you look at the, the, to say landscape again, you look at the landscape of local-first, and something is missing. So when you looked out there and you were like, "I could use something like this, but it doesn't meet my needs.
I'm gonna build Livestore," what was the gap that you identified when you reached out and were like, "Let me find something. Shoot, there's nothing here"? What, what was missing?
Johannes Schickling
Right. So I should say that back in 2020, that, like, landscape, uh, had way fewer, like- ... technology columns as today. So-
Aaron Francis
That makes sense
Johannes Schickling
... um, even if I got started today, the kinda column technology that I'm looking for would still not be there, so I would still today probably cam- come to the same conclusion and build it. But back then, there weren't any alternatives either, or, like, very few. There, there were some, like, more OG local-first technologies that have been working on that, like, for, like, over a decade really.
Like something like CouchDB, et cetera, comes to mind. Those ideas have been tried, and even though the term local-first has picked up a lot of s- uh, steam over, like, since 2020 or so, the ideas have been around for much longer. And like, yes, Linear is sort of the lighthouse example here, but some of the OG apps are actually, like, for example, how a mailing works.
Like, a mail client is sort of like the OG, um, local-first app because this is alr- like, you always had your mails locally back in, like, when you had the, the first Outlook versions, et cetera. Like, this worked all offlines. It's, this was like-
Aaron Francis
Mm-hmm
Johannes Schickling
... by default, your computer-
Aaron Francis
That's good point
Johannes Schickling
... was mostly offline unless you, like, beep, beep, beep, um, modemed into the internet. Um-
Aaron Francis
Mm-hmm
Johannes Schickling
... and so another group of, like, OG local-first apps is, like, most of the Apple apps. Uh, for example, if you-- I'm a, I'm an Apple user, and if I need to pin down a, a, a thought very reliably and very quickly, I open the Apple Notes app because I know this works in every circumstance. Whether I'm on a plane, whether I'm somewhere in the forest, in a parking garage, I can just pull it out and write it down.
So those ideas have been around for quite a long time, and there's various k- kind of more th- uh, pioneering technologies that tried to accomplish that before, and they had a much harder time to, to get there for those technology constraints. So another technology that comes to mind here is Realm, th- who got acquired by Mongo way later, but they tried to already do that way earlier, but they, they didn't have those tailwinds that we have these days where Wasm runs everywhere.
Also, like, the, the, the problems are more felt. I, I'm, I'm a big believer in, like, that a technology is successful, there needs to be a problem first that people have experienced for, for this problem to, to resonate. And I think for those technologies, the right time hasn't come yet.
Aaron Francis
Mm.
Johannes Schickling
So back in 2020, uh, I looked at the landscape, and there was very, very few, and there, there were already a few folks who kinda were getting on the same path. But I think just over the last couple of years, uh, like, all of those technologies popped up more, and they're also-- When you try something new, you might not get it right all, um, right away.
And so for example, the, the folks who are building Xero, um, the, the folks from Rosie Corp, they had two prior product approaches that they're now deprecating in fa- or, uh, deprioritizing-
Aaron Francis
Oh my God
Johannes Schickling
... uh, now in favor of Xero. So this is a fairly new emerging space where still many things are, uh, being tried out.
Aaron Francis
Hmm.
Johannes Schickling
But what was c- aside from, like, the particular technological decisions, what was clear for me is that if I want to build an ambitious app, then the bottleneck that holds me back to make this app become a reality is data, since most of the other things are really, like, pr- we're, we're in a pretty good shape already. Something like React, Solid, Svelte, all of those things are fantastic foundations to build something.
Uh, building for the web in particular, we have so many great options, but also on mobile. It's pretty decent to build something in SwiftUI or React Native or for Android. Um, but what about the data story? And particularly when you want those snappy user experiences, this is where I felt, "Okay, this is where we still don't have the React equivalent for data," and this is where I see the promise in local-first and syncing.
Aaron Francis
You know what? That is very interesting to me, the fact that we do have, I won't call it a solved problem, but close to a solved problem on the front end with these great, you know, battle-tested frameworks. A lot of innovation has happened there. But I agree, the data layer has not had the same, like, explosion of innovation and frameworks and stuff.
And so that actually makes a lot of sense to me as to why now, like, why these things are popping up now. Because all of that problem-solving energy has to go somewhere, and, like, React already exists. Let's put that energy somewhere else. So talk to me about Livestore. So give me, give me the, uh, give me the high-level overview of, like, what problem it solves and how, and then we can dig into some of the technical details and trade-offs and decisions you've made in the process.
Johannes Schickling
Right. Uh, I'll, I'll start here by saying, uh, to, to follow up on, on your point, like, that we don't have those data frameworks, and to contrast how LiveStore is designed compared to Prisma. With Prisma, I tried to meet people where they are, and, uh, no matter which kind of app people build, no matter which kind of architecture they're building for, as long as they're using TypeScript, as long as they're using one of the common databases, Prisma works for them.
Um, so it was very unopinicated, and it tried to bring- Mm ... like TypeScript, et cetera, like typing to, to developers. With LiveStore, I'm taking a very different approach. I'm very opinicated. I'm very opinicated about a per- uh, about a particular architecture, about a particular data design, and I'm trying to, like, only cater to that.
And, uh, I believe that for data, this is where the, the mantra, like, it depends, applies ultimately. Mm. I think you can only provide a lot of value for a particular sliver in a particular kind of architecture. Mm. That's, like, already, already philosophically kind of, or from the goal-setting perspective, very different to what- Mm-hmm ...
I've tried to do before. So, uh, with that out of the way, like, LiveStore is trying to be a good data layer for what I would call user or document-centric applications. Okay. So, um, let's define that maybe to, by what it's not trying to be. Okay. So it's not trying to be a good data layer where you build your next social network on.
Something like- Okay ... Facebook or Twitter. Um, those is, those kind of platforms are very, very different in terms of, like, how you'd build them, like massive databases, highly connected to where, compared to something like your Notes app, which is all about you. Oh, I see. Mm. And it's all about, like, what is the body of content that is being created?
Like, how is that structured? How does that grow? And how does that- Mm ... kinda sprawl? And in the social network, you, I mean, as the name suggests, you have a network of, like, highly, highly, highly connected things. But if you're thinking about, um, your Notes app, that, like, your Notes app and my Notes app have prob- unless we've shared something explicitly, has no overlap.
Mm. And, like, all of my notes easily fit on my phone, like forever. Mm-hmm. Um, whereas, like, all of the Facebook data doesn't fit on any computer at this point. It was like needs to be, like, dealt with entirely differently. And so I want to, like, embrace that, that, like, for some apps, not for all apps, but for some apps, it's much more like notes, like in, in size and, and like how it's structured.
And so when you're building an app that's s- uh, like oriented around a small group of users, let's say a family, a small company, even like a, a large-ish company, uh, for certain kinds of apps, all the data, uh, fits into, like a local database. Mm. Or at least that you can say slivers of that app data fit into a local database.
So when you think about, for example, Linear, you could say, "Well, I'm in such a big enterprise that all of the Linear workspaces don't fit on my device. However, I may be just, like, in those subteams, and thus- Mm ... all of the data fits on my device." And when you flip that, and you think about, like, I have all of my data locally, then you can build an entirely different data architecture.
Since, an- another thing to, to motivate here is, like, one of the hardest things in, uh, computer science and building apps are distributed systems. Mm-hmm. And I think distrib- like, this has really been, like, uh, like the, the most intense learning experience for me over the last couple of years, where I really needed to, like, face that reality.
And, uh, like I think th- s- it's kind of like the, the elephant in the room for many, many apps, and goes by many different names, whether it's like caching, cache invalidation, optimistic updates, et cetera. Mm-hmm. It's all sort of like, uh, different acknowledgments of like, hey, there's something really hard, and that is distributed state.
And the only way how you can tame distributed state that it doesn't become a game of Whac-A-Mole is by, like, picking a certain architecture and then really embracing it. Otherwise, you'll constantly fight it. And this is where I'm starting with that architecture to have all the data local, and then back work backwards from, like, making that an awesome experience.
Since most web apps are different. They're, like, have their database not local, but they have their database somewhere, um, on a big Postgres database in the cloud, and then they, like, fetch it, add a little bit of caching, add a little bit of optimistic updates, and that works as well as until the point where it no longer works, and you, you start, like, your app turns into a database.
You had, uh, Carl on, on- Mm-hmm ... your podcast I think two times. Mm-hmm. And he wrote this amazing blog post where he's like, "Stop building databases." Mm. Which makes the point that, um, for c- most c- complex enough apps are accidentally turning into a database. And, uh, I 100% agree with this.
And, like, my takeaway from this is, I think similar to Carl's, is like, hey, let's actually use a database to build our apps so we can free up, like, 80% of, like, the, the mess that we've created trying to tame that data. Um, and that just disappears when you start embracing a database. And now the second question for me was, like, okay, that wor- that's how it works on a single device, but how do we build it in a way that, like, my iPhone syncs with your phone?
Mm-hmm. Or, like, how does this work across different devices? And, uh, so yeah, that, that, that just gives you a bit of, like, a starting motivation or, like, how I've rewired my brain. And now I'm coming back to your initial question. So Livestore Livestore is a SQLite centric, um, client-side data layer that supports, uh, cross-device syncing and cross-user syncing based on event sourcing.
So we can explore more what that all means, but it's basically, let's say you're a React developer, you want to build like a linear-esque, uh, feature, uh, linear, linear-esque app, and you're thinking, "Okay, how do I build that?" Then Livestore tries to be a good foundation for that. And so it replaces things like MobX, Redux, tho- those sort of things, but that's on the client, but it also replaces the backend data layer for that.
Aaron Francis
Okay. All right. Let me say some of this, let me say some of this back to you to make sure, make sure I got it all. So one of the points of view that you have as, as Livestore is you are building for, um, we can call them maybe like tenant applications.
Johannes Schickling
Mm-hmm.
Aaron Francis
Whether the tenant is a team, big or small, or an individual, but you're not, uh, you're not trying to solve the use case of a large interconnected set of data. You want pretty clear boundaries on tenants, and that makes this whole, that makes this whole process easier. And is that, uh, or I think that is where you've expressed some of your opinionated nature is we're gonna help and solve this use case, but not the other use case.
Whereas with Prisma, you said, "We'll be everything. We'll be all things to all people." Here you're saying, "Whoa, whoa. We're doing basically tenanted data." And so it sounds like another, um, another point of view that is opinionated and different from what Carl is doing, whom you mentioned earlier, is your syncing or your source of truth is the events.
So Carl came on, you know, a few episodes ago and was talking about, uh, Graft and basically, you know, syncing blobs and little pages and little parts of pages, and nobody knows what's in the pages. We'll just sync them. And sounds like that works great for a lot of use cases, but you have a different opinion with this, with this project that you're working on, and that is event sourcing.
We're gonna do event sourcing. And so I think you said, uh, Livestore is a data, SQLite centric data layer that syncs da- uh, I'm sorry, syncs events. Is that, is that close to what you said?
Johannes Schickling
Yeah. So, um, I, I think there's two core technologies that f- for someone like checking this out, uh, that y- you need to internalize and then s- things start to make sense. So one is you have locally, you have a SQLite database.
Aaron Francis
Mm-hmm.
Johannes Schickling
And that SQLite database, this is where you read and query all of your data from. That is reactive, super fast. Um, like if you have multiple clients working at the same time or let's say in a local web app, you have multiple tabs open, et cetera.
Aaron Francis
Okay.
Johannes Schickling
You always query that database, and this is your primary place where you get stuff from, where you read things.
Aaron Francis
Mm-hmm.
Johannes Schickling
But, um, the question now is like, how do we write stuff?
Aaron Francis
Mm-hmm.
Johannes Schickling
And how do we write this in a way that in a distributed way where like I'm having my web app open over here, and I have it on my phone open over there.
Aaron Francis
Mm-hmm.
Johannes Schickling
There's latency. The phone might go, go offline, et cetera. How do we make sure that those writes, um, are all working correctly? This can mean different things. Let's say you're building sort of like a GitHub Issues kinda thing. Um, do you want to ... What should happen if two people, um, like try to, like one closes an issue, the other one still works on it as if it was still open.
Aaron Francis
Mm-hmm.
Johannes Schickling
Or they're just like conflicts that can happen. So the writes need to be dealt with, uh, with much more intent compared to a traditional web app, where in the traditional web app, like a database can just say like, "Hey, we start a transaction that might run a few hundred milliseconds," but no one is like, no one is dealing with that data until the transaction is done.
But in this local-firsty way, now those transactions might actually happen locally without knowing, uh, what's going on over here. So and you need to reconcile that somehow, and this is now where event sourcing comes into play. Since, um, the ... We've, we've kinda like looked at this, these problem statements before, and this is what led to, like back in 2011, I think, uh, led to, or 2014, led to Facebook introducing the Flux architecture.
Aaron Francis
Mm.
Johannes Schickling
So the, the Flux architecture later m- famously, uh, like led to Redux. Redux was like, uh, I think these days it's not as big anymore, but the ideas behind it, I think, are still very relevant, and I think we'll have sort of a renaissance of those ideas. I'm, I'm certainly embracing them with Livestore.
And the idea here is to not have your state be directly mutable. So in this case, if your database is you're representing your state as being synced across clients, you don't directly write to that. Since at that point, when you have m- mutable state, uh, things get messy.
Aaron Francis
Mm-hmm.
Johannes Schickling
You don't know exactly when something has happened, why something has happened. M- you don't know quite what is the source of truth. Um, when you have that, you also need to think about database migrations. That becomes a big problem as well.
Aaron Francis
Mm-hmm.
Johannes Schickling
So, um, I got fascinated with the ideas behind event sourcing, where there's a f- fair bit of like literature around it, and it's been mostly employed as an idea more in like microservices, et cetera.
Aaron Francis
Mm-hmm.
Johannes Schickling
Martin Kleppmann has written a, a f- fantastic, um, essay about it calling, uh, calling it the turning the database inside out.
Aaron Francis
Mm.
Johannes Schickling
Um, but the same ideas really apply to Redux, and the JavaScript e- ecosystem had internalized those ideas before, and I wanted to reapply them now, but in combination with SQLite. And the idea is basically instead of, uh, let, let's say you're building a linear app and you have a button that says Create Issue, and, uh, you create it.
Instead of s- ... uh, applying the insert into issues statement right away, you i- you create a event that says like, "Hey, the user wanted to create this issue," and then you, uh, apply the insert into a table statement. But then instead of syncing around that insert into a SQL statement to other clients, you sync around that event.
And now those other, uh, clients, if everything goes well, they can just apply it. But in case, um, they have dealt with something locally, um, that kinda conflicts with this, now it's way easier to think about that event, uh-
Aaron Francis
Mm-hmm
Johannes Schickling
... as opposed to deciphering a CRUD-like SQL statement.
Aaron Francis
Mm-hmm.
Johannes Schickling
And, uh, so that has many, many benefits. Uh, just to, to name a few, it helps you to deal with, like, local-first apps in this distributed setting, but it also helps you with just taming your database more broadly. When you have a certain, uh, state in your database, you might actually have that kinda be duplicated across your app, and then you don't quite know, like, hey, is this the source of truth of the, of that data?
Or is that-
Aaron Francis
Mm
Johannes Schickling
... the source of truth? Um, and with event sourcing, you know this event is the source of truth, and we can completely, um, like, reset the database and rebuild it from scratch. And, uh, that is also implies the kind of like a trivial solution to schema migrations since if you now want to change the schema of your SQLite database, um, then instead of, like, manually doing that, you can actually fully throw away the local SQLite database, run
through in your entire event history again- ... um, and apply it to your new database schema. And that was really, actually, that was a surprisingly-
Aaron Francis
That's kinda cool
Johannes Schickling
... motivating, um, use case for me coming from Prisma where I've, like, tried for over four years to, to make database migrations nice, and you can just only do so much in that architecture.
Aaron Francis
Yeah.
Johannes Schickling
And with event sourcing, it has the most beautiful solution to schema migrations, which is, like, to not do them at all. And, uh, so there's many ... As ... The more you pull on that event sourcing, um, thread, the, the more kinda like positive benefits come-
Aaron Francis
Mm-hmm
Johannes Schickling
... soaring in your way. Another one is time travel. I'm not sure whe- for those, uh, listening who tried out Redux, um, one of the amazing things about it were the Redux DevTools where you got, like, that time travel feature, um, which just blew my mind back then, and that's something you can now get in combination with SQLite, et cetera, and a signals like reactivity system around it.
So basically just trying to combine different ideas that were already kinda explored in isolation in the past and now putting it together in a, in a nice modern, uh, data layer.
Aaron Francis
Well, you make a compelling argument for event sourcing. So let me, uh, let me ask you this. So you said there's a local, local SQLite database, and instead of, instead of just writing, you know, insert into todos or whatever, you, uh, you fire an event, and the event is insert todo, and the payload is, you know, name and body and, you know, due date or whatever, right?
So you have this envelope of, of data. You've got this event, and this is, this is your source of truth. Now, talking specifically about LiveStore, you're in the browser. You fire off this event from, you know, View or React or whatever, um, and you fire that into, you fire that into LiveStore, and at that point, LiveStore takes over and does all of this stuff.
Um, that's the first question, and the second question is where are the handlers written? So do you have to have the handler, the event handler on every client? Is there some sort of centralized back-end state? Who is doing the, um, translation of create or insert todo, uh, into, you know, insert into tables todo?
Where does that, uh, transmutation happen?
Johannes Schickling
Right. So, uh, start. Le- let me just double-check. Uh, connection should be good, but I'll ... I have the questions, so remind. Um, so le- let me start out first by saying that the event should actually not be as CRUD-y in nature as you made it sound.
Aaron Francis
Okay.
Johannes Schickling
So the event is not insert into todos, but the event should be almost like if, like, a, a business person would have written it, a business person who's not an engineer and is just like, "Hey, I, um..." In this case, it might be like, "Hey, I created a new todo," or later-
Aaron Francis
Okay
Johannes Schickling
... "I completed a new todo." So instead of saying, um, "I updated todo and set complete to true"-
Aaron Francis
Mm-hmm
Johannes Schickling
... a, a more natural way to describe is like, "Hey, I ... What did I do with the thing? I completed it," or a user signed up. So instead of, like, a user was created, a user signed up, since we might later, um, like, wanna reinterpret what that actually means. So-
Aaron Francis
I see
Johannes Schickling
... this is where also where the ideas of, like, domain-driven design and domain modeling-
Aaron Francis
Mm-hmm
Johannes Schickling
... come into place. And, like, ultimately, we're building software to make a certain real thing happen, and now we should model it after that real environment. And, um-
Aaron Francis
So the, the event should describe what happened, not try to imply what you should do with it. You just describe-
Johannes Schickling
Exactly
Aaron Francis
... what happened.
Johannes Schickling
Exactly.
Aaron Francis
Okay. Got it.
Johannes Schickling
It should capture whatever context about that is relevant. So when a user signed up, the context that is relevant is their name, is their-
Aaron Francis
Mm-hmm
Johannes Schickling
... email address, is maybe whether they want marketing mail or not. But how we deal with that later, whether we write it into a customer's table or into a user's table or into employee table, uh, who knows?
Aaron Francis
Got it.
Johannes Schickling
We might completely change our mind later would we deal with this. But what is important is, like, a fact. A snap- like-
Aaron Francis
Cool. I like that
Johannes Schickling
... not a snapshot of, uh, of the entire thing, but, like, the, all the contextual information that is relevant to this thing that has happened. So that distinction is, like, fairly important.
Aaron Francis
Mm-hmm.
Johannes Schickling
I think sometimes they're, like, very close together. Um, but sometimes it also makes a huge diff- Like, for example, if you're building a shopping system, you say, like, "Hey, the, the order was submitted." What that means in your actual, like, e-commerce system, there's pro- probably writes to, like, eight different tables doing something crazy.
Aaron Francis
Yeah.
Johannes Schickling
Um, but domain-wise, like, hey, the customer has submitted the order. So-
Aaron Francis
Mm-hmm
Johannes Schickling
... with that out of the way, uh, let's look into the mechanics of, of LiveStore. So, um, there's the SQLite database. Um, and then there's also something called the event log. So all the events are-
Aaron Francis
Okay, first of all, are these all-
Johannes Schickling
Yeah.
Aaron Francis
Is this all in the browser? Where, where are we living-
Johannes Schickling
This is all-
Aaron Francis
... when you, when you're talking about this?
Johannes Schickling
Yes. So, uh, LiveStore is pluggable. So I have platform adapt- adapters for various-
Aaron Francis
Okay
Johannes Schickling
... platforms. I have currently one for, for the web. Uh, I have one for Expo, so that you can run it on-
Aaron Francis
Mm-hmm
Johannes Schickling
... iOS, Android. Um, and I have one for Node, which also runs in, in Bun and Deno, et cetera.
Aaron Francis
Okay.
Johannes Schickling
There's plans for Electron, Tauri, et cetera. So it will be cross-platform, but let's work with the web example for now.
Aaron Francis
Okay, let's start with the web. So we have a database. Keep going.
Johannes Schickling
So we have locally, we have our web app, and remotely we have some sort of sync backend. The sync backend is basically only accepting those event messages, and we're connected to it somehow. So-
Aaron Francis
Mm-hmm
Johannes Schickling
... locally, let's say a user clicks a button. Let's say they say, "Hey, this to-do is completed." What happens?
Aaron Francis
Mm-hmm.
Johannes Schickling
Um, somewhere in, let's say we're building this with React, uh, the, there's a React click handler. That React clickle- click handler runs some code. The code it's running is this store.commit todo completed.
Aaron Francis
Mm. Okay.
Johannes Schickling
So store.commit. LiveStore syncing is, like, very Git inspired.
Aaron Francis
Mm.
Johannes Schickling
Uh, and so when we are changing something in Git and we're happy about what we are, wanna do, then we create a commit from it, and then we push that commit. It's very similar here in LiveStore. So we commit an event, the event we've designed according to our app. So here we say, "Hey, we have an ... We, we want an event that captures when someone completes a to-do." So we just say store.commit events.
uh, todo completed. We capture maybe the to-do ID, maybe the time when it was completed-
Aaron Francis
Mm-hmm
Johannes Schickling
... everything that's necessary for this event, and that is then committed to the event log. It is immediately also applied to the SQLite database that the UI updates.
Aaron Francis
Mm.
Johannes Schickling
And it's done so through a thing that's called a materializer. If you're used to Redux, then those things were called reducers. Given that we're here not just reducing into, like, a JavaScript variable, but we're going through this database, there is, like, the, the concept of materialized views. Um, and but you're materializing state, and that is the, the name I've chosen here.
So your event is being materialized into the database by you expressing how that should happen, and that is typically, uh, here would be a simple, uh, update statement. Like, you, you just update a row in a database. But you could do, uh, whatever to the database in response here to that event.
So again, you commit that event. The new event is added to the event log, immediately applied to the database by flipping the probably, like, in a todos table, flipping the completed to true, and that refreshes React immediately, so you have on the next frame, uh, you have your expected state.
And then in parallel, if you're building an app that's actually also syncing, which is optional, but let's say you're building an app that syncs across devices, across clients-
Aaron Francis
Mm-hmm
Johannes Schickling
... um, then that event is also pushed to the sync backend. The sync backend, uh, just, like, accepts it. Think, think about it as like a Git server. Um, it might reject it because, um, you have maybe fallen behind. But let's say it accepts it. It writes it into its own event log and also then, um, sends that down to all the other clients who are constantly pulling.
And then all the other clients basically just m- uh, add it to their own event log, materialize it, and poof, it's reactive in the other clients. And that typically happens within milliseconds across the network.
Aaron Francis
Okay. That's a very helpful, uh, life cycle. Let's start back with, let's start back with the React click handler. So, uh, onClick or whatever y'all call it, onClick, you know, store.commit, and then you commit this event. And you said the event, and inside the event is some payload.
Uh, the event goes to the event log. What is technically the event log? Is that a discrete entity from the local SQLite database that holds your materialized state?
Johannes Schickling
Yeah. So it's currently, um, it, it really just needs to be a persisted list of events that could-
Aaron Francis
Okay
Johannes Schickling
... be stored however you want. You could even put it in-
Aaron Francis
Hmm
Johannes Schickling
... local storage or something. Um, as, uh, you, you can maybe already guess the answer, but that itself is a separate SQLite ta- database.
Aaron Francis
Mm-hmm.
Johannes Schickling
Uh, just because I have all of the SQLite machinery already in place, and it's super nice to work with that. But that is really, like, the simplest SQLite database you can think of. A single table, which is called event log, where you just append only those events. Um, but those are separate SQLite databases for that reason that if you want to change your main SQLite database, let's say you have currently-
Aaron Francis
Mm
Johannes Schickling
... a to-dos table, and you want to completely change how, uh, how you wanna model that. Maybe you're-
Aaron Francis
Mm-hmm
Johannes Schickling
... you're really, like, building a, a version two of the app and it's now called Issues, and there's another one that's called Tasks, and they're different things. Uh, so completely new schema. What you do is you change that schema to whatever you want. You adjust the materializers. Next time the app boots up, a fresh database is created, it runs through the entire event log, and your app is in the new desired state.
Aaron Francis
Okay. So you're writing to, uh, you do store.commit, and it writes to an event log that is backed by something. Most of the time it's gonna be backed by a separate SQLite database, just a big old table. Then after the event has been committed, so your source of truth has been updated, um, we have a new thing that has happened, then we have to take that event and
materialize it onto, I don't know what you should call it, the application database or the, the state database or whatever. Um, presumably you wrote the code that says, "Turn this, uh, event completed event into... or to-do completed event, turn this into a SQL, a SQL statement." So that is-- Do you call that the materializer?
Is that the name you give that thing?
Johannes Schickling
That's right. Yeah.
Aaron Francis
Okay. So the-
Johannes Schickling
So-
Aaron Francis
... materializer runs because a new event has been added onto the stack that has not yet been materialized. So this materializer, um, does this live in the application, and so every connected client is expected to have the same materializer code?
Or is this somehow, I can't imagine how, passed in the event so that clients can run the materializer without even having the materializer? Where-
Johannes Schickling
Right
Aaron Francis
... where is this materializer written?
Johannes Schickling
Um, yeah. So you're, you're asking, like, how are things bundled and pushed across the, the boundaries.
Aaron Francis
Yeah.
Johannes Schickling
Um, and so, uh, given that we're dealing with JavaScript here, and you famously can't, like, serialize JavaScript functions easily and send it across the wire, um, there's certain parts that your app is expected to already have when it boots up.
Aaron Francis
Right.
Johannes Schickling
And then some data is sent over the wire. Uh, so let's assume the scenario where the different clients you're running are actually the... They're, they're really, like, the same kinds of clients.
Aaron Francis
Mm-hmm.
Johannes Schickling
Um, in that scenario, you would basically just... You, you push app version 1.5, uh, you push it to your, your CDN, the various apps boot up, and they all have the same, uh, LiveStore schema. The schema is really just like, uh, how should your SQLite database look like? How do your events look like? And what are the, the materializer's code?
Aaron Francis
Mm-hmm.
Johannes Schickling
So all start up with the same code, and they all work in the same way. Um, and that basically also means in the unlikely scenario where you have a app that wasn't upgraded yet and somehow-
Aaron Francis
Mm
Johannes Schickling
... sees a new event that it hasn't yet, uh, been, been ready for, well, that is then kinda like, uh, it, it just puts it to the side, freezes the app in sort of a way that you should render, like a, a message which says, "Hey," like, "Upgrade your app, please."
Aaron Francis
Got it.
Johannes Schickling
Um-
Aaron Francis
Okay
Johannes Schickling
... but the materializer code, which is typ- Like, a materializer sounds more complex than it, than it is. It's really just, like, it's a callback function that returns a SQL statement.
Aaron Francis
Mm-hmm.
Johannes Schickling
Uh, LiveStore has, like, a kinda query builder thing built in that makes, like, type safety, et cetera, nicer, but you can use whatever you want there. You can use, uh, Prisma at some point. Uh, you can use Drizzle. You can use raw SQL, whatever you want. Um, but yeah. Materializer's super simple, but they need to be part of the app.
Um, what you could even imagine as well, uh, is that, uh, maybe there's a different kind of client. Maybe it's sort of like a admin dashboard where you rather wanna-
Aaron Francis
Mm-hmm
Johannes Schickling
... track how many to-dos were created today. Um, you could also say, "Actually, uh, I want to materialize that entirely different. Um, and I rather-
Aaron Francis
Oh, that's interesting
Johannes Schickling
... want to have, like, a count table, uh, that, that tracks that." And so, um, you can have just a different kind of client, but they're all working over the same event log.
Aaron Francis
That's interesting. So you don't have to-- This is obvious now. You don't have to materialize it the same way in, like, at the same time. I think I've been thinking when you're like, "You can change how you materialize it," that's when you say, "Whoops, I messed up. Let me change my schema and then replay all these events." But you can materialize these things differently in different applications.
And so-
Johannes Schickling
That's right
Aaron Francis
... I'm thinking, I'm thinking the materializer's pretty important. We gotta make sure every client has the same materializer, when in reality- Every instance of a particular client does need the same materializer. You know, we have it open in two tabs. We wanna make sure we're materializing the same way. But you could have a desktop app that materializes differently, a separate web app that materializes differently, a phone app that materializes differently.
And so it doesn't super matter, and it doesn't make sense at all to try to embed the materializer into the event, because then obviously you can't change it later 'cause the event log is supposed to be immutable. Okay. This is all, this is all starting to come together for me. So-
Johannes Schickling
And just to recap sort of like a main point here, um, is a- about what can you change later and what is the source of truth. The events are really the only source of truth here-
Aaron Francis
Mm-hmm
Johannes Schickling
... and everything else is downstream. And I think that really nicely expands on what I love so much about React, that React famously was introduced as, like, the UI is-
Aaron Francis
Mm-hmm
Johannes Schickling
... um, a pure function over the state. Like, UI is F over state. And now we basically can apply the same, like, uh, beautiful, uh, concept here that, like that F, that rendering, that is like-
Aaron Francis
Mm
Johannes Schickling
... that's a pure function. I think by now we, we are not as afraid of, like, saying pure function becau- in the past-
Aaron Francis
Mm
Johannes Schickling
... it was sort of like functional program-ish. But-
Aaron Francis
Mm
Johannes Schickling
... uh, with React, we all know what, what is so nice about this. And the cool thing here is, like, LiveStore applies the same idea, uh, twice. So it says basically-
Aaron Francis
Mm
Johannes Schickling
... uh, UI is F over state. The state is, um, just a query for your database, which is also a pure function, like, and synchronously returns. This is-
Aaron Francis
Mm-hmm
Johannes Schickling
... you always know what you get when the database is in a certain state. Querying that always returns you the, the same data. And now the question is what is the database? And the database is a pure function over how you materialize the events. And so you basically have like three pure functions, super easy to think about, super easy to, like, reproduce.
If something goes wrong, you... Like, that's always one of the hardest things. Like, something goes wrong, how do I reproduce it? How do I test for it? And there's no easier code to test for than synchronous code, pure code.
Aaron Francis
Mm.
Johannes Schickling
And so that is... I, I think that's sort of like the superpower of LiveStore is simplicity.
Aaron Francis
Yeah. This is really cool. Um, I have always, I've always admired, uh, this part of React, not all of it, but I've admired this part of React, that they were very clear that the UI is a function of state. And I thought, "Oh, yeah, that makes, that makes a lot of good sense." And so, uh, going all the way down the stack, you've applied that same idea.
So the database, what we're calling the, you know, the application database, the database is a function of events, materializing events. So-
Johannes Schickling
That's right
Aaron Francis
... at the very, very bottom, the bedrock is events. They are forever, they're immutable. That is our source of truth. Then you apply a function-
Johannes Schickling
And they're easy to think about. They're very-
Aaron Francis
Yeah
Johannes Schickling
... like it's one thing at a time. They always happen in the same order. And like, you know, like this has happened and this has happened, and you can like deal with that however you want.
Aaron Francis
Yes. And they're discrete. They're nice units.
Johannes Schickling
Yes.
Aaron Francis
Like, they, they're not messy. They have clear boundaries. So you have events and then you apply a function on top of that and you get a database out of that. Then you have a database and you apply a function, which is a query, and you get some sort of state that you can then, you know, put in your application. And then you have your state and you apply a function, and you get UI, and that is React.
That part is React. The other two parts are you. So this-
Johannes Schickling
And the entire thing is reactive
Aaron Francis
... this entire function makes a lot of sense.
Johannes Schickling
So it's-
Aaron Francis
Yeah. I guess so
Johannes Schickling
... all a pure function, but it's reactive.
Aaron Francis
Yeah.
Johannes Schickling
That means if you click the button, every, all of those stuff happens within-
Aaron Francis
Mm-hmm
Johannes Schickling
... like a fraction of a millisecond and is ready, uh, for, for you in the next frame. Uh, so it's everything super simple and super fast.
Aaron Francis
This, this is clean. I like, I like the, um... I like the discrete boundaries and the ease of reasoning, um, because, you know, like I know that we'll go back to Carl. Car- Carl's doing some amazing and powerful work, but it's a lot, like it's a lot to think about these individual pages and blobs and, like, that obviously serves a very important purpose, but this is very discreet and I like that.
The boundaries are very clear. The envelopes are very clean. That makes a lot of sense to me. Um, you said this, this is all so far self-contained. This is all isolated inside of one browser tab. You mentioned, um, when it goes to the event log, it can propagate or, uh, replicate or sync out to someone else, and I imagine that is a centralized syncing server.
Is that true? And if so, talk to me about this centralized syncing server.
Johannes Schickling
Yeah. Um, that, that's exactly right. There's like one middle step that we could actually talk about just for the sake-
Aaron Francis
Okay
Johannes Schickling
... of completeness. So even if you don't have that sync- centralized syncing server, um, they're... Like, you're running a web app, um, maybe sometimes not just in one tab, but maybe in multiple tabs or in multiple windows. And how do you-
Aaron Francis
Yep
Johannes Schickling
... deal with that? Not every app is commonly used in this way, but let's say we're building Notion. Um-
Aaron Francis
Mm-hmm
Johannes Schickling
... and in Notion I often have like multiple different pages open at the same time, and sometimes I even have the same one open at the same time, or they reference similar data.
Aaron Francis
Sure.
Johannes Schickling
So let's say I'm like building a more like offline-ish Notion thing, um, a way simpler one, but the, the core thing here is really I have state that, uh, is kind of the same state that I want to have in both tabs So most web apps only work in this way by going through, like, a, like, an API. And it's, it's sort of-
Aaron Francis
Mm-hmm
Johannes Schickling
... like, almost comical if you think about it, that, like, to, to-
Aaron Francis
Going from your, your browser out to Virginia back to your browser.
Johannes Schickling
Exactly. Just that you have the same data in th- in your two different tabs.
Aaron Francis
Mm-hmm.
Johannes Schickling
Uh, it gets even more comical if that breaks. But, uh, LiveStore is built in this sort of, like, hierarchical way, where there is, like, layers of syncing. And, uh, the simplest, uh, layer of syncing is, like, how a single tab syncs its state also to, like, a written database that if you, like, reload the app, that the SQLite database, uh, doesn't suffer from dementia, but it's still- ...
knows exactly what it, what it had before. And then the next layer of syncing is that it syncs between different tabs or different windows. So when you say-
Aaron Francis
Mm-hmm
Johannes Schickling
... you build an Electron app, you have multiple w- multiple windows, or in-
Aaron Francis
Mm
Johannes Schickling
... a browser you have multiple tabs. So LiveStore's syncing thing already starts locally, where it basically, it just propagates those events across those tabs. It's like, it's the same thing if you think about this as sort of like the, uh, flux, like, data flow unidirectional. Uh, it basically does the same thing in, in each tab and then also propagates the events between the different tabs, that they all end up in, in the same state.
Uh, doesn't mean they have to show the same pixels, but they still-
Aaron Francis
Sure
Johannes Schickling
... have all access to the same SQLite database. And that same idea is then just reapplied again in a more global way, where you now, instead of syncing the events between tabs, you now sync it to some backend service, and the, the circular loop is just a bit bigger.
Aaron Francis
So can we pause and back up just one second? How... I'm not familiar enough with, you know, Chrome's tab isolation and the, the nuances around local storage and Wasm and all of that stuff. Um, so in the instance where you've got the, you know, the Notion thing open in two tabs, are they, are they able to look at the same event log, or are those in sandboxes and you literally do have to s- like, send an event over the wall to the other tab?
How does that work at a technical level?
Johannes Schickling
Yeah. So there, there, we can get very technical, uh, to-
Aaron Francis
Let's go medium, medium technical.
Johannes Schickling
S- so, uh, since there are, like, multiple ways to, to do that, um, the, in case someone wants to roll something like this themselves, the easiest way to accomplish this is to create something that's called a broadcast channel, which is basically-
Aaron Francis
Mm
Johannes Schickling
... like, you create this, you instantiate a thing called new broadcast channel, and then you give it a name, say, my channel. You do that in both tabs, and then you can just post messages to that and listen to messages.
Aaron Francis
Hmm. Cool.
Johannes Schickling
That is the easiest way to do cross-tab things. Uh, there's also other ways. Uh, you can abuse local storage for that to look at, like, each writes to local storage, and the other one just listens if something has happened.
Aaron Francis
Hmm.
Johannes Schickling
You can also use IndexedDB for that. Um, what I'm doing for LiveStore is I'm using a shared worker that both instantiate. The reason for that is that SQLite is binary data, and I can't just like-
Aaron Francis
Mm
Johannes Schickling
... send messages that are, like, always encoded as a string, but I need to move memory. Like, if you're familiar with Rust, et cetera, you know the difference between copy and cloning data, uh, as opposed to moving. I need the move equivalent here, which JavaScript gives us, with transformable, transferable primitives. Um, and so that's basically how I create this little connection between those two tabs.
Aaron Francis
Hmm.
Johannes Schickling
And that shared worker is basically acting as, like, a little mini local sync backend- ... uh, that all the ones talk to. And then if you're using, like, proper syncing to, like, a backend, then that thing just propagates it even further.
Aaron Francis
Okay. Didn't know any of that, so that's very helpful. Thank you for explaining that. Um-
Johannes Schickling
The, the web is amazingly capable. I think there's so many-
Aaron Francis
Apparently
Johannes Schickling
... so many untapped potentials that, like, the, like... It's incredible what the web can do. I think it's just that, uh, we've been kinda thinking about building web apps more kinda like, uh, react server component down as opposed to, like-
Aaron Francis
Mm
Johannes Schickling
... capabilities up.
Aaron Francis
Mm-hmm. So in, in this, in this sync life cycle, let's expand, I think you said, a little more, make the loop a little more global. So the, at some point, I guess the, uh, event log says, "Hey, I got a new event," and then it probably loops through everybody that it should sync to, whether that is local or global, you know, hand-wavy, and it syncs out the event to something.
Is that something, is that sync server, is that basically just running LiveStore but on something that is, uh, persistent, whether, like, a server or durable object, or could it even be a fleeting Lambda? Like, where does the sync server run, and what does it do?
Johannes Schickling
Hmm. Right. So a sync server is conceptually super, super simple. It is an endpoint that receives messages, receives pull requests or push requests. So-
Aaron Francis
Hmm
Johannes Schickling
... a pull request is, um, like, "Hey, give me all the events either since the beginning of time or since event 100." Like, l- "Event 100 is the last one I've seen. Give me all the new ones." Um, and a push request is like, "Hey, I have, like, those two new events. Please, uh, accept them." Uh, very similar again to, like, how Git push/pull works.
Semantically also very similar in that regard. If you're trying to, like, with a Git client, if you have a local commit, and you push, and your colleague in the meanwhile has pushed some work, you need to, like, first reconcile that. You can do that-
Aaron Francis
Mm-hmm
Johannes Schickling
... through, like, a rebase or otherwise. Uh, in Livestore you do that through a rebase as well. But that sync backend, there, its only job is to, uh, accept those pull and push requests, and, um, the only nuance there is that the push request needs to enforce this total order. That basically means, like, if the p- last push was 100, and our client comes along and says, like, "Hey, please take event 50," then it says, "Uh-uh, I've already- I'm already at, uh, at 100.
You're probably out of date. Here, please pull all of, like, the newer stuff first."
Aaron Francis
Mm.
Johannes Schickling
Then it's always, like, in the same order. But that's really it.
Aaron Francis
Interesting.
Johannes Schickling
And so a sync backend is very, very simple, and you can put the, um, the... You, you basically just need to persist the event log. You can-
Aaron Francis
Mm-hmm
Johannes Schickling
... persist the event log. You can keep it all in memory. You can put it into a Postgres database. You can put it in-
Aaron Francis
Hmm
Johannes Schickling
... D1, Torso, and I think that's also attractive about this because-
Aaron Francis
That is pretty cool
Johannes Schickling
... it is conceptually so simple, and this is where you might also want to apply business logic that is specific to your app. So this can just become part of your normal, uh, app backend that y-
Aaron Francis
Mm-hmm
Johannes Schickling
... that might do other things.
Aaron Francis
Okay. Yeah. That's pretty cool. That is very simple. Um, so you really could run it anywhere, as long as you have a place to put the event log and hang on to it. So then-
Johannes Schickling
Right
Aaron Francis
... um, other clients out in the world, as a part of, as a part of what life cycle are they checking the sync server? So, like, at what cadence or what event, or how does that, like, phone home process work?
Johannes Schickling
Right. So, um, it kinda depends on which sync backend you're using and what the capabilities and constraints there are.
Aaron Francis
Mm-hmm.
Johannes Schickling
So a, a common sync provider that can be used with Livestore is, like, a Cloudflare Worker sync provider, and, uh, this is where we can use all the benefits of Cloudflare Workers with Durable Objects, which gives us-
Aaron Francis
Mm-hmm
Johannes Schickling
... WebSocket connections. So through its WebSocket connections, we have, like, that network, um, reactivity. That means if client A pushes something, client B doesn't need to, like, pull and, like, hope-
Aaron Francis
Hmm
Johannes Schickling
... that something has happened. But client B gets, uh, like, a message right away, so it knows, like, "Hey, something new has happened," and you get that real-time feedback loop. But if-
Aaron Francis
So in that case, the sync server receives an event, and then lets every WebSocket that's connected know it's just received-
Johannes Schickling
Right
Aaron Francis
... an event?
Johannes Schickling
So that is- ... like, a slightly smarter sync backend-
Aaron Francis
That is slightly smarter
Johannes Schickling
... that basically additionally to doing push/pull-
Aaron Francis
Yeah
Johannes Schickling
... it does, like, a poke.
Aaron Francis
Notify or something.
Johannes Schickling
Uh-
Aaron Francis
Yeah
Johannes Schickling
... so, um, the, the folks from Replit Corp., who previously built Replcache-
Aaron Francis
Mm-hmm
Johannes Schickling
... landed on a very similar architecture. And again, it's, like, very, very simple, and you can, depending on, uh, what hardware you're using, what sort of, like, network primitives, you can use certain things that are, for example, easy to operate, cheap to run, et cetera. So WebSockets are an amazing primitive for that.
But you could also very well just do HTTP polling or server-sent events.
Aaron Francis
Mm.
Johannes Schickling
You could do something very, very different. Um, I want to... I have, like, the, this little side quest where I want to use, um, just plain Git as a sync backend, where you'd basically just use-
Aaron Francis
Uh, cool
Johannes Schickling
... a, a Git repository as a sync backend, and, uh, your apps would collaborate on a Git repo, which would be kind of, like, meta, and I just wanted to-
Aaron Francis
That'd be so meta
Johannes Schickling
... like ... But it's, it's very simple.
Aaron Francis
That, that is super cool. Um, okay. This, this whole life cycle is making a lot of sense to me, and I, like I said earlier, I like the ability to reason about it simply. You can still build really complicated stuff, but you can reason about it very simply. That, that-
Johannes Schickling
That's exactly right
Aaron Francis
... makes me feel... Yeah, that makes me feel very warm and fuzzy. So as we're, as we're finishing up here, tell me the state of the project, um, right now, and your hopes and dreams for the future, and how people can help you, uh, s- see this come to fruition.
Johannes Schickling
Right. Before answering that, I just wanna say, like, this is, doesn't all come without trade-offs. So this is-
Aaron Francis
Okay
Johannes Schickling
... like, built for specific applications, and I don't want to say, "Hey, this is the best technology ever." There are trade-offs to this, and there are apps that this works well for, and there are apps-
Aaron Francis
Mm-hmm
Johannes Schickling
... use cases where it just doesn't make as much sense. We don't have much time to talk about that. I just don't want to be seen as sort of, like, ignorant and naive about this. This is, like, for specific, uh, application use cases, and I'd be happy to explore those, uh, with whoever's interested in it. But, uh, I just wanna make sure this, uh, this, this is well understood.
Um-
Aaron Francis
Jo- Johannes, you are, you are a man after my own heart. You are an exceeding reasonableist. I really- ... I very much appreciate that. Uh, nobody... Yeah, nobody thinks you're claiming to, uh, have invented the panacea, but it sounds like you have created something that is very useful for the use cases you're trying to solve. So I do appreciate that disclaimer. Um, so keep going.
Johannes Schickling
Th- thank you. And I, I'm, I'm modeling it ar- around my own use case, and I think that's the best way to, to build-
Aaron Francis
Perfect
Johannes Schickling
... something that, uh, that... Yeah. So, um, the, the state of the project, it's been in development at this point, yeah, since over four years really. It's had its first life through this Refl research project, and then over the last two years I've, like... That was, uh, the SQLite Reactive Foundation.
Aaron Francis
Mm-hmm.
Johannes Schickling
And now over the last two years, I've productionalized it further and added syncing on top. So, um, currently Livestore is in beta. Um, there is no concrete point in time yet where I would say, "This is 1.0." Um, it is probably, uh, probably another year away or so. I'm building a, uh, community of, uh, contributors and maintainers around it who are already starting to, to help me get there faster, since-
Aaron Francis
Mm
Johannes Schickling
... this is, like, a very, like, for example, just making sure that this works across those different platforms. And given that this is trying to tame distributed systems, uh, that- ... that's a really big effort, and it's probably one of, probably the most ambitious and complex system that I've ever, uh, tried to build and am building. So, uh-
Aaron Francis
That's so fun
Johannes Schickling
... the, this is, uh, this is not just your, your normal JavaScript, uh-
Aaron Francis
Mm-hmm
Johannes Schickling
... state management library. This, this is a more complex thing. And, uh, I'll probably be... I, I've full intent to keep working on that with the, with the next fi- within the next five years or so, maybe beyond that. Uh, it cer- I certainly have a roadmap for that keeps me busy for the next decade or so. Um-
Aaron Francis
Wow That's crazy.
Johannes Schickling
Um, it- one thing we haven't even talked about is, like, it has first-class dev tools, uh, which is a Chrome extension or, yeah, so, or like a Expo extension which allows you to look into it. So there, the scope is, is fairly, even though the, the core is simple, the scope of, like, what this thing can enable is, is fairly ambitious. So, um, yeah, but I've been working on that mostly full time next to working on Overtone over the, since the last four years.
And-
Aaron Francis
Geez
Johannes Schickling
... uh, my, my hope is that, uh, similar to how React has, uh, just completely changed, like-
Aaron Francis
Mm
Johannes Schickling
... how capable the web can be, I think there's, like, a similar, um, opportunity just to do the same thing for data for a specific kind of application. There's other folks who are building systems to address other use cases, and I'm trying to, uh, build a system for the kinda Overtone, Linear-esque, uh, use cases.
Aaron Francis
Mm-hmm.
Johannes Schickling
And, uh, that, that's what I'm trying to build. So, uh, if this technology sounds interesting to anyone, please give it a try. We have, uh, our cozy little Discord community-
Aaron Francis
Mm
Johannes Schickling
... where we help each other. Uh, we have a, a nice community of contributors. Uh, we're doing office hours regularly. And I'm also building this in a different way compared to Prisma, where we've raised VC money. I'm bootstrapping this thing, and I'm trying to make it a sustainable open source project-
Aaron Francis
Cool
Johannes Schickling
... which has its own challenges. So I'm leaning heavily into GitHub sponsorship. So far the project was, um, invite only for GitHub sponsors, but we're just crossing the boundary into open sourcing the project, so-
Aaron Francis
Awesome
Johannes Schickling
... I think this has happened at the point this episode comes out-
Aaron Francis
Mm-hmm
Johannes Schickling
... which I'm very excited about. And, uh, yeah, now it's a- available to, to everyone, and I hope that I find a sustainable path forward where this can be a great foundation for, for many apps.
Aaron Francis
Wow. Well, thank you for coming on and explaining all that. The, the stuff you're doing is amazing, and it's, uh, I, I will be very, uh, candid and say having a five- or 10-year roadmap for an open source project is pretty inspiring to think like, yeah, you're gonna stick, you're gonna stick with this for a long t- I mean, it's been a long time already, goodness. But to have that kind of, like, uh, dedication to it is, is very inspiring.
So for those of y'all listening, if you wanna join along, I will leave links to the projects and the repo, and, um, Johannes, if you can send me the link to the Discord, I'll leave that down in the description as well. Um, and a link of course to Johannes on X and everywhere else that I can, uh, find his stuff. So please, if this sounds interesting, reach out, uh, check out the repo, give him a sponsor, give him a star.
Um, sounds like very, very cool work, and we wanna support that, especially this open source stuff. So Johannes, anything else you wanna leave the people with before I wrap it?
Johannes Schickling
No, this was wonderful. Thank you so much. Yeah, and if this entire local-first thing speaks to, is interesting to, to anyone, uh, on the Local-First FM podcast, uh, I have-
Aaron Francis
Mm
Johannes Schickling
... a whole bunch of really interesting guests from the founder of Linear to the folks who built Dropbox to people building whole new operating systems around local-first. So that's a particular niche, uh, that I feel very, um, very at home. And if that sounds-
Aaron Francis
Mm-hmm
Johannes Schickling
... interesting to you, that's maybe also worthwhile checking out.
Aaron Francis
Yes. Good, good idea. I will leave a link to that as well. And, uh, I imagine the people that are interested in this type of show are interested in Local-First FM, so yeah, y'all head over and check out Johannes' podcast as well. Um, and, uh, my, my request for the people is if you have people that would be good on this show, please let me know.
If you have friends or you yourself would be good on this show, if you're actually building something like Johannes here, uh, that's who I wanna talk to, people who are building things in and around the data space. So please, if you know of someone or are someone, uh, reach out. And if you're listening on audio, we do have YouTube, and if you're watching on YouTube, we do have audio, and we'll leave links to all of that down below.
Um, thank you all for tuning in to the nerdiest podcast in the world. It is an absolute delight for me to do that, and so thank you for listening. Um, and again, please go check out all of Johannes' stuff. And until the next time, we'll talk to you soon. See ya.