Best practice of using Nakama server runtime

Hi there,

I’ve read and tested some of the examples for using the runtime framework, and it works just great.

I was wondering how to structure my server code properly because I’m now utilizing your server framework to develop my first app. If you could put me in the right route, that would be very appreciated (I decided to go with the Go runtime :slight_smile: ).

  • Let’s say I’m using the wallet and storage engine API, and also accessing some external endpoints…
    So how should these modules be arranged properly? Should I make a distinct folder for
    each module, with any necessary subfolders inside, and place them all in a single folder called
    “modules” and copy that folder into the Docker container?

  • Should I use InitModule to register all of my own RPC functions in one main.go file?

  • Every time I want to test something, do I need to build a new image and run the container again?
    Or is there a better way to test my code?

  • If I want to add another column to Nakama DB, should I use collections instead?

I’m just attempting to grasp the appropriate approach from your perspective for these questions, even though the documents are very clear and useful.

Thanks for your time.

Hi @Avihu,

How you structure your code / project is entirely up to you and what makes the most sense for your project. Just as with any other project there really isn’t a right or wrong here and it mostly comes down to personal preference.

With regards to copying the modules into the Docker container I would recommend reading through our documentation that goes over running with Docker which covers how to build your Go module and copy it into the container.

  • Should I use InitModule to register all of my own RPC functions in one main.go file?

Again, this is entirely up to you. If you feel like you have a lot of RPCs and want to break it out into something separate you can pass the initializer object around and use it wherever suits your needs to register the RPCs. If you only have a few RPCS then I would suggest keeping it simple and just registering them inside InitModule.

Every time I want to test something, do I need to build a new image and run the container again?
Or is there a better way to test my code?

If you are using Docker Compose you can run the following command to rebuild the image and re-run the server.

docker compose up --build nakama
  • If I want to add another column to Nakama DB, should I use collections instead?

In almost all circumstances you should use the Storage Engine rather than try and modify the database directly.

I hope this helps.