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