Server Sent Events and Cloudflare

I’m developing an API for a service that’s gonna launch soon. Clients will connect and listen for data via Server Sent Events. Everything went well until recently, when initial data got larger (really not that large though, just 37kb uncompressed JSON) only part of that initial data get streamed to the clients. This works with every other hosting (Heroku, Localhost, Digitalocean) – my guess is that Cloudflare is somehow interfering. We are setting the headers “Cache-control: no-cache”, but that’s probably not enough. Is there any way to bypass Cloudflare, at least for debugging reasons (to make sure that really Cloudflare is the problem)?

Hi Severin,

I’m happy to help look into this. Can you share a ray-id of a request that had this issue?

Hi! Here you go:

cf-ray: 6d48b28e2c5023df-ZRH

You can also test it out yourself: https://fcut-api.onrender.com/listen

Seems like something is holding back the data until it reaches a certain amount (we’re sending a ping event every minute, so after a while it will send more data).

I can confirm that this is an issue with Cloudflare. We are working with them to see how we can prevent this going forward. In the meantime, have you considered using websockets? This use case seems like a good fit for them and Cloudflare tends to handle those connections more gracefully.

Thanks for looking into it. For this case it was actually much easier to switch to Heroku (although I hoped to ditch their service). WebSockets would be an alternative, but I prefer SSE for unidirectional realtime updates – lightweight, simple and super performant.

As four Cloudflare: I do like their service (a lot), but I’m not too happy about not being able to opt out or at least configure when edge cases happen. And IMHO edge cases happen more often then you’d think.

Anyway, thanks again for looking into this, I’d be happy to switch back :slight_smile:

1 Like

I definitely understand where you’re coming from. It’s important that all traffic goes through Cloudflare, so we want to work through these edge cases so that Cloudflare remains as transparent as possible from a customer perspective.

I’ll be sure to let you know once we are able to resolve this with them!

Hello

The sample page https://go-gin.onrender.com. also does not work. The messages seem to be buffered

Hi folks, any update on this? We are having the same issue and it is blocking our release.

Hi Frank,

We are working with Cloudflare to identify a workaround. We don’t have an ETA for this yet, but it’s a high priority for us.

Still no ETA for this? Running into all sorts of issues with server-sent events migrating from Heroku

We’ve released a fix for this issue. You should now be able to use server-sent events. Let me know if you continue to run into any problems.