rocicorp / replicache

Realtime Sync for Any Backend Stack
https://doc.replicache.dev
1.01k stars 37 forks source link

Caching pulls for high scale #1043

Closed KyleAMathews closed 1 year ago

KyleAMathews commented 1 year ago

If you have a lot of connected clients, all of them pulling at the same time can add a lot of load to your db (probably necessitating setting up some sort of caching layer. It seems like it'd be nice to able to cache responses instead on the CDN. I was thinking of a scheme like this:

  1. fetch to version 42
  2. poll for or get pushed a new server version 43
  3. request /api/replicache-pull/42/43 — the server runs this once & tells CDN to cache it for everyone else.
  4. A user coming back from connectivity issues might request /api/replicache-pull/42/49 and so on.

Thoughts?

The tricky bit is the lastMutationId — perhaps that could be a separate request the client makes when it has an unconfirmed mutation locally?

aboodman commented 1 year ago

So sorry for the slow reply here. We don't often get questions in the form of issues and somehow this slipped by.

This only works if everyone gets the same pull response. But Replicache is designed to allow the pull response to be customized.

I think scaling reads is something databases are pretty good at. Can you give a sense of the scale you are worried about?

If you're still interested in this question come find me at discord.replicache.dev - happy to discuss more.