I have a problem with the implementation of SSE (Server Sent Events) and Cloud Run.
I have a service in node.js that is listening for events on a PubSub subscription. At the same time, I have another web application that is connected to this service by SSE. In the local environment it works smoothly, every time an event arrives to the service in node.js, it emits the message to the web client, but once deployed in Cloud Run it stops working, or, it works slow and not all messages are delivered. Anyone with a similar experience? Maybe I should use Compute Engine to deploy the node.js service instead of Cloud Run.
Check your logs for any returned errors or potential issues so you could identify the reasons for the mentioned behaviors. There could be several causes for this, example scenarios could be:
By default, Cloud Run only allocates CPU and charges when a container instance is processing at least one request. You can opt-into having CPU for the entire lifecycle of container instances, which are still subject to autoscaling. Cloud Run pricing depends on the selected CPU allocation.
Since Server Side Event are server side, pushing changes to the client won’t work, unless you have CPU allocated.
Hi @chaloman , even i’m facing the same issue now, we are using the Server Sent Events for the server initiated communication to client, but when i tested in local, everything is working fine, but when we deployed to the dev environemnt in the AWS cloud we are facing inconsisent issues, if i open 4 browsers we are getting events to 2 browsers, if i open 6 broswers we are getting events to 3 browsers, like half we are getting not to the other half.
SSE is quite limited using multiple tabs at the same time, the connection are limited per client. I recommend you to implement WebSockets, I think SSE is still lacking maturity on cloud technology. I made that change and it worked very well.
Switch to using websockets and it worked on Cloud Run. I essentially setup up a SSE with a websocket by sending updates from the backend to the front and nothing but a heartbeat ever gets returned. Good luck!
Hi, I have exactly the same problem. If I understand correctly, you have built a unidirectional SSE by sending events/updates to a site from your backend deployed on Cloud Run. You have used websockets instead of SSE-associated technologies (emitter…). Is that how you have it currently, and it has worked for you, right?