Architecture – statistics or profit give away result of the game

Imagine a coin flip game whose logic looks like this:

  • The server sends a websocket message (RESULT_MESSAGE) to the frontend resulting in a game (won / lost).
  • The server sends a Websocket message with updated aggregated statistics (STATS_MESSAGE) to the frontend.
  • The frontend responds to RESULT_MESSAGE with an animation (coin toss). In addition, the all-time statistics and the gain are updated in response to STATS_MESSAGE

The problem with this logic is that responding to STATS_MESSAGE (gain and statistic update) betrays the result of the coin toss before the animation finishes.

Solutions I can not use:

  • Merging RESULT_MESSAGE and STATS_MESSAGE updates only the statistics / wins after the animation is completed. Because these 2 messages are generated and sent by different services.
  • Associate a particular RESULT_MESSAGE with a STATS_MESSAGE and respond to a STATS_MESSAGE only when its corresponding RESULT_MESSAGE has been processed and its animation completed. Because in reality I have several types of STATS_MESSAGES (trophies updated, statistics updated, earnings / balance updated etc.) and it is simply not practical for the frontend to keep all these messages until their respective RESULT_MESSAGES are processed

Solutions that I've already tried, but I try to avoid:

  • If the backend sends STATS_MESSAGE with a delay, it ensures that it does not reach the frontend before the coinflip animation completes. This type encodes the behavior of the frontend (animation) in the backend.

All ideas and suggestions appreciated. Many thanks!

How do I update a NoSQL database and publish an event atomically in an event-driven microservices architecture?

In an event-driven microservices architecture, services typically need to update their domain state while publishing an integration event on a service bus (either completed or not completed). When using a relational database, this is usually accomplished by using the Outbox pattern: the database stores a single entry indicating that Event X needs to be published. This entry is saved as part of the same transaction that contains the domain state changes. A background process queries these entries and publishes the events. This means the event will eventually be published, eventually making the system consistent.

However, NoSQL databases do not support the idea of ​​updating multiple documents in a single transaction, and many of them do not support this without ugly workarounds. Below is a list of possible solutions (some uglier than others):

1. Deviation of the postal issue pattern:

Outbox patterns, but instead of having a separate collection of pending event documents, are stored as part of the domain entity. Each domain entity encapsulates a collection of events that still need to be published, and a background process queries those entities and publishes the events.

Disadvantage:

  1. If the background process publishes the event, but does not remove it
    It is republished by the domain entity. This should not actually be a problem if updates are not essential or the event handler can identify duplicate events.
  2. Domain entities are
    damaged by integration events.

2. Event Sourcing:

Event sourcing addresses this problem, but is very complex to implement and requires a lot of effort for small microservices.

Disadvantage:

  1. Complex, it may be necessary to completely revise the way services work with data.

3. Listen to your own events:

The service publishes only one event that is also subscribed (it does not update its status as part of the same operation). When the service bus returns the event for treatment, the service updates its domain entity.

Disadvantage:

  1. Other microservices can handle the event before the original microservice. This can lead to problems if it is assumed that the event has already occurred, although this is not the case.

Are there any other solutions to this problem? Which is the best?

Networking – Dynamic Game Server Architecture

I'm trying to find a way to design a game server architecture for a real-time mobile game. The design should be inexpensive, but still scalable to a degree (later).

Mobile client data flow:

Connects to a distribution server provided by DNS LB and grouped with x players. When your players are reached, the distribution server must contact a control server that starts or uses an already running game server. The control server sends the IP and port back to the distribution server, which then sends them to the grouped players.
The players then connect to the specified game server. After the game, players are sent together to a new or the same distribution server.

I'm wondering how the real server (VMs) for the game servers can be managed in a dynamic matter.
I've looked at AWS EC2 instances, but if we have 500 players with 6 players per group playing 6 hours a day, we need ~ 84 EC2 t3.small instances (2 vCPU, 2GiB RAM). This costs about 1,160.00 USD per month. At this price, it would be nice to have real VMs and no dynamic cloud instances, I think?

Enter image description here

Explanation of the components

distribution:

Mobile clients connect to them to group with other players. It's like a lobby where the players sit until X players are reached or z. a countdown started.

Control server:

You need to take care of the started servers (VMs) and edit the startup requests of the game servers from the distributors.

Game Server:

Is an authoritative server client with physics, etc. A game server (software) for X players in a group. Players will join the Distributor after the lobby "Phase".

Question:

How can this be dynamically scalable / cost effective and is this a usable architecture?
I see a problem with the control server because it has to handle N game servers, VMS and N distributors. However, as we scale the control server, each control server needs to know the same thing as anyone else.

(If anything is missing or can be improved, please let me know English is not my native language, so it is a challenge to express my goal in such a complicated subject as this one.)

Architecture – Business rules in the frontend

We'd like to develop an IoT app with some editable business rules, but I'm not sure what limits BR has. There are several types of rules we want to manage, for example:

  • We group several sensors into a cluster. If the X-sensors are in status Y, we would like to send an e-mail and turn on a lamp that turns the color to green. If the Z-sensors are in status Y, we would like to set the lamp to red and send an e-mail.

  • If the sensors send a low battery status … then we would like to create a ticket

  • Many other rules that a user can imagine

We think about the possibility to pre-set some business rules. For example, we group the sensor into a cluster and define an e-mail address and a lamp for each sensor group. In this way, we want to be able to define some (growing) rules as freestyle and some predefined rule sets.

We use React and want to have a kind of rule engine (FE and BE). What are the "normal" conditions for such a thing?

c method returns different data depending on your Android architecture

I've created a library for Android and a method that returns the milliseconds of the epoch date. I tested it on 2 different architectures to see if the returns were correct.

  • armeabi-V7A: Returns a negative number that is not an epoch
  • arm64-V8a: Return correct

Check if the data types could affect the return and try to return with long long and have the same problem.
I use clang (llvm) for cross-compilation and pass the build parameters according to Android's standalone toolchain and ABI.

Build parameters

    target thumbv7-linux-androideabi -march = armv7-a
-mthumb -mfpu = vfpv4-d16 -mfpu = vfpv3-d16 -mfpu = neon -softsoft-float

method

#include 

long getTime () {
struct timeval tp;
Gettimeofday (& tp, NULL);
// Calculate the milliseconds of epoch date
long ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
return ms;
}

c ++ – architecture of the networked game engine

After working on my game engine for 2 years, I decided to enter the network environment. I just do not know if it's a good idea to rewrite the engine or how much work it will cost (but I'd like to try anyway). I'm a bit confused by some approaches, that's why I'm here.

In short, I have an architecture like this:
There is one main object that controls the entire engine world (physics steps, rendering, audio, input, entities). Then there is a game instance that runs in the loop and "creates the content of the game".

I already started with ENet and created a small console chat app – but packages were just strings. But I'm not sure if I understand the concept of game networking. Here is my idea:

There is a server and clients. The server controls everything. Client sends messages.

So basically:
When the client connects to the server, the server creates a new entity. For example, if the client is & # 39; A & # 39; presses, a packet is sent to a server containing this information. Server will process it, moves the entity.

I'm right?

The clients basically have nothing but the input controller and the keyboard. So if you press keys, the action is complete. And render rendering for the scene, but all they receive is just a "picture" of the scene from the server? Or is there something I miss?

Thank you in advance.

Edit1
And you also wonder if everything, like the physics manager or the whole scene with entities, exists only on the server?

Architecture – Improve message routing in the Outbox pattern to reduce duplicates in event-driven systems

An attempt was made to implement the outbox pattern for an event-driven system. The outbound pattern allows you to ensure that system events are sent to the event log / queue / bus at least one time (here loose with the term Eventbus):

A separate process that regularly checks the contents of the outbox and processes the messages. After processing each message, the message should be marked as processed to avoid retransmission.

Enter image description here

My concern is to reduce the likelihood of duplicates because:

It is possible that we can not mark the message as processed due to a communication error with the Outbox.

In this case, the same message is sent again after the connection to the Outbox is restored.

The proposed solution is idempotency, which is fine for me. But does it make sense to at least improve message forwarding and reduce the likelihood of duplicates? Are there patterns to improve message delivery? If not, I think of the following:

Use 2 tables:

  • output table (stores messages that you want to send to the event bus)
  • Publisher Table (saves messages already sent to the Eventbus)

Pseudo-code for Worker reading the OutboxTable 24/7:

go through every message ...

if the article is being edited (by other workers)
- skip

if the item in the PublisherTable is marked as "published" (ie, a former co-worker could post the event but for some reason does not "confirm" it in the OutboxTable)
- mark the item in OutboxTable as "published"
- skip

if the article has never been edited or edited, but has not been published
- Mark element in PublisherTable as "processing" (so that other employees can skip it)
- Publish articles / send to the event bus
- Mark the item in PublisherTable as "published"
- mark the item in OutboxTable as "published"

(Each running process has a defined time limit that other people use to skip or process the article.)

What I am summarizing here is that I have essentially created my own mini message queue to accomplish this. However, since there is no way to perform an atomic transaction between a database and a real message queue, this approach makes sense.

So my question is, are there any patterns that resemble those I'm trying to do?

Architecture – What are the best practices for designing a database to deploy multiple apps in an ecosystem?

To clarify the question here is the scenario. There is a web app that implements the RESTfull API with JWT authority. It runs on PHP / mySQL in the background and Angular2 in the foreground.

Then comes another app that would need to use the same user credentials as the first, but has its own context. Over time, the two apps will integrate more and more with each other, with the exception of authorization and subscription payments, to what extent they will integrate with each other. Think of the Atlassian ecosystem as a comprehensive example of integration and account management.

How would you build the database and APIs in such a case?

Information Architecture – Are tabs and / or steps in a wizard displayed as separate fields in a Sitemap chart?

I'm creating a sitemap for a business application.

For a section in the application, there is a function to edit the calendar. Once you have clicked on it, you can set up three sections / or different types of calendars.

  1. Start / end date for the entire project
  2. Excluded dates (holidays and days off, etc.)
  3. Start / end dates for specific tasks within the project

We are currently using a step wizard to edit the calendar so that the user has to set up the data in that order.

Will I mark each step as a separate box in my sitemap, or would that be done on a separate user flowchart?

Sitemap Sketch