Designing Activities

We are getting started with Temporal to do a major rewrite - I had a question regarding designing activities (which are executed by the workers). Most of the documentation I have seen points to the fact that these activities always call an http or a grpc microservice.
I assume that technically it is also possible for the activity to directly access a db or any store to mutate a state but is it a recommended approach or is it recommended to execute all logic in a microservice and let the temporal activity orchestrate it ?
Any guidance or best practices recommendations would help.

I got this answered in the slack conversation - posting the link here for others’ benefit

Capturing all the replies here in text -

[Rob Zienert]
Activities can do whatever you like.

[Balchu]
IMHO plus the fact that one can have an activity instance separate from the workflow instance, having the activity actually do the work, say CRUD actions will be a better approach.
First and foremost it doesn’t incur extra network hop of calling that other microservice. (edited)

[Sagar Jadhav]
Thank you [@Rob Zienert] & [@Balchu]- just one followup question - of course every choice is a tradeoff - but curious to know how db connections and cache operations are managed when all the workflow and activity code is structured together

[Sagar Jadhav]
Ofcourse Connection Pooling and Transaction Mgmt will come in to play in order to productionalize it in case we execute all those actions from the activity itself (edited)

[Rob Zienert]
Do you mean db connections & caching of Temporal itself, or of application space code? (edited)

[Sagar Jadhav]
No I mean - let’s say for example - there are three activities in a workflow which basically update some sort of application state (not the temporal ecosystem)

[Sagar Jadhav]
so yes application space code

[Rob Zienert]
In that case, the answer there is completely dependent on the needs of your application(s). Temporal isn’t a factor.

[Rob Zienert]
You can think of an activity as an endpoint in a microservice. In fact, we have entire services that only expose their functionality via activities.

okay cool - thank you [@Rob Zienert] that helps

2 Likes