HTTP response streaming in app platform (for SSE support)
R
Roger P
I'm trying to serve Server-Sent Events (SSE) using Flask on the DO App Platform, but instead of streaming, something on DO's side seems to be caching the entire response and only returning it in one big chunk. I've been trying and trying to debug, and finally found this page which seems to indicate it's not possible? https://www.digitalocean.com/community/questions/how-to-enable-http-response-streaming-in-the-app-platform
So I have to migrate off the app platform now I guess? Or am I missing something?
Daniel Weinmann
+1
This is also really important for Remix/React Router v7 apps. Modern web development relies heavily on streaming.
Are you guys planning on implementing this? I love the App Platform so far and would love to move all my apps from Heroku to DO, but I might have to choose a different provider if you don't implement streaming.
Ronie Martinez
+1
I was trying this with a simple Flask application which worked on a droplet + nginx.
This same app didn't work on App Platform properly.
- On initial load, no server response.
- After waiting 3-5 minutes, the data is returned in bulk.
- You have to wait the same amount of time until the next set of data is returned.
I am pretty sure that the reverse proxy (looks like cloudflare) is buffering the SSE messages and ignoring the "X-Accel-Buffering=no" header.
Upon searching, I found this related issue: https://github.com/cloudflare/cloudflared/issues/199
I believe CloudFlare caching is enabled. (https://community.cloudflare.com/t/websockets-and-server-side-events-in-my-application-are-not-working-anymore-if-cloudfare-cache-is-enabled/179584/4)
Too bad, I can't move to App Platform yet and keep my Droplet + nginx setup.
Anonymous
Also struggling with this, if anyone has figured a workaround would appreciate the help
EDIT:
Changing my endpoints to accept POST and changing my server response headers as below seems to be working for me for now!
'Content-Type': 'text/event-stream',
'Connection': 'keep-alive',
'Cache-Control': 'no-cache',
'X-Accel-Buffering': 'no'
Alex Cavazos
Anonymous Did you get it to work with GET requests?
Saleh Alzahrani
Open AI apps need this
F
Francesco
Next.js apps don't work properly without this feature enabled. +1
Jesse Garrison
same issue- any updates on a fix?
S
Scott M
I am having the same problem and it would be great if the App Platform properly supported SSE. Our SSE server works fine when I run it locally and on other platforms, but when it is run on your App Platform, the event responses are not sent each time they are written, but only as a huge chunk when the server ends the response stream. The server is also not detecting when the client ends the connection.
Anonymous
Scott M: Hi Scott. Regarding aborts - are you sure that DO is responsible for this? I had this issue as well just to figure out it was an issue with Next.js framework. Upgrading resolved the issue.