CodingWithJamal
CodingWithJamal6mo ago

Realtime game with convex...?

So for the last few days ive been using socket.io (in rust) to build a simple 2d realtime game in react. I didnt want to use raw ws api but I also wanted control over how my data is sent. But then it made me think, could I use convex as a point of truth for my game since all clients can connect to the same query and mutate data? In my rust backend server I have the server create a room id, and spawn threads for players for each room. However in convex I could just have tables and when a game is created just add the userId to an active_game table or something. But another problem I thought about is player movements. The only way to make things seem realtime is to have updates to all player actions brodcasted to other players as well. This feels very expensive as players can trigger thoughsands of mutations per minute when playing the game... Maybe I could get away with coding a complex backend myself If I self host convex? Anyways, I really just want the community's opinion on this idea. Convex is great as a database and its selling point is realtime connections. If I was building a chess clone, this would be easier but I want a realtime game were players can move and control there 2d character and other players connected to the same game can see there movements. Which might be were my limitation is reached with convex... Either way, If I dont use convex as my core backend and write my own..I will still use convex for authenication and other site features later on for the game.
12 Replies
Matt Luo
Matt Luo6mo ago
Are you saying financially expensive? I suppose 10,000 function calls per minute is $28.80 per day in function calls expenses. It's a very large broadcast. My understanding of your use case is that the subscription updates would only happen to the clients actually watching the game, not all users of your app, right?
CodingWithJamal
CodingWithJamalOP6mo ago
Yeah the games will manually started by users and all subscribed users would see the same data and send inputs back to the server.. im just thinking the cost of using convex in this instance is too great for a game with no profit yet although i would have to write very minimum backend code. If i really wanted to publish this game, it would cost a crazy amount over time. Also it would be simple to make this game into a desktop game if I control the backend since convex does not run on all platforms (yet)..
Matt Luo
Matt Luo6mo ago
How did you get to the 10,000 function calls per minute? I guess it would be 100 chess moves a minute (across all games in the app), multiplied by 100 viewers subscripting to updates to those chess moves Actually, my math is wrong because a viewer isn't watching multiple games I think the main way you get to 10k function calls a minute is if you design some kind of dashboard experience of a matrix of live chess games, and many users use that dashboard
CodingWithJamal
CodingWithJamalOP6mo ago
im making my own version of this game. it needs to be realtime and i want to try to allow at least 50 users in a world at a time..
slither.io
slither.io
The smash-hit game! Play with millions of players around the world and try to become the longest of the day!
Matt Luo
Matt Luo6mo ago
Oh interesting. I suppose every point location change is a mutation and n subscription updates Maybe you can keep the location updates to only direction changes
ian
ian6mo ago
There are plans for cached function calls to be cheaper - so all viewers will share the same reads (if they aren't all making authenticated requests, which are each executed independently as a result)
ian
ian6mo ago
AI Town and clones are doing live worlds with characters walking around / controlled. https://www.aireality.tv/ is a notable clone that is pushing how many characters can be in one world. I will say this level of game engine does require more compute or creative tricks. for ai town there's just an action running nonstop calculating positions and publishing them, slurping up all of the inputs once per second. So there's a lag in order to keep the bandwidth low.
AI Reality TV
Join AI Reality TV, create AI simulated stories, social simulations and much more! Watch and join channels created by the community.
ian
ian6mo ago
But I think if you're writing vectors & timestamps & having mutations add new vectors it should all work out. As for economics, yeah you might want to figure out per-game how much bandwidth / function calls you might expect, and figure out how that compares to possible income (if any). If it's high, maybe you only allow users a few free games, or have a few public games, so you save on database reads with shared queries. Distributed realtime game design is non-trivial though - often involves trading off simplicity for latency/bandwidth optimization, so good luck!
jamwt
jamwt6mo ago
yes, I think a lot of these concerns would be addressed by the upcoming "scale" plan, which will offer significantly cheaper cache hits
CodingWithJamal
CodingWithJamalOP6mo ago
Thanks for the help guys, i will look into the best solution for my problems
ian
ian6mo ago
You may well find that using Convex for the game metadata, plus some optimized game engine for gameplay could be the best of both worlds. good luck
CodingWithJamal
CodingWithJamalOP5mo ago
thank you! im planning to use convex for everything except the game ws api

Did you find this page helpful?