Integrating with websockets / SSE

I’m curious about how folks have been integrating Temporal with real-time elements through websockets and/or server-sent events.

Take the classic Uber Eats as an example. As a customer that placed an order, and started a workflow, what would be the best way to automatically update my view as the state of the workflow progresses? e.g. From order placed to perhaps, order confirmed, preparing, waiting for pickup, on the way, delivered, etc.

Here are some working solutions I have come across from similar questions:

  1. The common answer appears to be to do some polling, and querying the state of the workflow. Nice, and simple, but this does not feel quite right, and you would need a relatively low polling interval to achieve the real-time element (EDIT: looks like GetWorkflowHistory can also be used with long polling for greater efficiency);
  2. Using an activity to trigger a side-effect in the non-Temporal world. We can have an activity that pushes events to a message queue / broker (e.g. Kafka, NATS). The websockets / SSE service can subscribe to these events, and announce them to the client accordingly. This feels slightly more complicated, and ad-hocish compared to (1);
  3. Performing some CDC on the persistence / visibility store. Probably the most complex of the other options.
  4. Similar to (2), and (3), the “notification” itself can be fired from the existing activities or third party systems that the workflow is interacting with (e.g. if we have a REST API for restaurants to accept orders, the “notification” can be fired from within the handler as it is already external to Temporal)

Examining the codebase, I’m wondering if there is room for a (5), and something similar to (3). Kafka appears to already be integrated as a MessagingClient, a relatively simple interface. It is used for indexing workflows into Elasticsearch if my understanding serves me correctly. There seems to be potential here to implement, and integrate other messaging systems. Changes to the workflow can then be fanned out to various consumers for analytics, indexing, triggering other events, etc.

(Related to Execute some code immediately after workflow completion? - #5 by silmarx)

Anyway, just bouncing some ideas around, and thinking out loud.

There is no ideal solution yet. In the longer term I think we want to provide direct websocket support by the platform. Another planned feature is long poll query that would return only on result changes.

For now, I would recommend something similar to my answer here: Signalling system - Human driven workflows

1 Like