Putting the Serverless in Server-Sent Events
A solution to sending Server-Sent Events from serverless platforms
For my last few projects, my tech stack has been very consistent: Astro, Turso, and Tailwind - hosted on Cloudflare Workers. More than once, a problem I've faced is streaming one-way data to clients from serverless environments. This is due to the short run durations and limits imposed by serverless platforms. This problem can be a major roadblock, especially when the application requires real-time data streaming.
The Problem with Serverless and Data Streaming
One-way data streaming, which is a fairly common requirement in many applications, has proven to be particularly challenging on serverless platforms. Traditional solutions are often convoluted and complicated to implement. They often involve setting up additional infrastructure, which can introduce more points of failure and complexity. This situation is far from ideal and it begs for a simpler solution.
Introducing Flux: A Simple Solution for Data Streaming
The solution to this problem comes in the form of Flux, a simple HTTP proxy specifically designed for data-streaming. Flux is created using Hono, a lightweight framework, running on Bun. It acts as a bridge between the serverless function and the client, allowing for seamless data streaming over Server-Sent Events (SSE). Essentially, Flux acts as a middleman; the server sends data to Flux, which then forwards it to the client as a stream.
Flux is self-hostable: you can deploy it on your own infrastructure as long as it supports Bun.
Getting Started with Flux
Flux is entirely open-source and available for anyone to use. A public instance with some documentation is available at https://flux.vsahni.me. Instructions for self-hosting or contributing to the project are available on the GitHub repository at https://github.com/notskamr/flux.