Pergunta

I'm working on a project that involves online purchases. I have my web api in C# and my client in REACT (javascript). Server and client are connected with SignalR. I want that when an ORDER is changed all the clients that are watching the details of the order receive the warn to refresh the page.

My question is: which is the best practice to do this? Is better to send a warn with the ID of the order to all clients? Is better to save on the server which page are watching a client and after send the warn only to the clients that are watching the specific order?

In production environment there will be a lot of clients and a lot of simultaneous orders (I hope :D ) and I don't know which can be the best practice.

Foi útil?

Solução

It seems pretty clear that it's preferable to deliver messages only to the clients that are interested in them. For one the other clients perhaps shouldn't know about orders that they are not involved in. The other factor is that as your client base grows, the amount of messages grows at an unsustainable pace.

Let's consider an example under these assumptions:

  • A customer places 100 orders a day on average
  • There are around 10 clients watching orders per customer
  • Each order goes through 5 state changes that you need to alert upon

With a single customer, that's (100 * 10 * 5) = 5,000 messages you need to send a day. Now let's say you have 100 customers. If you send only messages to clients that need them that turns into 500,000 messages a day. Now consider if you send every message to all the clients: that's (100 orders* 5 updates * 100 customers) = 50,000 updates that you need to send to (100 customers * 10 clients) = 10,000 clients. That's 500 million messages or a 100,000% increase in messages. The growth in this situation is quadratic. Each new customer increases is not only more expensive to support but also increases the cost of supporting all the existing customers.

Licenciado em: CC-BY-SA com atribuição
scroll top