More examples of the Interceptor functionality

Can interceptors be used to deal with more data instead of the sample which we have? I mean can they intercept an ID (database ID which is sent to the workflow) and based on this we can do different things within interceptor? Like reading the content of that ID from database (maybe blob as JSON) and do much more other stuff than it was presented in the log demo you have?

Yes, they can do a lot, that is just a sample.

Yes, though beware that a workflow interceptor is running with the same constraints as workflow code. So you can’t access a database, but you can invoke an activity for instance.

Interceptors are just ways to run hidden code around other more visible code. For this reason, unless there’s a good use case to hide the code in an interceptor, we strongly recommend using proper helpers that are visible in workflow code. Doing advanced things in an interceptor can be hard to reason about when debugging a workflow.

You might prefer a custom data converter for this if you want to convert one payload (e.g. a DB ID reference) to a value. But unless this is for overcoming payload limitations, it is recommended that you just do these things explicitly in your workflow. Feel free to make whatever helpers/utils make it easier for your developers to read/convert values.

Hi,

When you said workflow interceptor is running with the same constraints as workflow code, does that mean it must be deterministic and versioned?

Albert

Yes, your interceptors should follow same rules as workflows (see deterministic constraints in docs here)

Hi, can you elaborate a little on how you can get around overcoming payload limitations? If we had large amounts of data that we needed to pass between activities, how can Interceptors be used in this?

Interceptors probably shouldn’t be used for this. Rather a custom data converter may be used. You can store a reference to the data in some other data store and then re-download it as needed in the converter. However the best and most straightforward approach is to just store a reference to the data and download it as needed inside your activity.

I would advise against a custom DataConverter as well. You don’t want the large payloads to be loaded in the workflow code (even through S3 or similar blob store). This can make replaying history extremely slow. Pass references through workflow and download blobs in activities.

Another option is to cache large data in a process/host and route activities to it. This is the most efficient way.