# Staggering Workflow Enrollements

**URL:** <https://community.hubspot.com/t/staggering-workflow-enrollements/114570>\
**Category:** Lists, Lead Scoring & Workflows\
**Tags:** enterprise\
**Created:** [August 15, 2024, 3:43pm UTC](https://community.hubspot.com/t/staggering-workflow-enrollements/114570 "2024-08-15T15:43:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KLallemont](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@KLallemont](https://community.hubspot.com/u/KLallemont)\
**Post date:** [August 15, 2024, 3:43pm UTC](https://community.hubspot.com/t/staggering-workflow-enrollements/114570/1 "2024-08-15T15:43:24Z")

</div>

I’m working on a workflow that uses custom code to send a get request to check if the contact phone number in on the DNC registry. It will work if I send small amounts of agents through less that 200 but as soon as I send more that it come back with a error 504 Gateway Time-out. Online it says this is probably because I am sending to many through at once. So I have been just sending through small section through manually, but this is is not a good long term solution because we have many contacts to run through. Is there a way I can make my work flow send only a few through at once? Like staggering them so they dont all go through at once?

---

<div class="post-metadata">

**Author:** ![karstenkoehler](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/karstenkoehler/32/68554_2.png) [@karstenkoehler](https://community.hubspot.com/u/karstenkoehler)\
**Post date:** [August 15, 2024, 3:47pm UTC](https://community.hubspot.com/t/staggering-workflow-enrollements/114570/2 "2024-08-15T15:47:15Z")

</div>

Hi @KLallemont,

Yes, the best way to currently do this is as follows:

- Before the custom code, add a branch, ideally random distribution
- In the first branch place your custom code
- In the second branch add a five minute delay, then use “Go to action” to jump to the custom code
- In the third branch, add a 10 minute delay etc

If your subscription doesn’t contain random splits, you’d have to define other branch criteria to somewhat split the records into delays, e.g. the record ID starting with 1, 2, 3 etc.

Let me know if you have any follow up questions!

---

<div class="post-metadata">

**Author:** ![PBaxter](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pbaxter/32/86357_2.png) [@PBaxter](https://community.hubspot.com/u/PBaxter)\
**Post date:** [February 19, 2025, 12:24pm UTC](https://community.hubspot.com/t/staggering-workflow-enrollements/114570/3 "2025-02-19T12:24:31Z")

</div>

Hey all,

In case anyone has a similar situation, we finally found another workround for this, inspired by Karsten’s ideas above.

Assuming it’s a company workflow as an example, enrol the company with whatever your criteria are

Add a custom code workflow and insert this python:

from datetime import datetime, timedelta  
import random

def main(event):

# Generate a random delay between 2 and 10 minutes, down to the second  
delay\_seconds = random.randint(2 \* 60, 10 \* 60)  
# Calculate the target time  
target\_time = datetime.utcnow() + timedelta(seconds=delay\_seconds)  
# Convert to milliseconds since epoch (HubSpot format)  
hubspot\_timestamp = int(target\_time.timestamp() \* 1000)  
return {  
“outputFields”: {  
“hubspot\_timestamp”: hubspot\_timestamp  
}  
}  
(You’ll need to indent it right)  
Make sure you set an output for the code of hubspot\_timestamp, type: datetime  
on your company record, create a datetime property (our is called AI Timestamp)  
in the workflow, set ‘AI Timestamp’ to the output of the code ‘hubspot\_timestamp’  
Then add a delay action to the workflow to wait until the time in the ‘AI Timestamp’ property is reached

 ![PBaxter_0-1739967649994.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/5/5c65e22e9bb32d71fc1bc78dce73534329cac9ec.png)

then proceed to your other actions. we enrol into another workflow.  
here’s the whole thing:

 ![PBaxter_1-1739967795569.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/0/049dcb8b7fa45afc94255f9bc9ac588f7603f5ff.png)

 ![PBaxter_2-1739967838262.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/9/c/9cce82985902e74a63252975ffb0aa6fe0137163.png)

---

<div class="post-metadata">

**Author:** ![JamesDavis77](https://avatars.discourse-cdn.com/v4/letter/j/e56c9b/32.png) [@JamesDavis77](https://community.hubspot.com/u/JamesDavis77)\
**Post date:** [March 27, 2025, 10:18am UTC](https://community.hubspot.com/t/staggering-workflow-enrollements/114570/4 "2025-03-27T10:18:34Z")

</div>

What I usually do to stagger workflow enrollments is throw in a few “delay” steps—just add a quick pause between emails or actions so you’re not hitting everyone at once. For example, you could set delays for a few hours or spread them out over a few days. Another trick I’ve seen work well is enrolling contacts in batches by using separate lists. That way, you have better control over timing.
