Skip to content

Commit f104db0

Browse files
committed
Updated best-practices.mdx
Updated based on Edwin's comments
1 parent cefa58e commit f104db0

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

contents/docs/workflows/best-practices.mdx

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ sidebar: Docs
44
showTitle: true
55
---
66

7+
## Boundaries
8+
### Define clear triggers and avoid overlapping workflows
79

8-
## 1. Define clear triggers and avoid overlapping workflows
9-
10-
Use a single well-defined trigger per workflow (e.g. “user sign-up”, “purchase completed”, or a webhook), so the logic is clear. PostHog defines that every workflow starts with a trigger and ends with an exit.
10+
Use a single well-defined trigger per workflow (e.g. “user sign-up”, “purchase completed”, or a webhook), so the logic is clear. PostHog defines that every workflow starts with a trigger and end with an exit.
1111

1212
Avoid multiple workflows that respond to the same event and perform overlapping actions as this can cause duplicate messages or conflicting side-effects.
1313

1414
If you really need multiple workflows on the same event, consider whether a single workflow with [audience splits](/docs/workflows/workflow-builder#audience-splits)/branching logic would serve better.
1515

16-
## 2. Limit complexity and keep logic as simple as possible
16+
### Minimize deduplication and side-effects
17+
18+
Don’t duplicate workflows that do essentially the same thing under slightly different triggers, which increases the risk of duplicate messages, conflicting updates, or unexpected user experience.
19+
20+
Avoid side-effects where possible. For example, don’t rely too heavily on property updates or event triggers inside a workflow, treat automations as eventual side-effects, not core business logic.
21+
22+
## Logic, branching, and timing
23+
### Limit complexity and keep logic as simple as possible
1724

1825
Use minimal branching and splits. Complex branching can make workflows hard to reason about.
1926

@@ -26,37 +33,40 @@ Use minimal branching and splits. Complex branching can make workflows hard to r
2633

2734
If you find yourself duplicating logic across multiple workflows, consider refactoring: either unify into one workflow or extract repeated logic into reusable sub-workflows (if supported), or design event properties in a way that triggers workflows cleanly.
2835

29-
## 3. Use delays and conditions responsibly
36+
### Use delays and conditions responsibly
3037

3138
Use delay steps (e.g. “wait 2 days”) or conditional logic only when necessary. Overuse can lead to unpredictable states, e.g. if user attributes change during the delay, or if event data evolves.
3239

3340
Keep records/logs where possible, especially for later debugging (e.g. knowing that a user was “waiting in step N of workflow X”).
3441

35-
## 4. Ensure messaging channels are properly configured and tested
42+
### Design for fallback and safe defaults
3643

37-
Before sending emails or other messages, [set up and verify your channels](/docs/workflows/configure-channels). For email: configure "from" name, from-address, and DNS (SPF/DKIM) to avoid spam/folder issues.
38-
39-
Use templating and personalization carefully (e.g. with placeholders like `{{ person.name }}`), but also verify that placeholders resolve and avoid sending messages with unresolved variables.
40-
41-
If sending to external channels (e.g. Slack, SMS, webhooks), treat them as equally important as email: ensure you have fallback or error handling logic (e.g. when a webhook endpoint fails).
44+
For actions that send messages or update user data: ensure that if some data is missing (e.g. user email, user property) the workflow safely skips or uses defaults rather than failing or sending bad messages.
4245

43-
## 5. Plan for maintainability: naming, versioning, cleanup
46+
<ProductScreenshot
47+
imageLight="https://res.cloudinary.com/dmukukwp6/image/upload/error_handling_28a45d2ecf.png"
48+
imageDark="https://res.cloudinary.com/dmukukwp6/image/upload/error_handling_28a45d2ecf.png"
49+
alt="Error handling in workflows"
50+
classes="rounded"
51+
/>
4452

45-
Give workflows descriptive names like `welcome_email_on_signup`, `drip_7_day_followup`, etc. Avoid ambiguous names like `workflow1`. Version your workflows when you make significant logic changes, or at least document changes in a changelog, so you know which version ran when.
53+
## Testing setups and delivery
4654

47-
When a workflow becomes obsolete (e.g. onboarding process changed, or a campaign ended), archive or delete it to avoid accidental triggering and reduce maintenance burden.
55+
### Ensure messaging channels are properly configured and tested
4856

49-
## 6. Minimize duplication and side-effects
57+
Before sending emails or other messages, [set up and verify your channels](/docs/workflows/configure-channels). For email: configure "from" name, from-address, and DNS (SPF/DKIM) to avoid spam/folder issues.
5058

51-
Don’t duplicate workflows that do essentially the same thing under slightly different triggers, which increases the risk of duplicate messages, conflicting updates, or unexpected user experience.
59+
Use templating and personalization carefully (e.g. with placeholders like `{{ person.name }}`), but also verify that placeholders resolve and avoid sending messages with unresolved variables.
5260

53-
Avoid side-effects where possible. For example, don’t rely too heavily on property updates or event triggers inside a workflow, treat automations as eventual side-effects, not core business logic.
61+
If sending to external channels (e.g. Slack, SMS, webhooks), treat them as equally important as email: ensure you have fallback or error handling logic (e.g. when a webhook endpoint fails).
5462

55-
## 7. Test workflows in a safe environment or subset first (staging/small user group)
63+
### Test workflows in a safe environment or subset first (staging/small user group)
5664

5765
Before a full rollout: test with internal users or a small percentage of real users. Monitor delivery (for emails/messages), event logs, user property updates, or other side-effects. Watch for unintended behavior: e.g. multiple emails, loops (if your workflow triggers events that retrigger the same workflow), or delays stacking up.
5866

59-
## 8. Monitor and log
67+
## Observability and limits
68+
69+
### Monitor and log
6070

6171
Ensure that failures (e.g. email bounce, webhook error) are captured and surfaced. When facing a problem, check the “[Troubleshooting & FAQs](/docs/workflows/troubleshooting)” section for Workflows.
6272

@@ -70,23 +80,27 @@ Periodically review metrics: how many messages sent, how many workflows triggere
7080
classes="rounded"
7181
/>
7282

73-
## 9. Be mindful of costs and rate limits
83+
### Be mindful of costs and rate limits
7484

7585
PostHog plans to price Workflows based on the number of real-time destinations and monthly messages after beta. Design workflows to minimize unnecessary messages. For example, avoid sending multiple messages to the same user around the same event, and use batching or deduplication logic where possible.
7686

7787
Clean up unused/outdated workflows to reduce unnecessary triggers and costs.
7888

79-
## 10. Document workflows: what they do, why they exist, who owns them
89+
## Maintainability
90+
91+
### Plan for maintainability: naming, versioning, cleanup
92+
93+
Give workflows descriptive names like `welcome_email_on_signup`, `drip_7_day_followup`, etc. Avoid ambiguous names like `workflow1`. Version your workflows when you make significant logic changes, or at least document changes in a changelog, so you know which version ran when.
94+
95+
When a workflow becomes obsolete (e.g. onboarding process changed, or a campaign ended), archive or delete it to avoid accidental triggering and reduce maintenance burden.
96+
97+
### Document workflows: what they do, why they exist, who owns them
8098

8199
For each workflow, maintain a short description: what triggers it, what it does, expected behavior, and owner/maintainer. Document assumptions (e.g. “this workflow only runs for paid users”, “email template X must exist”, “delay step must be at least 24h”). Onboard new team members with a “workflow map,” a high-level overview of all active workflows and their purposes.
82100

83-
## 11. Design for fallback and safe defaults
84101

85-
For actions that send messages or update user data: ensure that if some data is missing (e.g. user email, user property) the workflow safely skips or uses defaults rather than failing or sending bad messages.
86102

87-
<ProductScreenshot
88-
imageLight="https://res.cloudinary.com/dmukukwp6/image/upload/error_handling_28a45d2ecf.png"
89-
imageDark="https://res.cloudinary.com/dmukukwp6/image/upload/error_handling_28a45d2ecf.png"
90-
alt="Error handling in workflows"
91-
classes="rounded"
92-
/>
103+
104+
105+
106+

0 commit comments

Comments
 (0)