Live data from Hacker News

Data fetching on the web still sucks

performancejs.com

11–20 of 98 posts

Re: Data fetching on the web still sucks

#11
Ember.js seems to check off a lot of those boxes, if you are willing to use a complete solution and not do the 'pick and choose' method of react and friends. While it has lost popularity in the last few years, it has been moving forward technically. It has become leaner and meaner.

Really learning the "Ember Way" to do things can reduce some of the friction the author mentions.

Ember Data can allow you to talk to multiple api backends (differing schemas) while presenting the same model to your UI. If you use the default JsonApi[0] based backend, you get a lot of things for free: powerful filtering, side loading data (relationships), consistent error handling. Sometimes it can be chatty, but that's a spot where HTTP2 can help.

Use ember-concurrency add-on and you have a nice way to manage your requests, things like de-bouncing, handling loading spinners, etc.

[0]https://jsonapi.org/format/

Re: Data fetching on the web still sucks

#12

> You shouldn’t have to ship kilobytes of metadata describing your data schema to clients in order to fetch data. I feel like this requirement makes every other requirement impossible unless you use some kind of compiled language feature and even then you're not going to be able to have type safety without some kind of metadata. Also, I don't think it's possible to make any one library that solves all "data fetching"…

That said, we do need some better standards. I look after a bunch of API integrations at work and we have everything from SOAP to GraphQL to downloading a magically named .xml.gzip file in a FTP directory with at least 10 other homemade REST implementation between and every single one of them is basically returning the same info but in wildly incompatible ways.

At least the SOAP one crashes when they change the API without telling us :/

Re: Data fetching on the web still sucks

#13
post #9
post #5

I'm currently experimenting with React and WebSockets and they seem to be a perfect fit. No need to write wrappers for Fetch, network errors and reconnects can be handled on high-level, handlers for each message type can be mounted and unmounted on useEffect hooks, all back-end jobs can notify the user in realtime, all session-based client-side data can be updated in realtime (in single or multiple open tabs). I'm al…

> and they seem to be a perfect fit Needs a fairly capable server though, I suppose. One that can handle lots and lots of open websocket connections.

Guess it really depends on how many concurrent users you expect to have...

Sounds like 30 GiB RAM for 1 million concurrent users is not unreasonable:

https://stackoverflow.com/a/17453704

Re: Data fetching on the web still sucks

#15
Not to toot our own horn, but while this mentions GraphQL with Relay / Apollo as fetching clients, with urql and its normalised cache Graphcache we started approaching more of these problems.

Solving the mentioned problems in the article for best practices around fragments is on our near future roadmap, but there are some other points here that we've worked on that especially Apollo did not (yet)

Request batching is in my humble opinion not quite needed with GraphQL and especially with HTTP/2 and edge caching via persisted queries, however we have stronger guarantees around commutative application of responses from the server.

We also have optimistic updates and a lot of intuitive safe guards around how these and other updates are applied to all normalised data. They're applied in a pre-determined order and optimistic updates are applied in such a way that the optimistic/temporary data can never be mixed with "permanent" data in the cache. It also prevents races by queueing up queries that would otherwise overwrite optimistic data accidentally and defers them up until all optimistic updates are completed, which will all settle in a single batch, rather than one by one.

I find this article really interesting since it seems to summarise a lot of the efforts that we've also identified as "weaknesses" in normalised caching and GraphQL data fetching, and common problems that come up during development with data fetching clients that aren't aware of these issues.

Together with React and their (still experimental / upcoming) Suspense API it's actually rather easy to build consistent loading experiences as well. The same goes for Vue 3's Suspense boundaries too.

Edit: Also this all being said, in most cases Relay actually also does a great job on most of the criticism that the author lays out here, so if the only complaint that a reader here picks up are the DX around fragments and nothing else applies this once again shows how solid Relay can be as well.

Re: Data fetching on the web still sucks

#16
post #9
post #5

I'm currently experimenting with React and WebSockets and they seem to be a perfect fit. No need to write wrappers for Fetch, network errors and reconnects can be handled on high-level, handlers for each message type can be mounted and unmounted on useEffect hooks, all back-end jobs can notify the user in realtime, all session-based client-side data can be updated in realtime (in single or multiple open tabs). I'm al…

> and they seem to be a perfect fit Needs a fairly capable server though, I suppose. One that can handle lots and lots of open websocket connections.

Yes that's some genuine concern. Though on B2B and B2C SaaS where you got paying users, I think each of them deserve a websocket, and it could* alleviate some headaches for developers.

* Anecdotal of course, at least for us.

Re: Data fetching on the web still sucks

#17
post #7
post #2

Relay modern does all of the things that this article sets as a criteria for good data fetching.

It doesn't have a great story around error handling IMHO.

I've found Relay to be pretty solid with error handling, though I think the ability in how to handle GraphQL errors does hurt Relay here, but it does for all GraphQL clients.

Re: parent, I also was surprised to see Relay dismissed on the list, it solves every problem they bring up in the list, perhaps maybe not the real-time aspects

Re: Data fetching on the web still sucks

#18
post #2

Relay modern does all of the things that this article sets as a criteria for good data fetching.

I'd agree Relay is relatively far along, compared to other frameworks.

I might lump its support into a few groups:

- Full (eg. request batching)

- Full, but painful (eg. colocation)

- Partial (eg. mutation queuing)

- Non-existent (eg. durability guarantees)

(I've been using Relay Modern daily for a few years.)

Re: Data fetching on the web still sucks

#19

SWR or react-query?

I started my current project using SWR and then switched to react-query after dealing with some annoyances with SWR.

Overall react-query is impressive for data fetching, but I’ve run into issues with mutations and cache invalidation.

Re: Data fetching on the web still sucks

#20
post #10

> Realtime updates. Sometimes, you want data to be pushed, not pulled (eg. for things like notifications). But the APIs for pushing and pulling data are often different, both on the client and on the server. Two and a half months since Google announced the removal of HTTP Push[1]. There'd been a number of threads open (some 5 years old now) asking the Fetch spec to please include some way to allow the page to be noti…

[deleted]
Post reply on HN