23:06So I'd be curious to learn a little bit
more about the challenges that you were
23:10facing building Replicache and building
Reflect as it relates to the challenges
23:16you've mentioned before in regards to
storage and other challenges we might not
23:20have talked about yet when it comes to
building such a technology for the web.
23:24Yeah.
23:26there's a lot of little things
that you discover when you set
23:29out to do something new like this.
23:31And a lot of times, you know, in
software engineering You know, a lot
23:34of the work comes from like unexpected
places, you know, it's not the
23:37algorithm, it's not the core algorithms
or the data structures or whatever.
23:39It's like dealing with the practicalities.
23:42Like one thing that is really a
quirk of the web that is another one
23:45of the web superpowers, but really
makes this challenging is tabs.
23:49Like, the web has tabs and tabs from
like a platform software developed,
23:54like a software engineering perspective
are weird because they are different
23:57execution environments, right?
23:58It's as if.
24:00You have an application, but it
has like, it has many different,
24:03like, places where code can run.
24:05Many, like, it's as if you had
a bunch of different processes.
24:07They're not, tabs aren't really different
processes, but like, from a software
24:10engineering perspective, they're kind
of like processes because they're
24:12different execution environments that
can have different code in them, right?
24:15Like, you could have different
versions of your app with different
24:18code bases running in each tab.
24:19Like, if the server updated
and and one tab updated, but
24:23the other didn't, you know?
24:24But they share storage.
24:26So that is a weird thing.
24:28Usually when platforms have a situation
like that, where you have processes
24:31or threads, they also have locks
so that you can like protect the
24:34storage and coordinate access to it.
24:36But the web has kind of has like
a fledgling web locks API, but
24:40it is very unused and tested.
24:42And there's a lot of edge cases in it.
24:43And we don't really trust it.
24:45Like our company doesn't use it and
trust it because we investigated
24:48a bunch of these edge cases and
they're sort of like underspecified.
24:52I don't believe that they're
consistently implemented across browsers.
24:56And we've even had people like on browser
teams like recommend that we don't use it.
24:59You have to figure out a way to
deal with the fact that You have
25:02this persistent storage, right?
25:04And one tab can update and the
other tab cannot be updated.
25:07And then what happens?
25:09Right?
25:09And There's always a problem
with these kind of systems of
25:12like schema migrations, right?
25:13You have to figure out schema migrations,
but it's harder on the web because you
25:17have schema migration on the server
You have schema migration on the client
25:20But then you have the problem that one
tab can update and like want to migrate
25:24the schema forward to like the version
of the Storage that it wants, but the
25:28other tab is like still back on the old
version, you know, like what does it do?
25:31So these are just like
fun practical problems.
25:34So I would actually love to learn a
little bit more about either of those.
25:38And so are those challenges that you've
been facing and that you can fully take
25:44care of on behalf of an application
developer, are you able to like go some
25:49way, but still leave some of the hard.
25:52trade offs to an application developer
and there's some path, some like bad
25:57or even worse trade offs someone needs
to make as an application developer,
26:01they ultimately have to choose.
26:04So how we're able to work around those?
26:06My view is that in order for storage
to be widely used on the web, it
26:11has to be as easy as, easier than
like building a normal web app.
26:16It has to be easier than
building today's web app, right?
26:18And I think that we can get there and
the and the people who need to fill that
26:22gap, who need to make it easier than
today's web apps are library developers.
26:26Like, it's not gonna be browser
vendors because they move way too slow.
26:29Like, it's gonna be library developers
because we have this , awesome
26:32ecosystem of people furiously tr trying
different things to figure this out.
26:37So we have completely solved the cross
tab thing, and I think our solution
26:40to it is, I'm really proud of it.
26:42Like we put a lot of work into it.
26:44It's for this like tiny moment when your
app is updating we put this massive amount
26:47of effort into this, like 10 seconds
at worst when your app is updating and
26:52like two tabs have different versions
but we made it really like elegant.
26:56And like, you don't
have to think about it.
26:58Like basically what happens is
as a developer constructor for
27:03Replicache, you specify the version
of the database that you want.
27:06And that's an identifier that you choose.
27:08So you say like, I want version
seven and you can create as many
27:11different schema versions as you want
in Replicache, and they'll each be
27:14isolated from each other, fully isolated.
27:16And when we talk to the server, we
send in the request the version of the
27:21schema that we're asking on behalf of.
27:23So the server has to respond with
that version or say, I can't serve
27:26that version, you need to reload.
27:27But then internally to deal with that
moment when tabs are on different schema
27:32versions, we actually fork the database
and we have both running at the same time.
27:37So typically in Replicache,
the storage is shared, right?
27:41So you make changes in one tab and
you see them instantly in the other
27:44tab whether you're online or not.
27:45But for this moment, when a schema
update is happening, they fork.
27:48So the tabs can continue independently
and they can continue working.
27:51You know, a concern is like, if you're
typing in a, in an input, you don't
27:54want to just reload the app at that
moment to get the new code, right?
27:56The user could lose their work
or just be frustrated, right?
27:59So you want, you need to allow
the app to continue running for a
28:02little while until it thinks that
it's the right time to update.
28:06That sounds incredible.
28:07And that sounds like
an absolute nightmare.
28:09If like I, as an application developer,
it's hard enough to ship the app
28:15version that I have, and then to even
like really think about that there
28:19is this point of time where a user
has the old version up and running.
28:23And to then just like throw multiple
tabs into the mix here as well.
28:28So, I think whatever pain you
can take away from my application
28:32developer here is amazing.
28:34So yeah you've been mentioning the various
app schema versions and that does at
28:39least locally speaking forks the database.
28:42And I suppose then there's some mechanism
how the forks are eventually being.
28:48joined or merged again, or how if the
different tabs are still being used,
28:55how did those forks come together again?
28:57Well, what happens is they're both
still talking to the same server, right?
29:01So the they're local storage
forks but they're still talking
29:04to a shared truth on the server.
29:06And the server and when tab a makes a
request to the server, it says like,
29:10hi, I, I want to talk and I'm talking
schema version seven and when tab
29:15B sends a request to the server, he
says, I'm talking version eight and
29:18the server can choose to speak both
versions if it wants, or it can choose
29:22to tell seven, I can't talk to you.
29:23I only know version eight but
that doesn't mean that tab seven
29:26has to reload at that moment.
29:27Tab seven can continue working
without a server connection, right?
29:30Because it's local first.
29:32And then it can decide to
reload when it's ready.
29:34Let's say we have tab a and tab
B and they're happily working
29:39in the same version right now.
29:41Is there some communication mechanism
between those two tabs that that
29:45doesn't rely on the server alone?
29:48Yeah, under normal circumstances,
the storage is shared.
29:51So you make changes in tab.
29:53If you're off totally offline
with Replicache or reflect,
29:56and you make changes in tab
a, you will see them in tab B.
29:58They share storage, right?
30:00It's just at this moment when an
upgrade happens, they fork momentarily.
30:04Just to maintain like integrity of the
system, like, so that you don't have.
30:09The schema changing
underneath one of the tabs.
30:11And, you know, that is like a little bit
of a rough edge in the like, abstraction.
30:17You know?
30:18But, under normal circumstances, you're
never going to notice this as a developer.
30:22And it's like, the cleanest
solution that we could come up with.
30:24I agree.
30:25I think it's not like that you're
rolling out a new release constantly.
30:29I think the, still the majority
of the time where the app is being
30:32used, that you're not upgrading.
30:35And so for that little period of
time to have a simpler solution to
30:39this very gnarly problem, sounds
like a very good move to me.
30:44So in the case where it's not
currently upgrading, you mentioned
30:47that those two different tabs.
30:50Share storage.
30:51Does that mean they share the same
IndexedDB database or is there even more
30:56sharing, such as like sharing an array
buffer between those tabs, or what is
31:01the communication mechanism between those?
31:03Are you listening to changes in
IndexedDB, is there sort of like
31:08a broadcast channel between those?
31:10How does the tap interplay work?
31:13I'm so glad you're asking these questions.
31:14Like, I don't know if our listeners
will care about these details.
31:17I hope they do.
31:18Because this is like,
the fun part, you know?
31:20But Yeah, this gets to another one of
the practical challenges that I am proud
31:23of in our implementation that I, that
we put a lot of work into, which is
31:26like we, it was very important to us.
31:29And I know important to you too.
31:30And a lot of other people in this space
that you have 60 frames per second
31:33interactivity, like at, you know, that we
want people to be able to use Replicache
31:38as if it's memory, you know, as if it's
your, as if it's your state model, like
31:42one of the benefits that should come
out of adopting these tools is that you
31:44don't need complex state management
libraries, you know, you have this like
31:48database locally You should be able to
use that as your as your state but when
31:52you look at that from like again from
like an engineering perspective, it's
31:55actually not so easy because You know
storage local storage on SSD is fast.
32:01Sure You know SQLite is fast IDB is
not fast, but you can like wrap it and
32:06do things to it to make it fast but
it's nowhere near as fast as memory.
32:09It's not 60 frames per second.
32:10It's an order of magnitude slower, right?
32:12So, so how do you bridge that gap, right?
32:15And if you want to have cross tab
consistency, if part of the product design
32:19is that you make changes in tab A and
they reflect in tab B, then you cannot
32:24use storage alone as your communication
mechanism because it's too slow, right?
32:28So you have to have memory inside the
tabs at some level, you have to have
32:31memory like that has the state in the
tabs because that's the only way it can
32:34be fast enough and then you again have a
synchronization problem like a distributed
32:38system problem between the tabs, right?
32:40They're changing independently.
32:41So how do you resolve that?
32:43There's like different, I think there's
different legitimate ways to address
32:45this, but the way that we do it, which
is that we basically, we use the storage
32:49as like, We, we run in memory, Replicache
runs in memory, like in the JavaScript
32:53thread, in the main thread, right?
32:55So it's right there next to your app.
32:57It's crazy fast and it lazily
loads and stores to IDB.
33:02And we have a, basically a
synchronization protocol between the
33:04tabs which you can kind of think
of it roughly as like two Replicache
33:09browsers, like sync via the server
and two Replicache tabs sync by IDB.
33:13That's like the basic structure.
33:15And yes, we need to have a way to know
when something has changed cross tabs.
33:18And for that, we use broadcast channel.
33:21But like, you know, it's the same
if you're familiar at all with
33:23Replicache, the server doesn't
send data proactively to the client.
33:27The server only sends a poke
that like a tap on the shoulder
33:30that something has changed and
the client requests the changes.
33:33And we kind of do the
same thing cross tab.
33:35Like we, we use broadcast channel to
tell the other tab, Hey, IDB has changed.
33:39And then.
33:40That tab is like running as fast
as it can in memory and it has like
33:43a background process to refresh
itself from storage periodically.
33:47I'm very curious to learn more about
that background process as well.
33:52Are you leveraging workers at all in
your implementation here, or is this
33:57mostly running in the main thread?
33:59And this is where given that you
have multiple tabs, multiple main
34:02threads is most of Replicache
running in the main threads.
34:06We don't use workers as part
of the implementation of
34:09Replicache Currently at all.
34:11you know, we, We want people to be able
to use Replicache as if it's memory,
34:15it should be as fast as memory and, the
only way to do that is to be memory, you
34:19know, you could have something running
in another thread, in another worker,
34:22but then you're still gonna have to have
state and memory, right, so, What we
34:26landed on was, we have Replicache as a
in, like an in memory main thread thing.
34:33It has a background process that syncs
with IDB, but that is just like a periodic
34:37task that's running on the main thread.
34:39You can easily run Replicache
in a worker, and many people do.
34:42People, like, people do
this to do full text search.
34:45They run Replicache in another tab, they
do, you know, indexing in that, or they
34:50run it in a worker, they do indexing
in that worker, and then they, like,
34:52access that index from the main thread.
34:54And because of the cross tab communication
that we have, it works fine across workers
34:58too, workers in the main thread, you know,
but where to put workers in your stack is
35:03like a, is a, is an application developer
question not a Replicache question
35:09I think it's very possible that
we would implement workers.
35:11We would add workers to various parts
of the implementation of Replicache,
35:15like as an implementation detail, you
know, like there's some background
35:18tasks that we need to do, like cleaning
up things, you know, that are heavy.
35:21And it would be useful to have those
on a background thread to make sure
35:24they don't interfere with the UI.
35:27The one thing that like people
frequently ask, and it has come up over,
35:31over the development of Replicache,
whether to use service workers.
35:35and because it, it seems so tempting.
35:39It's like this shared place that you
can run code, you know, across tabs.
35:42But man, service workers are like
another part of the web platform.
35:45That's just so hard to use.
35:46You know, it's just so gnarly,
and I feel like almost nobody
35:49knows how to use them, you know?
35:51And like, there's so few examples
of them being used successfully.
35:54And if we use service workers in
Replicache, it would have impact
35:57on how people build their apps.
35:58So we just haven't gone there.
36:00Once you're just a little library that
you use in your JavaScript app, then
36:05I think that keeps things way simpler
since I think very few JavaScript
36:09developers are even aware of the
concept of a thread in the context
36:14of building like their React app.
36:16And so a worker is a thread, but once
you have a library or technology,
36:20that spans, the main thread that spans
workers or service workers, then you
36:25need to conceptually deal with that.
36:27But it also becomes a tooling
and a bundling problem.
36:31So this is where I think the best
technology that we have for those sorts
36:35of patterns right now would be Vite
36:38and my opinion
36:39so have you had success or not so much
success with certain technologies?
36:45We love Vite it's like my default.
36:48It's kind of a funny story, like, when
I started RociCorp which was, like I
36:52said now, almost four years ago I wasn't
up to date with like the web, like,
36:56and like the popular open source tools.
36:59And my friend was like,
you gotta check out Next.
37:02js, it's like, so awesome,
like, you guys should figure
37:05out how to integrate with Next.
37:05js, and like, I started, like, working
with it, and I was like, oh, this is
37:08like a really cool DX, but like, I'm
trying to, like, what is it, like,
37:11what's the core value here, I couldn't
put my finger on it, like, it's like,
37:14it's hosting, like, there's the the
thing where you have deploys that are
37:18like, like, preview deploys, that's
really cool, but like, is that, I'm
37:20trying to think, like, why is this so
exciting, and I finally realized, it's
37:24like, the easiest way to set up React.
37:26That's really like the back then, like
that's the core of it, you know, that's
37:29how like it's like setting up a react
project is just so hard, like, and then
37:34I, you know, I think V has taken the
has taken the crown on that front now,
37:39Yeah, I think, so my take is that if
you're using Next and typically you
37:43then deploy it on Vercel, I think that's
great for like anything that's like
37:48a more on the, if there's a spectrum
from website to web app, then I think
37:53this is rather where you start on the
website spectrum and make it more,
37:57add more and more app like features.
38:00But I think it becomes increasingly
hard if you want to build a
38:04local first app with Next.
38:06js as you want to introduce those
capabilities, as you want to introduce
38:10really deep storage mechanisms or
once you want to work with workers.
38:14I'm sure it's on their roadmap somewhere.
38:17But I think they, they've just started
their journey on one side of the spectrum,
38:21which is, I think, rather to the websites.
38:24And that's great and
that works really well.
38:26Server side rendering, React server
components is great for this use case.
38:31But I think once you want to build web
apps that really feel more, almost like a
38:37native app, I think this is where you need
to reach for a different tooling stack.
38:41And I'm currently very happy with
Vite as it has support for workers
38:46as a first class citizen, was a
bit rough over the last few years.
38:49But it has gotten a lot better with every
release and I'm very happy using it.
38:55And I've even seen a few libraries
also shipping workers out of the
38:59box that work quite well with Vite
39:02so an example here would
be the SQLite WASM built.
39:05That also ships with some workers out
of the box, which works pretty well,
39:11yeah we use it often and like it as well.
39:14I don't have as much experience
with workers in particular just
39:17because we haven't taken it on as
like an implementation detail yet.
39:20But yeah, just overall we have a lot of
success with using it for our samples.
39:24And like, you know, when you're
building this kind of stuff, you end
39:26up making apps all the time, right?
39:28So speaking of maybe
this is a good segue to.
39:32How I would use Replicache or reflect
in, in my, let's say in my React app.
39:39So I think you've been mentioning MobX.
39:42Is that a typical technology that you
use Replicache with, or does Replicache
39:48completely replace something like MobX?
39:51MobX, Redux, Zustand, all those all
those sort of state technologies.
39:56Are they complimentary or are they
rather being replaced by Replicache?
40:02I think long, like long term they're
being replaced but the reality is
40:06that Replicache isn't there yet.
40:07Like these are, you know, very well
developed, like sophisticated tools,
40:11you know, like that people have,
Developed, like to do legitimately
40:15hard things, you know, like, you have
a fairly large data set in memory and
40:19you're trying to update like little
bits of it reactively, you know, that's
40:21like a legitimately hard problem.
40:23And so Replicache has an API like A
subscription, API that's memory fast.
40:28And I think it actually competes
well with like SQ lite based systems.
40:32In many cases it's faster.
40:34But.
40:35I mean, if you're building something
like Dax is building, you know, that
40:38has like a lot of data in it like 30,
000, 50, 000 records, you know, and,
40:43you know, you're trying to do 60 frames
per second updates in there, and you
40:46have a lot of, like, computation, like,
derived computation chains in memory,
40:50like, we don't have the, we don't have
the APIs in Replicache yet that, that can
40:54compete with, like, MobX or, like, Signia
from TLDraw, like, things like that.
41:00And the cool thing is like, the
design of Replicache is complementary
41:03to putting those things on top.
41:04Like at the bottom of the Replicache
abstraction stack, you have a
41:07key value store that's reactive.
41:09You know, so you can like plug those
reactive changes, like, into your into
41:12Zustand or whatever, and it'll work great.
41:15It's interesting, like, different people
in the space started at different angles.
41:18Like, I think that's something
you've been passionate about,
41:19like, from the very beginning.
41:21There's so many exciting things
happening in local first.
41:23Like, other people have
started focusing there.
41:25We started, like, a lot more on making
the synchronization correct and robust.
41:29And making partial sync
work, authorized sync work.
41:31You know, making the mass
storage, like, really fast.
41:34And we still have to like finish up
the libraries legitimately, like the
41:37API layer to make it really nice.
41:39I think that it's going to be competitive
with like using those types of
41:42tools, like, you know, next quarter.
41:43Yeah.
41:44I mean, Replicache has been, I think,
one of the first solutions really been
41:49on the local first market in that way.
41:53And so, and I think you, you have
been quite ahead there in terms of
41:57the work on syncing and just having a.
42:01A fully fledged thing out there that
developers can use to build on top of and
42:06that shows I think most most of the local
first apps that have been built over the
42:11past one or two years, I think, use your
technology and I think that's already.
42:16driving some of the change that
I want to see for our apps.
42:20So are there some apps that that
you're particularly excited about,
42:25where you say, okay, this is
exactly what I wanted to help create
42:29more of or help create more of?
42:31Well, I mean, right now the
one that, that I'm like most
42:34excited about probably is sst.
42:36dev, Dax's thing that I've
mentioned a few times.
42:39Like just because, I don't
know it's an example of like a
42:43data intensive application that
is like public that you can try.
42:46A lot of our, a lot of our customers
are like, you know, they're private
42:49things that, you know, not easy
for people to access outside.
42:52And yeah, we have a lot of.
42:56Customers using Replicache for things
that are like in the building industry
42:59or like service industry where like,
like we have a customer that is building
43:03like a tool that people who build
houses like would use and, you know,
43:08they go out in the field and there's
intermittent connectivity and, you
43:11know, actually like building a house
is like a super data intensive thing.
43:15You know, there's like
thousands of elements on the
43:17checklist to a house, you know?
43:19And like lots of people that have to
come through and look at it and then
43:21there's back office things that happen
and like, so it's like a perfect use
43:24case, but it's not something that you
can like use, you know, that you could
43:28go try and use right now because,
you know, it's a private system.
43:31So yeah, I think like sst.
43:32dev is like the best example
right now that I'm excited about.
43:36I'm equally excited about the things that
I can use myself, as well as the anecdotes
43:41I'm hearing about other technologies
being created for other people.
43:46So I think this is what I'm particularly
excited about Local First, that it
43:52makes it easier to build technologies
for use cases that were just not that
43:58Viable before to, to build technologies
with the tools that we had before.
44:02So what you've been sharing about
the construction use case here, or
44:07you've been also privately sharing
a few other use cases with me,
44:10those sounds, sound incredible.
44:12And this is exactly why I'm
excited that local first opens