I’m running a web app on Node that needs real-time access to events coming from the Particle Cloud. So far I’ve been using getEventStream from the node SDK, which uses server-sent events, keeping a connection open between my web app and the Particle Cloud. I just realised I could also use webhooks, keeping each message discrete.
Is there one method that is generally seen as preferred? My hunch is that webhooks are maybe more stable as no connection has to stay open, but what are people’s opinion on this?
You are running the server at home or small business with a non-static IP address.
You don’t want to go through the time and expense of setting up SSL certificates for your server.
Generally no firewall rules or port forwarding to worry about as the connection is outbound.
You want slightly lower latency for event notification.
Webhooks are better if:
You need to distribute the handling across multiple servers. (This also improves reliability through redundancy.)
You are sensitive to lost events. (With SSE, if the connection goes down, it can take a while, up to a minute, for this to be noticed and corrected. In the downtime, any events sent during that period will be lost.)
Google Pubsub is better if:
You are sensitive to lost events. With Google Pubsub, once the event is delivered to the Google cloud, they are buffered there. This means if your server is unreachable or down you won’t lose events.
You are running the server at home or small business with a non-static IP address.
Or your server is still in development and may not have 100% uptime yet.
You don’t want to go through the time and expense of setting up SSL certificates for your server.
Generally no firewall rules or port forwarding to worry about as the connection is outbound.
Once Google Pubsub events are received by the Google cloud they have confirmed delivery so you can have multiple event servers that handle events to distribute load and for redundancy without getting duplicates.