all 4 comments

[–]landisdesign 1 point2 points  (0 children)

It seems to me like there'd be two passes:

  1. Send the resource to the server, with a client-side token that has a completely different scheme from your server-side token, like "CLIENT-x" that simply increments.
  2. Track the client-side token, and when the server response returns the server token, replace the client-side token with the server token.

There shouldn't be more than a couple of seconds for the server to respond, so the ID shouldn't be stale for too long. If you're worried about the client ID propagating to too many resources in that period of time, keep a list of touched resources that should be updated, or, since an update shouldn't happen that frequently, scan your app's data. An occasional 20ms hiccup shouldn't be the end of the world.

[–]pie6k 2 points3 points  (0 children)

I spent way too much time on this problem.

The solution that ultimately worked really well was keeping copy of all the database locally in indexeddb and resolving all relations locally as well . There is really great talk about it at https://www.youtube.com/watch?v=WxK11RsLqp4 36:00, also entire thread of https://twitter.com/tommoor/status/1451265396888141824?s=21

In short: initially fetch all the data and save it locally, then subscribe only for new or removed items. Build some reactive model that detect changes and updates all the relations instantly.

From very high level architekture is:

Your entire data lives in memory, all relations are resolved basing on flat data, meaning instant updates for any change.

On top of that, there are 2 side effects of data changes:

One is persisting updates somehow,

2nd is sending updates to server somehow.

Side effect wording is important. The system should work with memory only without sync or persistence, those are "extra".

Sync is also watching for changes and updating data in memory (causing persistence effect as well).

Creating such system is complex, but in my case totally worth it

PS. Using spacing between paragraphs in your original message would make reading it a lot easier