This is a demo for dynamic countdown.

All the magic is on the backend, this is just timers

Similar to current implementation. This value is inititally passed by backend API and then counted on the frontend. There are no refreshes when the value is updated.
This value is being streamed every second via websockets.

Loading...

This value is:
  • 1. Initially passed by the backend(via websocket)
  • 2. Counted on frontend
  • 3. Synchronized by websocket every 10 seconds.
  • This approach is essentially an optimization of the websocket technique. The backend is hibernated, and woken up via alarm API every 10 seconds to update the value.

    This value is served to the client whenever client explicitly asks for it via a websocket(and on initial request). This approach seems to have the most sense, as it allows for hibernating the websocket, and pushing the updated values either on change, or via an explicit request by the client.

    NEW: The value is saved in transactional storage, so it's "ressurected" whenever a durable object goes out of memory.

    What might seem uintuitive, is that even the value refreshed every 10 seconds updates right away when you update the countdown. This happens because we're fully leveraging what websockets give us - which is we can just send the updated value right away. The only value that we cannot update dynamically is the fully client-updated one.