HTTP and JSON: Circuit Breaker for Unstable Endpoints Template
Build a Spojit workflow that tracks recent failures in MongoDB and skips calling a known-bad external endpoint until a cooldown passes, the classic circuit-breaker pattern.
What It Builds
A Schedule trigger runs the workflow on a cron interval. Before it calls your external endpoint, a Connector node on the mongodb connector reads a recent failure count for that endpoint, and a Condition node decides whether the circuit is open (skip the call during cooldown) or closed (proceed).
When the circuit is closed, a Connector node on the http connector calls the endpoint, the json connector shapes the response or error, and the failure counter in MongoDB is incremented on failure or reset on success. The result is a workflow that stops hammering a failing service and recovers automatically once it stabilizes.
The Prompt
Paste this into Miraxa, the intelligent layer across your automation, and it builds the workflow, connecting the tools for you:
Build a circuit-breaker workflow on a Schedule trigger that runs every 5 minutes. First use the mongodb connector to find the recent failure record for the endpoint key "orders-api" in a "circuit_state" collection. Add a Condition node: if the failure count is 3 or more and the last failure was less than 10 minutes ago, skip the call and end the run. Otherwise use the http connector to GET https://api.example.com/v1/orders, parse the response with the json connector, and on a failed or non-2xx response increment the failure count and store the current timestamp in MongoDB, or reset the count to zero on success.
Connectors Used
- Schedule trigger - runs the check on a 5-field cron interval with an IANA timezone.
- mongodb - stores and reads the per-endpoint failure count and last-failure timestamp (
find-documents,update-documents). - http - calls the external endpoint with
http-get(orhttp-post/http-requestas needed). - json - parses and reshapes the response or error body (
parse,get,set).
Customize It
Change the endpoint key ("orders-api"), the target URL, and the cron interval to fit your service. Tune the two breaker thresholds in the prompt: the failure count that trips the circuit (3) and the cooldown window (10 minutes). For a busier endpoint, lower the schedule interval and raise the failure threshold so a single blip does not open the circuit. To watch several endpoints, store one document per endpoint key in the same circuit_state collection and pass the key you want to check.
Tips
- Use the http connector node in Direct mode here. The call is a single deterministic request, so you do not need Agent mode or AI credits.
- Treat any non-2xx status or a timeout as a failure when you increment the counter, not just a thrown error, so flaky 500s actually trip the breaker.
- Store the last-failure timestamp in ISO format and compare it with the date connector so your cooldown math stays timezone-safe.
Common Pitfalls
- Forgetting to reset the count on a successful call leaves the circuit stuck open forever. Make sure the success branch sets the count back to
0. - Skipping the call silently can hide an outage. Add a Send Email or Slack step on the skip branch so someone knows the circuit is open.
- If two scheduled runs overlap, they can both read the same stale count. Keep the schedule interval longer than a typical request, and write the updated count immediately after the call.