api – WebApp architecture with multiple client


I’m investigating how I could achieve a project I’ve been thinking of for a while. Let me explain the project (I will not go into too much details, but I think what I’ll write will be enough).

So, I am planning a WebApplication that, once opens, allow the user one of two options:

  • Creating a room (Host);
  • Joining a room (Player);

Suppose the host creates a room with its setting; at the end of the setting form, a screen with something like:

Room uniqueRoomID has been created. n Players are connected, wait for others.

Now, the players kick in. Suppose n players join the room:

  • The host will now have a different screen, showing information about the room;
  • Each player will have its own screen, with its own information;

From now on, you can think of a poker game: any player can make a call, based on the previous one, until everyone leaves. The first “match” has finished, so it starts the second and so on, until a total match of x have been played.


Hoping I’ve explained enough what I need to achieve, here what I think:

  • I need a server running somewhere (let’s say a node.js server, so I use JavaScript even for the server). Suppose I have the server running on 123.456.789.123;
  • When the host creates a room, it communicates with the server, for example by fetching the URL 123.456.789.123/API/create-room; at this point, I was thinking of adopting PubSub pattern: the call let the server creates a new topic TOPIC_RoomNameId, and return OK to the host;
  • Now, all the clients must execute the fect 123.456.678.123/API/join-room/RoomNameId: this will lead them to subscribe to the topic created from the host. Question here: I think the subscription should be executed from the player itself, and not the server, right?
    I mean, the fetch on API/join-room should return OK if the room exists, and then on the OK response I execute the subscription from the player… Right?
  • At this point, whenever a player makes a call, it sends a message to the server, which then will publish something new on the topic, alerting all the players about the new call;

So, if you have reached this point of the question, here’s what I was thinking to use:

  • Ionic and REACT, so that the WebApp can be published in mobile stores, besides being used on Desktop and browsers;
  • Using Node.js for the server. Then, I should host it somewhere. I’d like to use AWS or Google Cloud, but maybe they are an overkill;
  • Using Socket.IO (https://socket.io/docs/rooms/) for the PubSub pattern;

Of course, I still don’t have any code to show, I’m planning the architecture of the WebApp. But now, after have written all you need (or at least, I hope this is enough), here’s some questions:

  • The idea of using PubSub pattern is ok? Because I can see that I could also have a client-client connections, making the clients communicate between them.. But I honestly don’t understand how could I know the addresses to which send the messages. Without a Server, I don’t see how this could work.
    Notice that the players are different devices, thus different people in different locations;
  • Again, any idea to where I could host a server like the one I would need?
  • I’m afraid I’m missing something like keeping the state of the room. Suppose a player closes the browser: it loses everything he has done so far, and can’t recover that! So, it seems to me some kind of storage is needed.
    I don’t know if I could store everything in the server like having arrays (I mean, if the application will be used by me and my few friends I suppose this is OK), or adding a Database that will store any kind of information about the room/player/anything else;
  • Regarding the point above, I guess I would also need some kind of logic for each player, otherwise even if I save the data in the database.. How could I link data to players? 🙂

Thanks.