18:34Yeah.
18:34And again, I like anchoring
this in , how did we get here?
18:37We've been downloading
data for a long time.
18:38You can get a CSV file off the Internet.
18:40You can email somebody
in Excel file, right?
18:43We kind of get that,
like, then you have it.
18:45You know, I can email you an
Excel file and then you can
18:48open it like no big deal, right?
18:50That seems easy.
18:51Similarly, like with my with my
story about the music app, you know,
18:57I could download those playlists
and just cash them on the device.
19:01And so that's like a kind
of a modest thing you were
19:03saying, just cache everything.
19:04Cool.
19:05Okay.
19:05As long as all you're doing
is reading, no big deal.
19:09That's fine.
19:10Right?
19:10That just works.
19:11Cool.
19:11We'll cache everything.
19:12The problem is that we also still want
to be able to work when we're offline.
19:17Right?
19:18one our tenants is you should never, ever
be stopped from doing what you want to do.
19:24By the availability or lack of
availability of another computer.
19:28And I would say this is maybe also
where you can draw a line between.
19:32Current, not yet local-first software
that's not entirely useless in an
19:36offline scenario if it caches things
a lot, so at least I can read it.
19:41But to go from there to that,
it allows you to still do
19:45the job completely offline.
19:47I think this is sort of like a barrier
that is incredibly hard to overcome with
19:52like your more like typical three tier app
19:55optimistic,
19:56of caching.
19:57yeah, exactly.
19:58And it's not only that, but, like, it's
just complicated to think about, right?
20:02Like, there's a lot of subtle problems.
20:04Oh, if you know, you click the
OK and then it goes green right
20:07away, but really you're running
the fetch in the back end and
20:11have an
20:11post request failed.
20:13now we've already told
the user that it works.
20:16Okay, now we need to
like raise an exception.
20:19Let's make sure that we
check if we're online first.
20:21Oh, but the browser
thought we were online.
20:23But now it's just, it's a
nightmare as let's not do
20:26I've seen many times that basically like
shows you indicates, Oh, this was great.
20:31And then you see like a little spinner,
a pop up, something has gone wrong.
20:36Please reload the
20:37Refresh the browser.
20:38You've lost all your work.
20:39One of my all time least favorite
messages is on Google Docs.
20:44Sometimes if you work on a document,
like while you're on a flight,
20:47even though you've downloaded it,
remember to add the extension, cached
20:51it before you got on the plane so
that it would be available offline.
20:55And then you edit the document on
the flight and then you land and
20:57you come online and it says, we're
sorry, this document has changed
21:01too much while you were offline.
21:04We're now resetting you to the cloud
state and then all your data is gone.
21:10That's only happened to me once
or twice, but man, that hurt.
21:14What we do is we can, you know, if
it's just you working again, there's
21:19not really any problem here, right?
21:20Like I can edit the data.
21:22And then just when I come
online, we upload it.
21:24The real challenge is if you have
two different things, editing
21:27the data, and then you need
to merge their changes, right?
21:30So like I added a track to the playlist.
21:34And, you know, Spotify added
a track to the playlist.
21:38Okay now we have a conflict.
21:40Conflict is the technical
term we're going to use here.
21:42And so that's the hard thing.
21:43And lots of different systems
have approached this in different
21:46ways over the years, right?
21:47Like, Git gives you the ability
to merge conflicts as long as you
21:51don't have edits to the same file
or the same line in the file, right?
21:57CouchDB and PouchDB, you know, they
use what's called last writer wins.
22:01And so it's whichever.
22:03The, you know, all the systems agree
that whichever the last one was will
22:06overwrite now, which one was last.
22:09Okay, now we start to get into,
like, interesting distributed
22:11systems questions because you can't
trust the clocks on the computers.
22:15So, is it the last 1 to the server?
22:18Does there have to be a
central server that decides?
22:20Can we get rid of that
central server, Johannes?
22:22Can we?
22:23spoiler!
22:24Yes, we can!
22:25Sort of.
22:26Sort of.
22:26We'll come back to that later.
22:28That makes sense.
22:29If the software runs on our devices
and if the data is also in our devices,
22:34now the server is kind of demoted in
a way no longer necessarily has to
22:40play that absolutely central role.
22:43If something goes wrong, the client
can just forget everything and get
22:46everything again from the server.
22:48But that's exactly the step where we
want to go beyond to have the work that
22:52we do and the clients to actually trust
that and then collaborate with others.
22:58that's right.
22:58And I think the beauty of this model,
and we talked earlier about wanting
23:01to make software simpler, right?
23:03A lot of the complexity of the model
that we have today comes from having all
23:07these different systems and programming
languages and Like different computers
23:12involved in literally every task, right?
23:15Like if I tick a box in a standard
web app, I've got my computer, which
23:20then sends a request to the API
server, which then does a right to
23:23the database, which then needs to
propagate that back to my computer.
23:26So like, like best case theoretical.
23:29We've got three systems involved.
23:31Practically, though, there's also like
API gateways and like, you know, request
23:36routers and like all this other stuff
is happening along the way, PG proxy
23:40bouncer connection bouncers and all
this like extra hidden complexity on top
23:45of the sort of notional three servers.
23:48Whereas if you can move that so
that you know, yeah, you tick
23:51the box and it writes it locally.
23:54That's it.
23:54You're done right now.
23:56The problem is, well, how do I let
other people know that I took the box?
23:59And so what we're trying to do is set up.
24:00We call this synchronization, right?
24:02So we want to synchronize the state
that you have in your local device
24:06to other computers, whether that
servers in the cloud or other people
24:09who you're collaborating with.
24:10And so what we're doing is we're kind of
changing the relationship where instead
24:14of the server mediating what's happening.
24:18Right.
24:18The client decides what it's doing,
and then it lets the server know,
24:21like, Hey, I made this change.
24:22And, you know, we can
do that incrementally.
24:25And in fact, what we can do is record
all the edits that are happening on your
24:28local machine and then just basically
send a log of that to the server.
24:32And then similarly, the server
can send you a log of any other
24:36edits that other people have made.
24:38And now you have, in some sense,
a much simpler problem, which is
24:40just like, okay, well, I've got all
these different sort of changes.
24:43We have a change log, basically.