DEV Community

Cover image for How I Built GitHub Hot-Reloading for HYNA-Stage (And Why It Takes 3–5 Seconds, Not Instant)
Harun - solo dev
Harun - solo dev

Posted on

How I Built GitHub Hot-Reloading for HYNA-Stage (And Why It Takes 3–5 Seconds, Not Instant)

In modern development, we are conditioned to expect "instant."

Hot Module Replacement (HMR) in React is instant. Local file watchers are instant. So when I tell you that HYNA-Stage's GitHub hot-reload takes 3–5 seconds, it might sound slow.

But there is a massive difference between watching a local file change and syncing a remote Git repository into an isolated cloud MicroVM.

Here is how I built the hot-reload feature, why I chose this specific architecture, and why 3–5 seconds is actually a win.

🧠 THE PROBLEM: WEBHOOKS VS. POLLING

The industry standard for "repo changed" events is Webhooks. GitHub sends a POST request to your server when a commit is pushed.

It sounds perfect. But for a platform provisioning ephemeral, temporary sandboxes, Webhooks are a nightmare:

  1. Every sandbox needs a unique, public-facing URL to receive the webhook.
  2. You have to manage routing, SSL, and security for thousands of temporary endpoints.
  3. If the sandbox is asleep or restarting, the webhook fails and the update is lost.

I build on a $150 Android phone in Termux. I don't have the infrastructure or the time to manage a complex webhook router for temporary VMs.

So I chose ETag Polling.

⚙️ HOW IT WORKS: THE 3-STEP DANCE

Instead of waiting for GitHub to tell me something changed, the sandbox asks GitHub: "Has this file changed?"

Step 1: The Poll
A lightweight background process inside the MicroVM checks the ETag header of the repository's raw files via the GitHub API.
Why ETag? Because it's a simple hash. If the hash hasn't changed, the response is a 304 Not Modified (a few bytes). It costs almost zero network bandwidth and zero compute.

Step 2: The Sync
When the ETag changes, the sandbox runs:

git fetch origin
git reset --hard origin/main
Enter fullscreen mode Exit fullscreen mode

git reset --hard is brutal but necessary. It doesn't try to merge or resolve conflicts. It just forces the sandbox to become an exact mirror of the remote main branch.

Step 3: The Restart
A simple fuser -k kills the old running process, and the start command fires again.

⏱️ WHERE THE 3–5 SECONDS GO

It’s not magic. It’s physics.

  • Network Latency (1–2s): The sandbox has to talk to GitHub's API over the internet.
  • Git Fetch & Reset (1–2s): Downloading the diff and rewriting the files on the MicroVM's ephemeral disk.
  • Process Kill & Restart (0.5–1s): Tearing down the old Node/Python/Go process and booting the new one.

If you push a massive 50MB binary file, it will take longer. If you change one line of CSS, it will be closer to 3 seconds.

🛑 THE HONEST LIMITATION

Because this relies on polling, it is not truly instant. There is a check interval (currently every few seconds). If you push a commit, you might have to wait one poll cycle before the sandbox notices.

Also, it only watches the default branch (main). If you push to feature-x, the sandbox won't see it until you merge. I made this trade-off to keep the polling logic simple and the compute cost near zero.

🔨 WANT TO STRESS-TEST IT?

I want to know what happens when you push rapidly.

npm install -g @hynaweb/stage
hyna-stage watch --github <your-repo>
Enter fullscreen mode Exit fullscreen mode

The Mission: Push three commits in ten seconds.
Does the sandbox catch all three? Does it get stuck on the second one? Does the URL stay the same?

Dashboard: https://hyna-stage.netlify.app/
GitHub: https://github.com/harun-sket/hyna-stage

Drop your results in the comments. If it breaks, tell me exactly how.

— Harun, Founder & CEO, HYNAWEB 🐯☁️

Top comments (0)