Realtime communication between canisters and clients

Hi guys,
I was wondering if anyone has discovered a way to communicate in nearly realtime between frontend and backend canisters ?
Or if there is a way for the canisters to notify clients ?
It would be great to have a Websocket or Server Sent Event like connections between canisters and clients to push data to clients.
Have a good day !

1 Like

There is a pubsub pattern for subscribing data from canister: https://github.com/dfinity/examples/tree/master/motoko/pubsub. But due to the latency of inter-canister calls, it’s not realtime.

You can also pull the state by sending a query call to a canister. This gives sub-second latency. If you have lots of clients writing data to the canister, you can also use WebRTC to synchronize on the client side, and synchronize with the canister for ground truth from time to time.

5 Likes

FWIW I’ve hit the same wall when creating a POC chat application. I’ve eventually resorted to polling, but the disadavantages of that approach are obvious.

Given that Motoko as a language does not support any form of network IO other than what is implicitly provided by the IC (eg no socket communication), this might just be a limitation of the platform and/or language as of now.