From acc10e847c44f23df8aac2ce6e9a7152cc578c14 Mon Sep 17 00:00:00 2001 From: Oskar Otwinowski Date: Mon, 22 Dec 2025 16:36:54 +0100 Subject: [PATCH] chore(docs): add more cost saving tips (#2806) Co-authored-by: Eric Allam --- docs/how-to-reduce-your-spend.mdx | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/how-to-reduce-your-spend.mdx b/docs/how-to-reduce-your-spend.mdx index 0fc8949fe..0e04701f1 100644 --- a/docs/how-to-reduce-your-spend.mdx +++ b/docs/how-to-reduce-your-spend.mdx @@ -168,3 +168,45 @@ export const boundedTask = task({ }, }); ``` + +## Use waitpoints instead of polling + +Waits longer than 5 seconds automatically checkpoint your task, meaning you don't pay for compute while waiting. Use `wait.for()`, `wait.until()`, or `triggerAndWait()` instead of polling loops. + +```ts +import { task, wait } from "@trigger.dev/sdk"; + +export const waitpointTask = task({ + id: "waitpoint-task", + run: async (payload) => { + // This wait is free - your task is checkpointed + await wait.for({ minutes: 5 }); + + // Parent is also checkpointed while waiting for child tasks + const result = await childTask.triggerAndWait({ data: payload }); + return result; + }, +}); +``` + +[Read more about waitpoints](/wait-for). + +## Use debounce to consolidate multiple triggers + +When a task might be triggered multiple times in quick succession, use debounce to consolidate them into a single run. This is useful for document indexing, webhook aggregation, cache invalidation, and real-time sync scenarios. + +```ts +// Multiple rapid triggers consolidate into 1 run +await updateIndex.trigger( + { docId: "doc-123" }, + { debounce: { key: "doc-123", delay: "5s" } } +); + +// Use trailing mode to process the most recent payload +await processUpdate.trigger( + { version: 2 }, + { debounce: { key: "update-123", delay: "10s", mode: "trailing" } } +); +``` + +[Read more about debounce](/triggering#debounce).