For a while I've been playing with the idea of long polling for my notification system, but i've never been able to think of a way to make it more efficient for my backend.
Most implementations I have seen hold the connection open, and the php queries the database server every few seconds to see if new data has been aded. This strikes me as no better than having the javascript repetitively poll the server.
In either case I have my database servers being hit tens thousands of times, which is understandably not particularly desirable.
Are there any systems in place that could 'alert' the executing/sleeping long polling script to the new data?
Long polling is the simplest way of having persistent connection with server, that doesn't use any specific protocol like WebSocket or Server Side Events. Being very easy to implement, it's also good enough in a lot of cases.
Long polling is more resource intensive on the server than a WebSocket connection. Long polling can come with a latency overhead because it requires several hops between servers and devices.
Kafka is an example of technology implementing long polling model, and that's the reason why it is more scalable compared with RabbitMQ when there is a massive amount of messages and clients.
HTTP Long Polling is a technique used to push information to a client as soon as possible on the server. As a result, the server does not have to wait for the client to send a request. In Long Polling, the server does not close the connection once it receives a request from the client.
Single system
If your application is the only system that changes the database, then you can trigger your listeners only when your application performs changes (ideally only for changes to the entities which are interesting for each listener).
Multiple systems
In the case of multiple systems accessing/changing the database, you can either
or if you don't want to do that (I usually avoid it), you can either
or if that's not possible
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With