Quering workflow persisted data and restarting workflow from where it got terminated

Hi I am new to workflow orchestrations and temporal.
I would like to design workflow using java sdk of temporal which would run for many users. Basically my requirement is that let say a workflow instance for a particular user was in running state and had executed 2 activities out of 6 registered and then got terminated. Now all these events are stored and can be seen in temporal ui. Well I have 2 questions here
a) Is there a way to query state of a workflow using rest apis so that we can get data programmatically.
b) Is there a way to start the workflow for that user exactly at the point where it got terminated. For. example in above mentioned use-case the restarted workflow will now start execution from 3rd activity.

@yesadi Thanks for your interest in Temporal!

For a) you can define rest endpoints that query your workflows (call your workflow @QueryMethod methods), see example here: https://github.com/tsurdilo/temporal-patient-onboarding/blob/main/onboarding-app/src/main/java/org/acme/patient/onboarding/OnboardiyoungResource.java#L38
If you are looking for the workflow execution status, you can use DescribeWorkflowExecutionRequest, something like this for example: Util method to get workflow execution status · GitHub

For b) In most of the cases it’s best to not to fail but to utilize retries until the failure is fixed, meaning that if you have to reset your failed workflows in most cases you have a bug in your workflow to begin with.
There are tho two ways to do what you are looking for I think:

  1. Use Temporal cli Temporal CLI - tctl | Temporal documentation
  2. API using ResetWorkflowExecutionRequest (service gRPC api here: ResetWorkflowExecution)

Hope this helps.

Thanks @tihomir , I will be going through the link you shared in detail. Just clarifying on part b) Actually what I hope to achieve is let say user comes and a workflow starts. After 2 activities he/she could leave and may come back later. So at later instance I wish to start workflow from 3rd activity. Workflow restarting in this case is purely on need basis and not necessarily due to errors.

Also c) Is it possible to have separate dedicated services (may be hosted on different server) for activities. I would like my activities and workflow distributed across micro services.

Thanks @tihomir , I will be going through the link you shared in detail. Just clarifying on part b) Actually what I hope to achieve is let say user comes and a workflow starts. After 2 activities he/she could leave and may come back later. So at later instance I wish to start workflow from 3rd activity. Workflow restarting in this case is purely on need basis and not necessarily due to errors.

I think there is some misalignment in terminology here. In the Temporal model, this is not “restarting” a workflow, it is just continuing its execution normally. After two activities are executed the third one is scheduled, but it can take as long as necessary to execute. Another option is to model interaction with the user using signals. So workflow can be blocked as long as necessary waiting for a signal from the user.

Also c) Is it possible to have separate dedicated services (may be hosted on different server) for activities. I would like my activities and workflow distributed across micro services.

Yes, it is absolutely possible. The idea is to use different task queues for different micro services.

Thanks @maxim for the clarification. Let me try and come back in case of doubts.