I want the state of the game to be shareable via following process: Player A presses save -> a JSON is saved onto my server -> A link is generated and shown to Player A -> Player A shares that link with Player B -> Player B clicks that link -> The game is loaded with the state of Player A
So the only interaction between front- and backend would be saving and loading that one JSON. My problem is: To me, the web might as well be magic, and I'm a bit overwhelmed with how I can get the ball rolling.
I think my options are:
A) Amazon Lambda + a S3 bucket (appeareantly this is somehow the cheapest and the most expensive option at the same time?)
B) Renting my own VPS and interacting with it through a REST API (I think I would need a managed server rather than a web hosting option, right?)
C) Something like Google Firebase/AWS Amplify
I feel like option B would be the old-school way of doing things and a good way for me to finally overcome my web-phobia, but do I really need to pay 50€/m to host a game that probably nobody every will play?
[1] https://developers.cloudflare.com/pages/platform/functions/
[2] https://developers.cloudflare.com/workers/learning/how-kv-wo...
[3] https://pages.cloudflare.com
Cloudflare offers generous free tiers, so you shouldn't have to pay anything.
I find Cloudflare's ecosystem much, much easier than all of the alternatives for simple projects. It's fast, the UIs are nice, the docs are great, and everything is usually deployable straight through GitHub and simple configs.
Other than that, I'd self-host it, either on a cheap VPS or just a rasperry pi in the closet, this way you avoid thinking about all the cloud stuff and won't be surprised by some massive bill because something went wrong, writing a backend in nodejs will feel very familiar to you if you've already used javascript or typescript before. For storing the state, it depends how much data you expect.. I'd see how far I could go with just keeping an object in memory and serializing that to a text-file.. or you could use sqlite with nodejs, then you don't need to administer a separate piece of software, it can simply be a nodejs module.
edit: to clarify, you don't need a server at all for what you're doing, just a database with an API, which (as I understand it) is what Firebase and Supabase offer. Firebase in 100 seconds by the Fireship channel: https://www.youtube.com/watch?v=vAoB4VbhRzM
Setup a VM. Install SQLite and caddy on it. Choose an async server framework Node or python quart or something.
Add a table to your SQLite, saved_games(id,json). Add two endpoints, save and load, save generates and Id saves json and returns a link, load returns the json. Make sure there’s an index on the id too.
Run your server, for example via Hypercorn if you’re using Quart or equivalent node prod setup.
Set up caddy to reverse proxy port 443 to your running instance. This gives you HTTPS
There you go. Quite simple and fast.
You could probably serve upwards of 1k QPS with this setup. That’s about 1/100th the qps of Google search.
You could try compressing the json before storing it too. Once you have some saves a dictionary compression would be really effective on a particular json format.
Edit: I've adapted my code example to your usecase here: https://github.com/void4/jsonserver/
You should probably set data size limits
Let me know if you need to know more, sounds like a fun project!
You encrypt and dump the JSON object to a site like https://hushfile.it/ — the download link has the decryption key as part of the URL:
https://hushfile.it/2f5998db28974#5KQPcgUzQdrQmjPHoXYcwxeiW3...
Now you don’t leak game state, and anyone with the link can access the game state and send a new game state back.
There’s a few AWS-sponsored workshops. It’s pretty cheap for low/medium usage.
Amplify is a nice wrapper and will give you some level of authorization if you’d like (using AWS cognito underneath).
Like you say everyone will be biased towards what they know.
^ my tendency is to take detailed steps using the console so that it’s possible to reproduce. And avoid infrastructure as code until you really need it.
You can leave the bucket fully redable / writable by anyone, or limit who can do what.
Player A would upload the JSON to it and get the shareable URL: ================================================================== import { getStorage, ref, uploadString } from "firebase/storage"; const storage = getStorage(); const storageRef = ref(storage, 'some-child');
const state = '{foo:bar}'; uploadString(storageRef, state) .then((snapshot) => { console.log('Uploaded the state!'); return snapshot.ref.getDownloadURL(); }) .then((url) => { console.log(`Shareable state url: + ${url}`); }) ====================================================
And Player B would simply HTTP GET the shared URL.
If you pick Supabase, it's Postgres with a web api and sdk on top. Then, sure you can serialize all the game state as a jsonb record. You don't even need to deal with authentication if you don't care about isolating games.
Free tier until you make money somehow and then pay the 25/mo.
6-12 bucks will get you a more than powerful VPS, and Amazon S3 will be pretty cheap for this and allow you to set a policy that all storage expires after n-days, which will prevent this for exploding too much.
S3 is expensive for storage, but you are dealing with data at the kilobyte level, where it does not matter.
I would take a look at y.js if you are building shared state - https://github.com/yjs/yjs
just make sure you understand how billing works. mostly it’s just egress bandwidth expensive, alarms and monitoring good. also 2fa is non optional.
do something like this:
https://github.com/nathants/aws-gocljs
or with less opinions:
https://github.com/nathants/libaws/tree/master/examples/simp...
welcome to cloud, glhf!