I’m currently hosting my Shopify remix app on fly.io and looking at some hosting solutions for my database. By default this is a sqllite DB and works quite well since I only have 1 table and very little read/write.
To prevent downtime I have 1 app with 2 machines and have also set up 2 volumes for my SQLLite.
So now I have persistent data but as I understand I can have some issues because the data can get out of sync between the 2 volumes.
I.e.
Machine 1 with Volume 1 inserts record ABC into row 1
I run a deploy
Machine 2 comes up with Volume 2, while it has a valid running SQLLite it does not have row 1 from above.
Before I can into other options, is the above assumption correct? Is there anyway to keep the above simple approach working without turning into alternative?
While looking at alternatives I am seeing LiteFS come up quite a bit. Is this the answer for above if I want to stay with a sqllite world?
I am a bit unsure from reading the LiteFS how it works with volumes or if it needs them at all?
Assuming my setup of 1 app with 2 machines what would the normal setup be that both machines have access to the same data and its persistent?
Am I still creating 2 volumes with LiteFS on it, and they somehow keep the data replicated?
Still bit confused I will try and write clearer questions.
So if I go for LiteFS do I still need to have the same set up of 2 machines and 2 volumes? If a write happens on one machine it will auto add that the other volume? So sqlite file on both volumes stay in sync?
In the above setup is there a way to keep the LiteFS set up super simple since I will only always have 1 machine and 1 volume up and running and it will only switch to the second machine during a deploy? I.e. Seeing a lot of complexity in blog posts about replica nodes and a leader node etc.
Basically I am just trying to see what the easiest way to migrate from a machine + volume using normal sqlite to litefs is.
If you have 2 machines then one will be the primary and changes will be shipped to the other one. There will be some small delay—typically on the order of a few milliseconds—but it could be longer if the two machines are physically far away.
The typical setup is to run 2 machines in a region where either one could become primary and then run other machines around the world for fast regional reads. We haven’t put work into a single-node deployment where it could switch over on deploy. Something like that could be possible but there’s probably some footguns in there.
I’m happy with for my app to just be deployed in one region
In that region I have 2 machine and a volume each (so 2 volumes)
Very happy with SQLLite
If I want my data to be in sync across both volumes (because my machines will switch during a deploy) I need to switch to LiteFS.
My LiteFS setup can stay the same 2 machines and 2 volumes for the one region. What would be easiest way to allow the new machine + volume combo to be allowed to write automatically. Is this where the litefs proxy comes into play? Basically I am hoping for a simple setup like above I need to manage who can write and who can read this there will only be 1 active machine + volume at anytime if that makes sense? I just need to the 2 volumes to stay in sync
Update on this I tried to set it up today and although no errors on deploy it seems be behaving just like a normal SQLLite volume and don’t believe its replicating across all volumes.
Some questions I have.
I have created a litefs.yml as the docs suggest in the speed run (Speedrun: Add LiteFS to your app · Fly Docs) but I am unclear if I need to add this file to my docker file as well. The docs just mention the creation of the file but not if it needs to be added to the docker file as I see some other people have done.
Here is my current docker file
FROM node:18-alpine
EXPOSE 3000
WORKDIR /app
COPY . .
ENV NODE_ENV=production
RUN npm install --omit=dev
# Remove CLI packages since we don't need them in production by default.
# Remove this line if you want to run CLI commands in your container.
RUN npm remove @shopify/app @shopify/cli
RUN npm run build
# for alpine-based images
RUN apk add ca-certificates fuse3 sqlite
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs
ENTRYPOINT litefs mount
Does the above need a line to copy my litefs.yml on the machine? If so how does this current not complain…
I want to make sure all my paths are correct and if I am reading / writing in the correct folder