Database Integration advice

I’m a student taking a Database course, and we have a final project where we need to make a database, or use a new database technology, or do a research paper. I’m really into game dev, so I thought it would be cool to combine the two and try to integrate a db into ue4 that I could use with games. I’ve seen some good suggestions, but no great documentation, just not sure if I’m looking at this correctl. SQLite I could not find any documentation for UE4, other than one youtube video, or just flat out plugins, but it kind of defeats the purpose of the course if I’m using a plugin. MongoDB was the other suggestion that I saw. I don’t see any UE specific documentation. Would I just create a C++ class that doesn’t derive from anything, and write it as if I was writing a regular C++ class? I see MongoDB itself has pretty good documentation. But then how would UE interact with it? And what would even be worth storing in a db when considering game dev? Any advice appreciated.

Probably the first decision you have to make is about the client/server setup. Does it make sense for the DB server to be hosted on a separate machine/server, and then when you (or any other player) run the game, your game application connects to the DB server as a client? Or would it make sense that your game starts the DB server itself, locally?

If putting the DB server on a separate, central machine, would it be better if you develop a web server around it so that your game communicates to the web layer, instead of connecting directly to the database? Again, in this relationship your game application would be acting as a client, and you have a server to respond to its requests. In real case scenarios usually this is how it goes, rather than connecting to a central DB directly.

If all you need is basic, in-game data storage, then you don’t need to host the database server separately. And you would certainly not need to develop a web API around it.

These are all architectural/design decisions that depend on your needs. It is worth thinking about requirements, and what makes sense for your data.

Okay so say it was an online game. I would need to create a RESTful API for the client to interact with, and then that API would interact with MongoDB? Or is MongoDB secure enough to interact with directly? I’ve just seen people in other forum posts say that you shouldn’t allow the client to directly interact with the DB. From looking at a MongoDB tutorial it seems I would use Node.js to setup this API. I understand how the API and MongoDB interact with one another, but I’m unsure of how I would have UE and the API interact?

Perhaps I can attribute the desire to develop an API layer between your client (a running instance of your game) and the DB as the following:

  1. Your needs are usually a bit more than just reading/writing data directly from/to the database. There is usually some processing or validation logic that should happen in-between. And that’s something your API layer can easily handle.

  2. If you want your game to directly work with DB, then you would need to pull in the relevant DB client binding into your game. Not saying it’s not doable, but comparing this with having your game talk to the API layer, the latter seems like a more desirable implementation. Unreal already has the infrastructure for you to use for sending requests to your API layer.

  3. Perhaps the most important reason: If you only expose an API layer to the outside world (public) rather than your whole DB, then you are only revealing a limited surface of access. If your database is directly accessible publicly (even with proper security of course), you are putting your whole database at risk by making it accessible. This is another very important reason to encapsulate your database behind an API layer so the only means of getting to database is through the API layer. Effectively limiting the attack surface.

Now, with regards to the technology you want to use for your API implementation, you can use anything you are comfortable with, that is supported by the database you are choosing. You can use C++, C, Java, Go, Rust, JS (I mean NodeJS), and many others. The beauty of it is, no matter what technology you use for this, the API interface can look the same to your client (game instance). So the way you would call the API can remain the same. Hence, I suggest you pick something you are comfortable with to make it easy.

And P.S. your API still needs security. So your game should have a means of authenticating with it.