Search code examples
reactjsgoogle-cloud-platformstreaminggoogle-cloud-runremix.run

Does Cloud Run supports HTTP streaming?


TLDR: Is there a way to enable HTTP streaming on the Cloud Run service on GCP?

So React 18 supports streaming. I am using the Remix framework that should stream responses out of the box according to their documentation.

Sounds cool right? Unfortunately I'm into Google Cloud Platform and App Engine Standard. App Engine Standard wasn't supporting it (and being honest about it in their docs).

I deployed a Remix application on App Engine and it didn't seem to stream. Here is a screenshot of the response headers of my Remix project running on App Engine (so that this post doesn't lose information if I take the example offline). enter image description here

App Engine Flex might support it (as it can also do stuff like Websockets where App Engine standard cannot), but App Engine Flex has the downside that it always needs 1 instance running. Which is not ideal for my hobby app, as it has very few users.

But I was reading about Cloud run and hoping that it was able to do HTTP streaming. I made a Dockerfile for a generated Remix project in a repo and deployed it to cloud run. Here is a screenshot: enter image description here

Both these screenshots look way different from what the response headers look like when I run the Remix project locally: enter image description here

As you can see there it says Connection: keep-alive and Transfer-Encoding: chunked

I did search the internet about cloud run and streaming but all I can find is this reddit post which says streaming might not work if you deploy in certain regions (but I deployed on the region in the Netherlands as I'm located there). Also I found this other SO question where it said it does grpc streaming but that's not what I need.

Help is appreciated!


Solution

  • I made a streaming example that streams pokemon names in a very visible way (for like 15 seconds): https://github.com/Leejjon/remix-vite-with-streaming/

    I deployed to:

    • App Engine Standard, and there streaming doesn't work. The server just waits for 15 seconds and then sends the entire response.
    • App Engine Flex, at first it seemed to do the same as standard. But once I set the "X-Accel-Buffering" header to "no" in my response headers (like this) it started to stream. Then again this requires always 1 instance to run 24/7 making it an expensive option for hobby apps.
    • Cloud run, there you see the streaming work at once. It doesn't set any Response headers to tell you that it streams though. PS: I thought it required a dockerfile at first, but it turns out you don't need that. Nice.