Why is it that Activities were made to be pre created Singleton objects. in Temporal design ?
Conceptually, should each activity from workflow correspond to a standalone single object ?
because of this, developers should take extra care to ensure that their Activity Implementations are made Thread safe ( no modification of Instance attributes )
Once upon a time at a well-known company, I created a service framework that was creating a handler instance per request. Developers hated that. Some of the reasons:
Practically all existing frameworks share a single service handler object. So they didn’t expect such behavior.
Passing dependencies like database connection pools or service clients is not trivial. It either requires factories or some sort of context object.
Such implementation doesn’t work well with dependency injection frameworks
As handler object is created per request for a single handler invocation its instance attributes are not really needed as local variables are engouth. But it makes hard to have fields that should be shared like counters.
Thread safety is still needed for any shared objects.