Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: let clients receive events they missed while they werent connected #91

Open
yusdacra opened this issue Feb 3, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@yusdacra
Copy link
Member

yusdacra commented Feb 3, 2022

Currently, clients can't receive events they missed, when they weren't connected to the server. This can happen for many reasons, but most notably because the user closed the client application, or because of an internet failure. This means that once they reconnect, their state will be out-of-date, and they will need to refetch all of the data instead of incrementally fetching what they need. This issue is for tracking potential solutions.

Solutions?

solution 1

  1. introduce a new StreamEventsResponse.event variant:
    message StreamId {
    	uint64 stream_id = 1;
    }
  2. StreamId lets the client know the ID of the current stream they are using. This will be sent to the client upon connection of the stream.
  3. introduce a new StreamEventsRequest.request variant:
    message KeepTrack { }
  4. KeepTrack lets the server know that after the current stream has ended, it should store any events dispatched to this user under the ID of the stream that ended.
  5. introduce a new RPC to ChatService called SynchronizeEvents. it's request type will take a uint64 stream_id = 1;.
  6. ChatService.SynchronizeEvents will return a list of events, ordered from oldest to newest, that the client has missed since the end of the stream the ID was bound to. After this is called, the stream ID should be invalidated, and all the events should be removed.

The events should only contain the newest state, and nothing in between. New messages should not be kept, only edited / deleted messages, as new messages will potentially take up a lot of storage. The client can fetch the new messages itself.

solution 2

  1. servers attach a "last modification time" to basically everything (profiles, messages, guilds, channels, etc)
  2. clients later can synchronize their state by sending a request with the last time they were connected. the server will figure out what's missing and send it to the client. the response can simply be a list of events, ordered from oldest to newest that the client can apply easily without writing new logic.

Unlike the first one, this doesn't require much protocol change aside from one new RPC, and doesn't require the server to store redundant state. However this is potentially much more complex for servers (?).

@yusdacra yusdacra added the enhancement New feature or request label Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant