Is it possible to write Railgun listener and endpoint code in a Cloudflare Worker?

For Railgun to work, it seems a server has to have the Railgun OS/listening agent on the server or load-balancer end. On the other end, there’s Cloudflare, which effectively only receives the “differences” in dynamic content before serving it to the end user at their POP globally.

This is because Railgun doesn’t appear to be very customizable by type of request or path. A worker would be a great place to make a request to the origin and then “know” that the origin will only send “differences” from previously known structured content.

The schema for the content that’s being compared would live in KV store, instead of memcache, which is what’s required with Railgun.

How would I approach writing Railgun on a specific path, as a Cloudflare Worker, using KV store as backing storage for comparison purposes?

That’s a fascinating question. Our current roadmap is to replace large parts of the Railgun functionality with Argo Tunnel. Argo Tunnel can incorporate the same compression technology without requiring the complex setup of Railgun.

In terms of your literal question, it should absolutely be possible. In the simplest possible case you would store copies of your pages using the Cache API (I think that probably makes more sense than KV), and then send to the origin which version of the page you have. The origin could then just send the diff between the current version and that saved version, you could apply the diff and then return the response to the user. Obviously though that is far from simple, Railgun has gone through many iterations and it is far from simple technology to reproduce.

3 Likes

Could you update the status of the progress on this i.e. replacing Railgun with Argo Tunnel so that the single listener cloudflared or similar does everything in one shot (compress/cache/route)?

Another (very) important question - I only want to enable Argo and/or Argo Smart Routing + Tunnel for a specific sub-domain, not for my entire domain. How would I do that?

I am unable to add domains which are sub-domains (I tried) - it has to be a root domain.