HACKER Q&A
📣 ajaxAlphaBrand

Is Firebase suitable for a realtime multiplayer game?


Hey HN, I’m making a realtime multiplayer game and it’s time for me to write the backend. I really like the idea of using a BaaS - I ideally just want to write my game’s backend logic and have everything else (spinning up servers, load balancing, containers, etc) handled for me.

I’ve been looking around at solutions online and Firebase seems really appealing to me. It’s got tons of documentation, lots of features (auth (with anonymous auth), analytics, blob storage, etc), and doesn’t seem to be one of Google’s graveyard bound projects (hopefully).

There’s some things I’m not sure firebase can handle that I would like in my game: - complex interactions in my game. Firebase seems good for easy I/O (with their cloud functions feature). You make an api request, Firebase handles the request, maybe manipulates some data in the real-time DB, and then returns you some result. Maybe it also tells a bunch of other clients that result. If a player in my game walks forward, I would make an api request to have that player move forward, the request would update the player’s location in the real-time db, and all other players would be notified and updated of the movement. Cool. But what about more complex interactions? What if a player places a bomb that explodes in 10s? Could Firebase somehow get triggered after 10s to perform an action? We can’t trust the frontend to handle the 10s timer. Or what if I want the world to be alive, with NPCs walking around. Can Firebase run a game loop like thing in the backend to have NPCs walk around? - price: if I’m constantly sending / receiving requests from clients (ex: a client moves their mouse around the screen and I want to update each other client with the position of the mouse, that would be a lot of api requests per second) and handling each of those requests in a cloud function, I feel like that could add up pretty quickly

As easy as Firebase sounds, I’m afraid I may rely on it only to realize months later that it can’t do certain things.

Any alternatives you would suggest?

Thanks for the help!


  👤 verdverm Accepted Answer ✓
I doubt firebase or the others listed here (https://meliorgames.com/game-development/back-end-solutions-...) would work for a real-time game, where we are talking tick level logic on the server side. It really depends on what you mean by "real-time game"

I've liked Dapper Dino's videos for learning about these things. Looks like he's started an updated version: https://www.youtube.com/watch?v=eymqAMmnqPg


👤 XCSme
> I ideally just want to write my game’s backend logic and have everything else (spinning up servers, load balancing, containers, etc) handled for me

My advice is to just make the game, and implement the simplest backend possible (using a basic server/VPS) without worrying about scaling at all.

What type of game is it?

> I would make an api request to have that player move forward, the request would update the player’s location in the real-time db, and all other players would be notified and updated of the movement.

You can store all this data in memory of the server running the game loop. Note that you need a server, otherwise the game would be client-authoritative, so prone to cheating/hacking/desyncs.

I would suggest creating a Node.js server on a VPS and using web sockets for communication.


👤 sebag1507
[I work at Firebase :)]

Realtime Database (RTDB) client update latency (in ideal situations) is below 100ms (blazing fast). You could absolutely track the state of the game in RTDB (e.g. players' position, artifacts, etc). You do that using the RTDB SDK and all clients listening to the same document will get updated.

For time dependant events (like bombs) you can use scheduled functions : https://firebase.google.com/docs/functions/schedule-function...

The client setting the bomb calls the function, the function updates RTDB with the location of the bomb and schedules the explosion. 10s later it updates RTDB with the explosion happening.

My 2c