Why we migrated our backend from Vercel to Fly.io and the challenges we confronted.
On this article we’re going to see the explanation that made us change our backend
to Fly.io and the challenges we had through the migrations.
We selected Hono as our API server with Bun
because the runtime and choose Fly.io as your internet hosting service.
🤔 Why did we wish to transfer our backend from Vercel?
⚡ A light-weight Server
We required a light-weight server with a easy REST API for our monitoring
endpoint. Deploying a easy Specific server is feasible, however it isn’t
particularly designed for this goal.
It is attainable to deploy an Specific.js utility as a single Serverless Perform, nevertheless it comes with drawbacks and may solely be used as a migration path. As an alternative, use Subsequent.js or embrace a number of Serverless Capabilities as you incrementally migrate to the Vercel platform.
Additionally launching a clear and new Subsequent.js server takes 2.5 seconds on my MacBook
Professional M1 and takes 110mb of RAM, and it consists of pointless further options from
Subsequent.js. Our prod Subsequent.js app takes about 5 seconds to launch on my laptop
(contentlayer).
For comparaison launching our present server takes 0.19ms and solely takes 91mb.
Our present server stack is Hono + Bun.
💸 Pricing
We initially aimed to offer multi-region monitoring for all customers whereas
sustaining a free tier. On Vercel, if you’d like a multi-region operate, you
must go for Edge Capabilities. Edge features are cost-effective as you solely
pay for the precise CPU execution. Which means that you will not be billed for idle
occasions when fetching information.
It is nonetheless inexpensive, however we’re a bootstrap enterprise and it troublesome for us
to foretell our month-to-month bills. If we expertise a rise in new customers, our
prices may even enhance accordingly.
Here is the mathematics for the price of one monitor for a consumer:
6 (10 min displays) * 24 * 30 * 3 (common execution unit per monitor) * 6 (variety of areas) = 77,760 executions items per thirty days
77,600 * (2/1,000,000) = 0.15c per monitor month-to-month
We’ve over 1000 displays, and the month-to-month value to run them could be $150.
Whereas on fly we solely have 6 servers with 2vcpu/512Mb It value us $23.34 month-to-month
($3.89*6).
🤯 What challenges did we face throughout our migrations?
Docker + monorepo = 🪨
We’re deploying to fly.io. We’ve to setup our app as a Docker picture. Our apps
is in a monorepo. Our preliminary picture was over 2 GB in dimension, which was excessively
giant for a primary server.
Our picture included every little thing, which was inefficient. After optimizing, our
picture now occupies solely 700MB. Though it’s nonetheless considerably giant, it’s a
vital enchancment over our preliminary model.
It was one thing we by no means needed to handle with Vercel deployment.
⏳ Fly deployment timed
Our Fly deployments have been experiencing frequent timeouts with none
particular motive. The one answer we’ve found is to extend the timeout
period.
flyctl deploy --wait-timeout=500
Based mostly on our expertise, Fly deployments are typically much less dependable in contrast
(extra timed out) to Vercel deployments. Moreover, we’ve not found a
fast technique to rollback to the earlier model.
🐛 The Bun bug
Once we migrated to Fly, we determined to make use of Bun as our runtime. Nevertheless, within the
first few hours after the migration, we noticed an unexplained enhance in
request failures.
After digging into the Bun GitHub we discovered an answer: We wanted to set the
keepalive
parameter to false
. That is obligatory as a result of closed connections
will not be mechanically eliminated and stay within the CLOSE_WAIT
state.
Here is the GitHub challenge:
https://github.com/oven-sh/bun/issues/3327
I want it had been documented elsewhere.
Our conclusion
We’re happy with our migration to Fly.io, though it was accompanied by a
difficult weekend. And we nonetheless love Vercel, they provide an excellent product, it
removes a whole lot of ache for the builders.Nevertheless, when you require a internet hosting an
utility aside from Subsequent.js, it might not be the most suitable choice.
We’re nonetheless utilizing it for our frontend.
Create an account on OpenStatus
to begin monitoring our web site and managing your incidents without cost.