0:07:55 Yeah, that happens all the time.
0:07:57 I think that's one of the reasons
why it took off, is because it's very
0:07:59 pragmatic, for the slop that most
people are working with every day.
0:08:04 Whether that's your own slop,
hopefully you've been in your job
0:08:08 long enough to have to deal with your
own slop, or it's slop from before,
0:08:13 or you're just moving so fast that.
0:08:15 That's just what it is.
0:08:16 But, but the reality is that, you
know, things are just messy, when
0:08:21 you're shipping real products to
real people as fast as possible.
0:08:24 and I built React Query 'cause I needed a
way to make the experience better for, for
0:08:31 developers and users without needing to
get in the middle of the entire process.
0:08:38 like Meteor was trying to do,
or like GraphQL was trying to do
0:08:42 or Apollo, you know, I needed as
little buy-in as possible with
0:08:46 the maximum amount of, effect.
0:08:48 And, that's what it came to be
and I think it's very natural.
0:08:53 when you start playing with Query,
you start to realize that it is
0:08:58 in a way, a sync engine, right?
0:09:00 You have defined these declarative.
0:09:03 subscriptions to your data,
it's very manual, right?
0:09:08 Very, course brain manual timings
of like, how often do I want
0:09:12 to go and get this thing right?
0:09:14 So it's in the middle of like a
one-off, API call and a sync engine.
0:09:19 but it is living and breathing
and, the life cycle of that life
0:09:26 in this, Query cycle still takes
some effort from users, you know?
0:09:30 So when you change something, you
need to let Query know, that you've
0:09:35 changed something at the very least.
0:09:37 And we call that this invalidation, right?
0:09:39 And this is kind of like the bare
minimum for What I would call
0:09:44 probably the worst sync engine you
could want is just like, I've changed
0:09:49 something, invalidate everything
and just re-sync everything, right?
0:09:53 It's, it's very manual.
0:09:54 You are the one deciding when to re-sync.
0:09:57 And it turns out that a lot
of developers just weren't
0:09:59 doing that in the first place.
0:10:01 so it's crazy to think that just teaching,
giving people a good tool, like Query
0:10:07 and then telling them, Hey, when you
change something, you need to just
0:10:10 mark everything as dirty and re-sync.
0:10:14 It.
0:10:14 Just, that has improved
everybody's apps a ton.
0:10:20 And user apps, you know, it's
like, oh, data is up to date.
0:10:24 You know, it's not super efficient, it's
not automatic or whatever, but it is.
0:10:28 so I think that's, the bare minimum,
and that's the reality where a lot
0:10:31 of developers are today is they're
probably still coming, they may even
0:10:37 be coming from .net or, you know, some
monolithic backend shop into front
0:10:44 end, and they've never done any front
end syncing, data syncing at all.
0:10:49 And they might just think, well, I'm just
gonna call my API and display the data.
0:10:52 Right?
0:10:53 So I think that that's the
reality for most developers.
0:10:57 Most, successful companies are not running
the latest and greatest, and many of
0:11:02 them probably don't even know, you know,
the first thing about designing a sync
0:11:06 engine, I barely know anything about them.
0:11:09 So I, I wouldn't expect many, you
know, many of your run of the mill
0:11:13 developers to know a lot about it either.
0:11:15 So, but I think that's the first step.
0:11:18 And I, I think personally that once
you taste that, it's addicting.
0:11:22 You want more of that and you
naturally start to say, okay,
0:11:26 how can I make this faster?
0:11:27 Right?
0:11:27 And that's on the read's end, which
is kind of like the bare minimum.
0:11:30 It's like, I wanna read my data
and make sure it's up to date.
0:11:34 And then you start thinking about the
writes and you're like, oh, well you know
0:11:36 what would be cool is if when I click
this button it just showed that it's done,
0:11:42 even though we know it takes, you know,
a hot second for it to go and be done.
0:11:47 And then to resync all the
data, it'd be cool if it was
0:11:50 just looked like it was done.
0:11:52 And so we call that an
optimistic update, right?
0:11:55 Like optimistic, data manipulation
and Query has that built in.
0:11:59 Again, it's very manual.
0:12:01 you have to manipulate the cache that's
in your browser, in the Query client
0:12:07 to represent that new state manually.
0:12:10 and you fire off the mutation
or, the change that's going
0:12:13 to result in that state.
0:12:14 And then you just kind
of cross your fingers.
0:12:16 That when you invalidate your
data, when it's done and that new
0:12:19 data comes in, it matches what
you optimistically put in there.
0:12:23 Again, this is like from my perspective,
if you can implement optimistic
0:12:29 mutations with something like Query,
you're already so much further ahead
0:12:33 than what the standard has been
for a very, very, very long time.
0:12:38 but like I said, it's very addicting.
0:12:41 So then after that, you know,
you start to think, okay, this
0:12:45 mutation thing that I'm doing, these
optimistic updates, those are tedious.
0:12:50 You know, it's like, well, I have to,
I have to make those perform, like make
0:12:54 those optimizations myself and manipulate
the cache and it feels dirty, right?
0:12:59 And so that's when it starts to get
a little more intense with like,
0:13:03 okay, how could we make it so that
when I say I clicked this button.
0:13:10 I should like this post somewhere that
I don't have to go in and manually
0:13:16 kind of do the optimistic update that
my mutation can just know what it's
0:13:23 going to affect, make the update, send
it to wherever it needs to go, and
0:13:29 then it will sync when it needs to.
0:13:31 And then we can just carry on, not
just as like a user interface to click
0:13:35 something and be able to carry on
immediately, but also as a developer
0:13:39 to be able to say, this is what's
changing, and then just move on.
0:13:43 You know, not have to worry about
optimistic updates and cache
0:13:47 and validations and whatnot.
0:13:48 So this is where I think, at least for
me, where things start to get really,
0:13:54 really fun and really, really scary.
0:13:56 Mostly because it's just,
it's a new space, right?
0:14:01 And, you know, to, give you my
perspective on it, I haven't gone
0:14:05 too far down that rabbit hole to
be honest, because it involves a
0:14:10 lot of knowledge about a system.
0:14:12 usually involves knowing about schema
or, creating schema in some way.
0:14:18 there's different implications for where
that data is being synced, whether it's
0:14:23 local like offline or on a server or
through web sockets or REST or whatever.
0:14:28 so there's just a lot that comes with
that and that has been intimidating
0:14:33 for me because it's difficult for
me to generalize where like, React
0:14:37 Query was easy to generalize.
0:14:39 but it doesn't mean that
we're not thinking about it.
0:14:42 You know?
0:14:43 this was a, perfect tour from the
beginnings of the motivations that led
0:14:48 to React Query and now TanStack Query,
the benefit it provides and like how
0:14:53 far it gets you, but also like to the
point where it brings you where things
0:14:56 are already working pretty well, but
maybe you face some new challenges
0:15:01 and you would like things to work even
more automatically in the right way.
0:15:06 You now need to better understand that.
0:15:09 And this is also like nicely reflects,
like a lot of my thinking over the
0:15:13 last decade where I've been wrestling
with the same ideas and the same
0:15:18 challenges and a few points always like
bubbled up to me again as like those
0:15:24 can't be ignored in a generalized way.
0:15:27 And I think this is really the, key
point to underscore here, like looking
0:15:31 for a generalized solution and like at
least I don't want to be the bearer of
0:15:35 bad news, but I don't think for data
there is a generalizable solution because
0:15:40 data is like the ultimate as it depends.
0:15:44 And I think this is where a
technology like React as like
0:15:48 the first of its kind in a way.
0:15:50 showed us a, like close to generalizable
solution that applied so perfectly
0:15:57 to so many different situations and
use cases, and unfortunately I don't
0:16:02 think that is realistic for data.
0:16:04 Just because for data you have
just different trade-offs.
0:16:08 Let's say you're building a banking
app, this is where you really want to be
0:16:12 certain has that wire gone out or not.
0:16:15 But if you're building, let's say, a
note taking app, it is actually more
0:16:19 important that you can just carry
on writing down your thoughts, then
0:16:24 that you perfectly know that it's
also already arrived on the server.
0:16:29 And so it's just different trade-offs
and those different trade-offs
0:16:33 need or could be productized
and systematized into something.
0:16:38 And this again, is where I think React
Query has been just so phenomenal in
0:16:44 striking those trade-offs it meets
people, where most of them are, where
0:16:49 they don't need the perfect thing.
0:16:51 Something good is already
better than nothing.
0:16:54 And then just like calling,
fetch themselves and then,
0:16:58 dealing with that somehow.
0:17:00 But for people who wanna now go
further for a more specialized path,
0:17:05 I think this is where now there's like
a, tree of potential new approaches
0:17:10 and potential new technologies.
0:17:11 And some of them you've
been investigating.
0:17:14 And I think, one particular like hairy
topic here to investigate further is
0:17:19 like, how do you get for the writes
that you're doing for the optimistic
0:17:24 updates or the updates more generally.
0:17:26 What happens when you're updating
data, like most directly, you're
0:17:31 updating data in like a local variable
somewhere, somehow running in your,
0:17:37 let's say, React app, but then you're
also maybe posting to an API endpoint,
0:17:43 and now it's already, the universes
are already potentially splitting.
0:17:48 So you've updated your variable,
maybe your API request.
0:17:52 Goes through.
0:17:53 And as that API request is
being propagated further, fail
0:17:58 somewhere there and now you
need to unwind the entire thing.
0:18:01 But let's say maybe you do two
API requests, one goes through
0:18:04 the other, doesn't go through.
0:18:06 Now you're like in the
split brain situation.
0:18:09 And so now you need to, should you wind it
back, should you partially wind it back?
0:18:14 And now you need to handle that on your
API server as well as on your client.
0:18:19 And on the client, maybe you just say
like, you know what, if we hit this
0:18:22 case, it's so rare we just show an
error message and say the user like
0:18:26 reload, but maybe it's not so rare.
0:18:28 And then you need to think about
it in a more principled way.
0:18:32 And this is where another kind
of manifestation of that is cash
0:18:36 inconsistency and There is a
really great blog post, that goes
0:18:41 along the lines of like, your
app shouldn't become a database.
0:18:45 we'll link it in the description.
0:18:47 But, I think that is like a very nice
and provocative post that shows the
0:18:52 reality of most ambitious apps that
as you pull more on that thread, your
0:18:57 app becomes a database with all the
hard things about a database, and it
0:19:03 needs to be transactionally consistent.
0:19:05 So if you click that button,
maybe it should reflect in
0:19:08 instead over here and over there.
0:19:11 And if it doesn't, your app feels
broken or things might actually like
0:19:15 you get the dreaded, undefined is not
a function because like some, like
0:19:20 array index is not there, et cetera.
0:19:23 And the more you pull on that,
the more you want kind of like a
0:19:26 React-like foundation that you can
just trust that is maybe a bit more
0:19:31 specialized to your use case, but you
can actually trust and it just works.
0:19:36 And this is where I hope things are going.
0:19:38 Like, basically a tree of different
possibilities for, mature and well
0:19:43 designed data systems that, match
the corresponding set of trade-offs.
0:19:49 And it's now our role as educators to
educate developers which trade-offs
0:19:55 work well for their apps and what are
good, solutions and systems for those.
0:20:01 And I think that something like React
Query has been an excellent catch
0:20:06 all that already lifts people up.