https://www.activepieces.com logo
Building a custom Activepieces piece that calls a ...
# 🧩|building-pieces
b
Building a custom Activepieces piece that calls a flaky third-party API? You need a circuit breaker, not just retries. Standard retry logic (3 attempts, exponential backoff) kills your workflow execution time when the API is down. A circuit breaker fails fast after 5 errors, returns a fallback value immediately, and tries again only after a cooldown period. Implementation in a TypeScript piece:
Copy code
typescript
// Simple circuit state
let failures = 0;
const THRESHOLD = 5;
const COOLDOWN = 300000; // 5min

if (failures >= THRESHOLD && Date.now() - lastFailure < COOLDOWN) {
  return { success: false, fallback: cachedData };
}
Store
failures
and
lastFailure
in the Store piece (global storage) so it persists across executions. This prevents your automation from hanging for 30s+ when the CRM is down, and stops you from DDoSing your vendor's recovery efforts. What's your go-to pattern for handling external API outages? https://cdn.discordapp.com/attachments/1060469824104439838/1481859623857422366/1773373244650-post.png?ex=69b4d8d1&is=69b38751&hm=b7d3e2f0d31510d07a1afde070a980970bd1681f1dd00c522544e254661cc6d5&