Skip to main content

         This documentation site is for previous versions. Visit our new documentation site for current releases.      

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

Best practices for writing activities for background jobs

Updated on April 5, 2022

Ensure that work items are processed correctly and that data is not corrupted during a node shutdown by using best practices for writing activities for background jobs.

Queue processors, job schedulers, and agents are background jobs that use an activity to implement processing logic. These activities are expected to finish processing in less than a few seconds. If an activity takes longer to complete, use the following best practices to ensure that work items are not affected during the shutdown process.

Create small work items

If possible, break down large work items into smaller work items, queue them to a queue processor, and process them individually. Use a queue processor instead of an agent because queue processors provide better performance, resiliency, fault tolerance, and flexibility than agents. Scale queue processors horizontally by increasing the number of nodes configured with the node type. Scale queue processors vertically by increasing the number of threads. For more information, see Managing queue processors in Admin Studio help.

Use checkpoints

To ensure that activity logic can gracefully handle restarts without corrupting data or introducing inconsistencies into your application, use checkpointing by saving the state of jobs in persistent storage or as messages in a queue that is appropriate to the use case.

For example, consider a scenario where a work object can have the following statuses: NEW, IN-PROGRESS, and PROCESSED. You can read all of the work object records to be processed, loop through them one by one, mark the status of the current work object as IN-PROGRESS, continue with the business logic, and when processing is finished, change the status to PROCESSED.

Divide and scale tasks

If you have background tasks that can be broken down into multiple tasks that have different performance capabilities, consider dividing them and scaling each independently. Queue processors can be scaled horizontally by increasing the number of relevant nodes and can be scaled vertically by increasing the number of threads. For more information, see Managing queue processors in Admin Studio help.

Create sub-activities

Split activities into sub-activities when possible so that the state is saved frequently, ensuring that if there is an abrupt node shutdown, the sub-activities can proceed based on the recovered state.

For more information about agents, job schedulers, and queue processors, see the Admin Studio help.

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best. is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us