Search Unity

Best practices when using NoSQL DBs?

Discussion in 'Multiplayer' started by ImAldu, Mar 2, 2017.

  1. ImAldu

    ImAldu

    Joined:
    Mar 6, 2015
    Posts:
    64
    Just some quick and dirty advice from anybody would be lovely. I'm mostly just gathering information currently and figured I'd ask you guys since I'm already researching.
     
  2. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    Hmm I assume by placing this in the "multiplayer networking" forum, you're referring to the use of a nosql database as a way to store persistent data for a player on the server side of your solution?

    Could you provide some additional information on how you plan to use your database? I should then be able to advise further.
     
  3. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    The general advice for DB access is to make sure that it is only accessible through an API. Don't let clients connect directly to the DB server (if there is one.) You don't want random clients (or whatever) to be able to run actual queries, because they could do anything with or to your data.
     
  4. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    Hmm okay so you're going to want to have a central server where the data is stored (separated from your game server(s)), that only your game servers can access in order to manipulate the data?

    I see the attraction to nosql here, because database engines like mongodb and such have very nice apis for manipulating application-specific data (in the form of JSON objects). However, it's more common that there would be a layer between your database and the outside world (in your case, game servers). For example, the more common approach, although obviously more work to implement, would be to implement some sort of RESTful api and/or custom web-based application in which you make https requests from your game server.

    An example could be, say your game has some sort of virtual currency, and you want to "add coins" to a player's "account". You could set up a simple web-application that expects a request to be made, either to a script or some sort of web-application framework (or even a RESTful api that you can manipulate) where you specify how many coins to add. The web application would verify the request, and then manipulate the data, therefore adding a sort of authoritative layer between the data and the outside world.

    Obviously the concern here though is in order to "verify" the request, you need to ensure it comes from your game servers. There are various ways to do this, such as using RSA keys and other forms of authentication that you must ensure are not exposed to the client-side (and are always handled over https between your game servers and your central web server). However if you need further advice on this let me know.

    It's worth noting that if you did want to avoid having a layer between the outside world and the database, you could achieve something like this if you were to use something like SSH tunneling to tunnel into your database server and effectively run command-line sql queries remotely (from your game servers for example). This would be harder to implement, and does pose some additional security risks, but it's worth being aware of the option.

    Let me know if you have any further questions.
     
  5. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    In addition to the above, there are some third party options that serve the purpose of creating player accounts and storing the related data. I personally would rather be in control of this myself (and do something like suggested above), however if you're interested in that, check out unity's Social api, and/or services such as playfab and gamesparks. (i've never used these, but found them with a quick google search).

    Hope this helps!
     
  6. GameSparks_Clare

    GameSparks_Clare

    Joined:
    Feb 7, 2017
    Posts:
    37
    Hi,

    GameSparks offers a comprehensive set of tools to help get the backend of your game up and running as painlessly as possible. Part of that includes player storage. Players data can be stored the player object itself and retrieved with a simple api call using our Cloud Code API. It can also be stored in a custom runtime mongo collection and retrieved and updated there from there. Players can pass values in through custom LogEvents and then handle the data accordingly in Cloud Code.

    You can check out our tutorial here https://docs2.gamesparks.com/tutorials/database-access-and-cloud-storage/
    And if you have any questions, please don't hesitate to contact our support team via https://support.gamesparks.net/

    Clare