Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Cloud Run support server sent events (SSE)?

We can't get SSE to send from containers on Google Cloud Run. I've tried hosting a container with just a simple SSE example (https://github.com/kljensen/node-sse-example) to see if it was something in our library -- nope.

I see from the server that clients connect (like the initial GET works), but no events get sent from the server. The EventSource on the client never changes from CONNECTING to CONNECTED.

From the Cloud Run docs, it's a little ambiguous if this would be supported (emphasis mine):

Cloud Run (fully managed) currently does not support HTTP streaming. Therefore, inbound requests with protocols like WebSockets and gRPC (streaming RPCs) are not supported.

As an exception, Cloud Run (fully managed) services support unary gRPC for inbound requests.

For outbound requests, both WebSockets and gRPC are supported on Cloud Run (fully managed).

Wouldn't SSE count as outbound requests, or am I misunderstanding?

like image 650
andrew Avatar asked Dec 06 '22 08:12

andrew


2 Answers

UPDATE (October 8, 2020): Server streaming is now supported https://cloud.google.com/blog/products/serverless/cloud-run-now-supports-http-grpc-server-streaming

Not currently. However, this feature (gRPC server-side-streaming and SSE) will be launched very soon. We're working on it actively, stay tuned.

like image 146
ahmet alp balkan Avatar answered Dec 17 '22 21:12

ahmet alp balkan


If I refer to the Cloud Run design, the container processing is performed only when a request is handled, the rest of the time, the CPU is close to idle. That's why you are billed only when a request is processed.

If I take the SSE flow, the server initiate a connection to the client. You need processing time (and resources) for establishing and maintaining this connexion. And because it's out of any request, your CPU is idle and it can't work for performing this.

So, I don't have a clear answer to your implementation problem, but, by design, I'm quite sure that Cloud Run can't work with SSE. At least, for now.

like image 20
guillaume blaquiere Avatar answered Dec 17 '22 19:12

guillaume blaquiere