1

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.

  • Does it make sense to send all the clients updates about all orders? Would/should they be able to view these orders? It seems unlikely you want to broadcast this but I don't fully understand the intention here. – JimmyJames Feb 14 at 16:39
  • Obviously not all clients can see all the orders. But my idea is to send only a warn with the ID of the ORDER that is changed and if one client that receives this warn is on the detail page of the order with the same ID it can refresh the info. But I never worked in project like this and I don't know which is the best practice. – Christian Cascone Feb 14 at 16:45
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.