vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
618 stars 167 forks source link

Fault-tolerant messaging for server-client communication #20348

Open mshabarov opened 2 days ago

mshabarov commented 2 days ago

Describe your motivation

Vaadin doesn't store any information about messages that are sent from server to client (and vice versa) and triggers a full page reload in browser, when the server detect a mismatch between UI state on client and server, e.g. when message is lost.

This may happen due to various reasons, but those caused by network issues / message loose, can be reliably eliminated by implementing two-side message buffer for already sent, but not-yet-confirmed messages. Server can store an ordered log/buffer of UIDL messages and client can store a similar log/buffer for RPC message. The messages are preserved in buffer until a consumer (may be a server or client, depending who sends the message) confirms that it has received the message in the next request, then the producer deletes this message from the buffer.

Describe the solution you'd like

Flow Client (MessageSender) and Flow Server (ServerRPCHandler) have the logs (buffers) of ordered messages that producer (either Flow server for UIDL or Flow client for RPC) has sent to consumer.

These logs has message JSONs mapped to the sync ID or client ID. These IDs are already being used for detecting a out of sync.

Producer stores a message in the log until it gets a confirmation from the consumer. Once a consumer sends another request (e.g. client sends another RPC for another user action), then the producer checks if this request has a confirmation for previously sent message (e.g. for the previous UIDL update that server sent to client). If the confirmation is there, then server deletes the corresponding message from the buffer, otherwise it re-sends it again in the current response along with the current UI update. Then the consumer receives two responses instead of one (if, of course, message is not lost again).

This is illustrated by the sequence diagram below: first UIDL message is logged, then deleted after confirmation. Second UIDL message is lost and server re-sends it again after action 3. Then browser receives two UIDL messages (2 and 3), updates the UI and sends the confirmation in the next request.

Server-Client buffer 2

Acceptance Criteria:

Additional context

Better to do it in two steps:

Target Vaadin release - 24.6, but can be picked to older versions.

mshabarov commented 2 hours ago

To note: Atmosphere has already some cache for messages in the server-side, we have to avoid duplicates for caching thus.