I have a web API which returns streamed data over an extended period (potentially as long as 5 minutes). The usage of this app is minimal - generally one user issuing no more than a request every few minutes.
As a result, a long running request is typically the only thing running on my app. That’s a problem, as the autostop process sees no incoming requests, and assumes the app can be suspended. When it does, that kills the streaming process that’s sending data to the client
What’s the best way to fix this? Can the autostop mechanism be configured to detect long-running streaming requests?
I’m happy to consider app-level fixes. I’m very new to web application development, and the streaming API is the most complex thing I’ve done. If someone told me “that’s the wrong way to tackle this problem”, I frankly wouldn’t be surprised!
One possibility I thought of is that I could require the client to call a “heartbeat” API every second while the streaming is happening, as that would look like activity to the autostop process. But that requires the client to know implementation details about the service that I’d like to avoid exposing.
Alternatively, I’ve heard that server-sent events are another way to continuously supply data to a client - are they a possible approach here? I don’t want to spend a lot of time redesigning my code with an approach I’m not familiar with, only to find that it has the same problem, so I’d appreciate it if someone could confirm that it would work better with autostop, before I go down that route…
I guess I’m surprised that streaming responses cause this issue - they seem like a pretty normal thing to do in webapps, from what I’ve seen. Is it just that fly’s default machine management isn’t really designed to support them? After all, my app is very unusual in terms of the incredibly low level of activity it’s designed for. On the other hand, I don’t want to switch off autostop, as that’s a huge waste of resources for an app used so infrequently.
Thanks for any suggestions.