realtime icon indicating copy to clipboard operation
realtime copied to clipboard

[WIP] Backlog of events

Open abc3 opened this issue 3 years ago • 4 comments

What kind of change does this PR introduce?

This PR fixes #125 by adding an additional module BacklogReplication that saves all DB updates to the disk. Also, it suggests separating exports (Webhook/WebSocket) notifications to different processes and slows down the Websocket rate.

What is the current behavior?

  • A large transaction can kill the Realtime because all events are stored directly in a process state
  • Overflowing the message box through broadcast
  • In the next code, two problems https://github.com/supabase/realtime/blob/c293c7680b84e19a068787d0d7f8e49ef8c275f8/server/lib/realtime/subscribers_notification.ex#L15-L16

The WebhookConnector.notify has to wait until the notify_subscribers finished, and if the notify_subscribers crashes, the WebhookConnector.notify never starts.

What is the new behavior?

Each exporter (Webhook/WebSocket) subscribes to a process group.

A BacklogReplication stores DB updates to disk and then sends the transactional to subscribed exporters. The system environment variable "REPLICATION" can change the replication module.

The Adapters.Changes.BacklogTransaction structure contains a link to a part of the file where stored updates. The changes decode in a time when need send to clients.

IMPORTANT. In the current implementation, the transaction for webhook is limited to 10 000 changes because that place can crash the application too.

Additional context

First of all, PR made for EC2 t4g.micro instance.

TODO:

  • [x] Store DB changes to disc
  • [ ] Decide how right handle large transactions for Webhook
  • [ ] Add unit tests

abc3 avatar May 15 '21 11:05 abc3

@abc3 really excited for this PR! Let me know when it's ready and I'll start reviewing. Thanks!

w3b6x9 avatar May 25 '21 01:05 w3b6x9

@w3b6x9 of course, I've just stuck in routine tasks, but I will continue soon.

abc3 avatar May 25 '21 07:05 abc3

@w3b6x9, you can already start to review or testing. Interesting what you think about that. And I'll start writing tests.

abc3 avatar May 26 '21 13:05 abc3

@abc3 sounds good, i'll take a look soon!

w3b6x9 avatar May 26 '21 16:05 w3b6x9

Not relevant anymore with the latest version of Realtime landing soon

chasers avatar Sep 26 '22 19:09 chasers