API Backend for new App

6/27/2025
Loading views...

The Plan
If you remember from my previous post What next... a number game was one of my options. I've decided to go with this idea and I as I mentioned this is a bit more complicated. And it kept getting more complicated.
When I started to really think about this idea it became obvious to me that it would have to have a back end that both users can communicate with to play the game. So I began design the data model. Or I should say the first iteration of the Data Model, there were several modifications I would have to make during the development.
With the Data Model in place I could start thinking about how the users would interact with the data. They would need to start games, find another player to play with, submit thier number for the round and check on the status of the rounds and games.
With a rough idea of what I needed to make I started implementing. And I quickly realized there were a few things I needed to figure out.
What I needed to learn
I have never done anything with two users updating and reading the same data at the same time. I had to wrap my mind around how they were going to do that.
Finding another player and starting a game was a particularly head scratching question for me. I settled on a queueing system paired with a matchmaking operation that monitors the queue and when it finds there are at least two players in the queue it creates a game for those two players.
Another challenge was figuring out how the game would flow, this was less technical and more logical. I had to come up with a flow for the player to submit a number then get the result of the round. And on top of that the backend needed a game to flow too. Once a round is finished the next round has to be created so it is ready for the next numbers submitted from the players. And finally the players have to be able to see who won the game after all the rounds are complete.
Most of the figuring I had to do was around the design of the game. The implementation was pretty simple, while I don't have syntax and project structure memorized for a next.js project I could easily turn the design into implementation, especially with a little help from chatGPT for getting started.
Pros of the API
I do see a few pros of creating an API for this project, aside from the obvious of multiplayer being impossible without it.
Since I have an independent API I can create multiple UIs for this project. I can create a web version, an iOS app, or even an Android app if I really wanted (but I highly doubt I will). I do see myself making both the web and iOS app. I'll probably actually start with the web version.
With the data model and game play logic stored in the API the UIs can be much simpler and easier to create. (right?) I just need to call the appropriate endpoints and read and display the results to the users. And designing the API forced me to think about the user experience and flow, so I don't really have to figure that out any more.
Finally it was nice doing something different. I've created a few different iOS apps that have all their logic contained within the App. Getting to use a different language to write code was fun and being forced to come up with a design that had to accommodate all the challenges of a two player game was a good learning experience.
Wrapping up the API
While I would be foolish to think I won't have to go back and make a change here and there, I am comfortable saying that I have completed the API and I am ready to move on to a UI. As mentioned before I think I will start with a web app, it will be more universally available so more people can access it.
I'm looking forward to figuring out what I have missed in my design and finally having a fun game to share. Let me know if you want to play a game against me sometime, we can do it in Bruno for now!
Comments
No comments yet. Be the first to comment!