webbrowserwebsocketlong-pollingajax-polling

Reliable and fast way to send database updates to one or more web browsers


What is a reliable and fast way to send database updates to one or more web browsers?

I have a Postgres database with a few tables being updated over time. The updates range from 0 to 1000 updates per second. When a table is updated I want one to many web client to receive the updates as fast and efficiently as possible. The updates are less than 1K each.


Solution

  • UDP will be the fastest, but it requires dedicated clients and data loss is likely to occur.

    TCP/IP guaranties data integrity, which means you can use SSE or WebSockets for browser clients. However, it requires the data to be sent for each client.

    SSE only supports text data and is unidirectional. It also imposes other limits and uses up one of the browser's per-domain connection limits (browsers are often limited to 6 HTTP connections per domain).

    WebSockets are bi-directional and offer more flexibility. Also, they don't detract from a browser's per-domain connection limit.

    Polling is really a bad idea as far as performance goes, both due to overhead and the chance of redundant requests.

    A short search will get you more information. Many questions about this subject have been asked before.

    There's a discussion about WebSockets vs. SSE, performance discussions about polling vs. WebSockets and an overview of use-cases for AJAX in a WebSockets world.

    These should get you started.