Hi, I have been experimenting on deploying my Rails app running on Sqlite3 (app database and background job with solid queue) + redis (cache and action cable). The goal is when my app starts to grow, I can easily deploy to a new region closest to my users so that they experience the same snappy app as the one near to my primary region. Fly seems like a good bet to achieve this.
So far, I have managed to deploy my Rails app on Fly with litefs. The primary region is in hkg (I am based in Malaysia)
Here are the page speed of the response when hitting the #new endpoint of one of my controller:
Sending a request from Malaysia (without VPN): 81ms
Thanks for the reply, the endpoint I am testing doesn’t perform any write so I was wondering if I missed anything that might improve the speed more.
I am a little confuse with how to setup the proxy and having issue where PUT request when performed in non-primary region failed as it wasn’t redirected back to the primary. My understanding of the doc is that the proxy should handle it already, so maybe I am setting it wrong.
proxy:
# Bind address for the proxy to listen on.
addr: ":8080"
# Hostport of your application.
target: "localhost:8081"
# Filename of the SQLite database you want to use for TXID tracking.
db: "my.db"
You’ll also need to ensure that your application is running on the target port, which is 8081 in this example. Additionally, make sure your internal port is configured to the proxy’s bind port in your fly.toml:
Then in my litefs.yml, I set the target to localhost:3000.
proxy:
# Specifies the bind address of the proxy server.
addr: ":8080"
# The hostport of the target application.
target: "localhost:3000"
# The name of the database used for TXID tracking.
db: "production.sqlite3"
My question will be, where should I set the bind address of the proxy port 8080 in my fly.toml? Do I need to add the [[services]] as per the doc? Or I need to change my [https_service]'s port?
Set that as internal_port, otherwise the LiteFS proxy is being bypassed completely.
The chain should be Fly edge proxy → LiteFS proxy → Rails. The fly.toml settings forge the first of those links, and litefs.yml does the second.
[http_service] is a simplified way of doing [[services]]; it basically saves you the inconvenience of typing port = 80, etc. The internal_port in the documentation that you quoted is the same knob, just with different syntax overall.
[http_service]
internal_port = 8080 # LiteFS proxy will forward to Rails
force_https = true
auto_stop_machines = false
auto_start_machines = false
The terminology of LiteFS takes a little getting used to initially, but it does make sense in the end…
Thank you so much for the reply. Yeah, I am trying to get my ahead around litefs and your reply is definitely helping me.
So I tried setting the internal_port to 8080 but I am seeing these warnings and the site won’t load. Do you know what actually went wrong, cause from the doc I thought I should set it to 8080 too.
Setting the internal_port to 3000 works, but I also need to update my app to rescue from error when trying to PUT or POST to other region and forward the request to the primary using fly-replay.