Should I Use An External Database (Firebase)

This is also documentation so feel free to scroll down. I probably wont upload this in the marketplace unless prompted, and I might make a video on how to setup a server and make the module work.

Hi, I’ve made a Python server and hosted it on a free sandbox website. This server allows me to send POST requests to get, delete, and post data to Firebase (Google’s database).

Uses Cloud Firestore

Which means that everything is free.
It usually takes 2-4 seconds for the data to appear (on the website directly), more in some cases. But for use it is faster. Also creating a collection requires a refresh on the website, but in reality it’s faster than it looks.

Should I be using this as an alternative for Roblox’s API Datastore service? I’ve heard it you can send more http requests than datastore requests, it’s easier to work with, edit, and look at externally, and some other good things about it. But I’m still wondering wether it’s good to use.

Here’s an example of sending a simple post request (I wont be sharing the server link though)

The code is also very easy, here is some code for a get request.

GET request
local HttpService = game.HttpService
local url = "im not giving the url >:("

local data = {Collection="accounts",Name="dwanejohnson"}
local recieved = HttpService:PostAsync(url.."/get", HttpService:JSONEncode(data))
print(HttpService:JSONDecode(recieved))
Output
> {
    ["name"]="The rock",
    ["health"]=69420
  }

Only uses post async method. (Thanks to the Python server)

3 Likes

If I wanted, I could create a new collection for every game, add a document for each player’s id, and add the data in the fields. It means I can access data from any game of which the id is present in the collections. Just by changing the Collection parameter (it takes a while for the first time you create using the request)

2 Likes

UPDATE:

You can now use :put(), :increment(), and :default() functions.

:put(name,data)

Using the “put” function you can add and replace data. Instead of simply using :post() and setting the data to be EXACTLY what you give in the data table argument, you can now just say the values that you wish to add/replace and it wont recycle all previous data.

PUT EXAMPLE CODE
local data = {money=10,gems=20}
base:put("1234567890", data)

E.g. gems is already in the fields with the value of 15, gems will be turned into 20.
But money wasn’t actually in the data already, it’s new. So we will just add money to the existing data fields.

:increment(name,data)

Using the “increment” function you can add/subtract values which are numbers. Just add the name of the field you want to increment, an equals sign to represent how much to increment. You can add multiple fields with different increments at the same time.

INCREMENT EXAMPLE CODE
local data = {money=10,gems=20}
base:increment("1234567890", data)

E.g. gems used to be 10, so gems will become 30 now. If money was 0, money would be 10. BUT MONEY AND GEMS HAVE TO BE NUMBER VALUES, OR ATLEAST BECOME A NUMBER IN tonumber().

:default(name)

This function lets you set a document to a “default” field/data value. You can set a default_name value that is inside your collection. By default, if not given, the default value will be the document named “DEFAULT”. Please make a document named default if you are going to use it.

DEFAULT EXAMPLE CODE
base:default("1234567890")

E.g. the document’s fields will be the same as the document named “DEFAULT” 's fields. Unless changed.

I mean if you really think it’s better then something like ProfileService or Datastore2, I say go for it but I was stuck in a rut for what type of database I should have in my game and I just ended up using Roblox default datastores

1 Like

Alright but it does seem easier to use cloud firestore. It opens up a lot of options, and I can also add more methods to interact with things that aren’t firebase related directly too. Roblox’s default datastores are also good, but roblox does go down every once in a while and external databases are cool.

1 Like

Alright I switched the server to a Python file, and it takes way less time. around 200-300 mbps ping time. And the data refresh is shown in 2-4 seconds.