Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need advice for backend solution

Discussion in 'Multiplayer' started by stefanplc, May 4, 2021.

  1. stefanplc

    stefanplc

    Joined:
    Feb 21, 2015
    Posts:
    82
    Hi,

    As a hobby I'm building a small game in Unity. I need to hook it up to a database. The game's interaction with the database would be the following:
    - When the user first opens the game, it would grab all of their account info like achievements, currency, progress etc...
    - Every ~5 minutes or so, as the player makes progress in the game it would update their progress in the database.
    - There's a leaderboard section that players can access which sorts users by certain criteria. It doesn't load all the users at once, it looks at the player's rank and then loads 10 players that are higher than him and 10 players that are lower. Then you can load more players, ~20 at a time or so.

    I know a little bit of php & mysql and set up the functionality listed above and it seems to work fine. My question is if this is a good option for when I'll have maybe 1000 or 100,000 concurrent users (unlikely but that's not the point) or if I should use a different back-end solution that's much faster and better suited for this? For example I've learned that Instagram uses Python and it's an app with a lot of users and data, would that be better?

    Thank you!
     
  2. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    Doing it yourself using whatever backend tools you already know is perfectly fine. As a solo dev if I ever actually got to where I had 100k ccu I would definitely want to pay for a backend service at that point.
     
  3. stefanplc

    stefanplc

    Joined:
    Feb 21, 2015
    Posts:
    82
    I understand that, but I don't mind (in fact I enjoy) learning new technologies and if one is better than the rest for my particular case, I would like to learn that one. I already work as a web designer and front end developer and I have some experience with back-end solutions, I just don't have enough experience or understanding to decide what would be better for what I'm trying to achieve.
     
  4. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    I guess I don't understand what you're asking. There is no "better", you use the tool that does what you want to do. Code it yourself or use an asset from the store or a third-party service, all perfectly viable options.
     
  5. stefanplc

    stefanplc

    Joined:
    Feb 21, 2015
    Posts:
    82
    Alright, thank you! What I was confused about is that if for the actions that I described above, say php & mysql were a better option than python & postgresql for example in terms of let's say speed as one characteristic. But if they're all the same and php & mysql should do the job just fine, then I'm all set!
     
    toddkc likes this.
  6. Chris_St

    Chris_St

    Joined:
    Apr 25, 2018
    Posts:
    19
    Hi.

    I hope it's ok to go a bit offtopic in your thread, but i'm a bit lost and maybe i can avoid making an extra thread.

    I'm learning Unity/C# for some months now and i'm in the middle of designing my first game.
    Now i want to make a simple leaderboard. I learned a bit about databases and that stuff about 15 years ago, so my knowledge is kinda...0 :D
    Can you maybe point me in a direction where i can learn about the very basics, like getting the right web host, what tools/programs i need to edit stuff in the database, how to then code it in C# to access the database etc etc?
    I'm a bit frustrated because i don't really know where to start my search, therefor i don't know WHAT to search and so on...

    Would be great if you have some adivce :)
     
  7. stefanplc

    stefanplc

    Joined:
    Feb 21, 2015
    Posts:
    82
    I'm not an expert so I can just tell you what I've done. I'm using php to send and get data from a mysql database. So that would be the first thing that I would learn, just look up some basic php and mysql tutorials (for web design) and for the host I think just about any shared hosting that supports php and mysql should do which should be most of them. You'll also need to connect your host to a domain name and that's something that the hosting company's support team can help you with.

    Now to get and send data to the database from my app I just access custom URLs at my domain. Unity has some methods for that, you can see more at https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html or just google UnityWebRequest.

    So for example if I wanted to do a login, I would access the URL www.mygame.com/login.php?username=John&password=abc123, and then the PHP script inside login.php would check the credentials against the info in the database. Then the PHP script would print one of two text strings "correct" or "incorrect". I would check the text string in C# and if the string is "correct" then the login is successful.

    Now you don't want to access an URL like the one I described above, because someone could be listening to your HTTP calls and have an easy time learning your password or other sensitive data, so I would look into some sort of a encoding such as MD5 so that your link looks something like www.mygame.com/login.php?90as8d0a8sd09a8sd09a but your PHP code will know to translate it into www.mygame.com/login.php?username=John&password=abc123 With PHP you also need to look into security measures to avoid things like "sql injection" for example so it's a bit more work.

    And that's the gist of it, if you want to do it how I've done it. As far as I know, there are 3rd party solutions that are either free or you can pay for and those do all of the hard work for you, but I don't really have any experience with them and I felt a lot better having all of my game's data in my hands.

    Hope this helps!
     
    scsltd and Chris_St like this.
  8. Chris_St

    Chris_St

    Joined:
    Apr 25, 2018
    Posts:
    19
    Wow, thanks a lot for the detailed answer, that's exactly what i needed.
    Some keywords and what to do first/second/etc.

    I feel like that too. Also in this case i think it's good to know what's going on before using a tool.

    THANKS again, i'll dive right into it :)
    Have a great day!