Case study

The progress bar that kept freezing: moving an API off AWS App Runner

ClipForge turns a prompt into a captioned vertical video. A run takes a couple of minutes, so the web app shows live progress for each stage: script, voiceover, images, render. That progress travels over Server-Sent Events (SSE), one long-lived HTTP connection that the server keeps writing to.

The symptom

During the render stage the progress stream would die. Render is a long ffmpeg chain that reports only twice, when it starts and when it finishes, so the connection sits silent for minutes. The API was running on AWS App Runner, and App Runner's managed proxy sits between the browser and the app.

First attempt: a heartbeat

Silent connections get cut by proxies, so the obvious fix is to send something every so often. I made the stream send a small heartbeat event every 20 seconds:

HEARTBEAT_INTERVAL_SECONDS = 20

while True:
    try:
        event = events.get(timeout=HEARTBEAT_INTERVAL_SECONDS)
    except queue.Empty:
        yield _sse({"event": "heartbeat"})
        continue
    if event is None:
        return
    yield _sse(event)

I labelled it a stopgap in the code, and it was. With the heartbeat running, App Runner's managed proxy still silently ended the stream during the render stage. The app was doing its part and I couldn't change what the proxy did.

The fix: remove the proxy I couldn't control

I moved the API to a plain EC2 instance with Caddy in front of it. Caddy is a reverse proxy I configure myself, and it gets its own TLS certificate directly from Let's Encrypt. There is no load balancer or managed proxy left in the request path. That fixed the problem outright, and live progress now runs from the first stage to the finished video.

The instance, the frontend and the DNS records are all in one Terraform setup that GitHub Actions can bring up and tear down on demand.

What I'd tell a client

What this doesn't cover

ClipForge isn't running publicly. It's shown through a recorded 88-second run and screenshots, and the Terraform setup is built to deploy on demand rather than staying live. The project has 147 automated tests. The App Runner behaviour is what I observed in this project, not a general claim about the service.

The code from this post is public: https://github.com/hassan91199/clipforge/blob/main/clipforge/api.py.

If your app streams progress or long-running results and something between you and the user keeps cutting it, book a call with me on Upwork.

All posts