7 comments

[ 3.1 ms ] story [ 28.2 ms ] thread
Hi everyone, I'm the author of this article. Let me know if you have any questions or comments about this. You can play the game mentioned in this article here: https://quest.ably.dev/
So, how's the state is synchronised?

Are clients both publishing and subscribing? How do you make that work?

Good question, the flow is like this:

1. Clients trigger HTTP function endpoints (add a player, do an attack).

2. Centralized state is being updated (based on Durable Entities).

3. The Azure Functions publish messages to the realtime channel (via a REST based client).

4. Clients are subscribed to the realtime channel (using a WebSocket based connection) and respond to the messages (update player health etc).

So clients are only subscribing to messages that the Azure Functions are publishing.

Got it, thanks. So clients use REST, which triggers a publish?
Yes, the Ably REST API is used within the Azure Functions to publish a message. The Ably platform then uses WebSocket connections to the connected player devices to deliver the messages.
Are WebSockets used in the Azure Functions?
No, since the functions are short-lived it doesn't add much value to setup a WebSocket connection. You could choose for the premium tier or even a full AppService tier for Azure Functions and then you do have instances that are staying alive. But in my opinion that makes it less serverless.