I currently have multiple clients who need to be informed when a customer creates a new order. Each customer is registered to an individual client and customers create orders on my website (each order has a particular client id when created).

I'm currently using polling and each client hits my API every few seconds and gets a list of new items. This is not ideal to say the least! I would like to find a way of finding a more efficient way.

Ideally each client should be pushed/sent each new order as they come in instead of the client continually hitting my server every few seconds. Is this possible with signalR or some other technology?

If it is would signalR be able to wait for a new order then push that order straight out to the client then store the order in the database? Or would signalR be watching the database table and then retrieve a list of new orders? Would this put a load on the DB?

Any ideas would be appreciated.

  • Think of SignalR as a group chat app. That's all it effectively is. Your clients will register to receive messages (subscribe) when opening the app and, when a new order is created, you will send them (publish) a message with the order ID and summary. They receive the data over the previously-established web sockets connection and the app displays a notification of the order or whatever you want to happen.
    – Dan Wilson
    Aug 18, 2020 at 14:35
  • Thanks for the info. So it's like a broadcast system whereby a client connects to a hub and then the server publishes a message to all clients at once or it it possible to publish to individual clients (subscribers)?
    – pinman
    Aug 19, 2020 at 11:51
  • Also how can these published messages get triggered? Can you setup some trigger that would then cause a new message to be sent to a subscriber? maybe whenever an insert happens on a database table? or whenever a particular api is accessed from a customer (e.g. create customer order api)? Any pointers @DanWilson
    – pinman
    Aug 19, 2020 at 11:54
  • You create topics, subscribers subscribe to the topics which interest them, and you use the SignalR API to publish messages on those topics. You can publish messages based on anything, you just need a way to hook into the trigger mechanism. If you want to publish a message after a table insert then you'd need to use something in the database (or the service which creates the record and calls the database).
    – Dan Wilson
    Aug 19, 2020 at 12:43
  • Thanks for your info @DanWilson i've starting do some research and playing around with sample code and realised my database provider, microsoft azure, does not support sqldependancy to be able to trigger messages to clients (unless you pay ALOT for sql managed instance). Is it possible to trigger a message as the result an API hit in my scenario above? do you have any pointers to some resourses i could look at? thanks.
    – pinman
    Aug 24, 2020 at 11:33


Your Answer

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

Browse other questions tagged or ask your own question.