Observability with Slack Workflows
I recently needed to keep an eye on a third party's rate limit during a product launch, and Slack Workflows seemed like a nice solution to alert me to issues. Let's take a look at how it worked.
About Rate Limits
Often when we use third party services, they come with some kinds of limits for the amount you are able to use them. This is often to stop abuse of their APIs and protect them from suffering denial of service attacks or service misuse.
Most third party services offer different tiers which can help you adjust your limits for different situations. For example:
- Auth0 has a tiered system based on monthly active users that can be adjusted month-by-month based on usage.
- OpenAI has a comprehensive tiering system which scales with the amount you spend and the length of time you have had an account.
- Analytics tools like Mixpanel offer tiers based on the number of events tracked which can be scaled per tier.
Often catering for rate limits will involve picking a plan early or pre-paying for a certain amount of usage. While this seems helpful on the surface, it can result in needing to pay for more capacity than you actually need.
We were expecting to experience a short-lived spike in traffic which would result in us nearing our current plan limits. We'd created a couple of components which could be turned on when we were approaching a limit - but I wanted a way to also send myself and my team an alert during an unexpected spike so we could check everything was still running ok and potentially adjust our plans.
Slack Workflows
Slack provides great functionality for development teams to use automated messaging for observability and alerting. One of these tools is the workflow builder which allows you to POST data to an Slack webhook and that in turn can be used to post a message to a channel on your Slack organisation.
The message itself can include templated variables, emojis, @mentions and also a call to action button.
In my case, I wanted to alert how close I was to the limit, when it would be refreshed and include a link to a button that allowed me to configure the limit.
Locating Rate Limits
Different services provide different ways to retrieve rate limits. Lots of services like Auth0 and OpenAI include rate limit information in the response headers.
For example for OpenAI, they have comprehensive information on the state of your applications limits with fields such as:
x-ratelimit-remaining-requests
- remaining allowed requests in the current timeframex-ratelimit-limit-requests
- max number of allowed requests in the current timeframex-ratelimit-reset-requests
- time until the request rate timeframe resetsx-ratelimit-reset-tokens
- time until the token limit timeframe resetsx-ratelimit-remaining-tokens
- remaining allowed tokens in the current timeframex-ratelimit-limit-tokens
- max number of allowed tokens in the current timeframe
As another example, in Auth0 they are:
x-ratelimit-remaining
- remaining requests in the current time framex-ratelimit-limit
- remaining allowed requests in the current timeframex-ratelimit-reset
- unix timestamp of when the rate limit will reset.
POST to Webhook
In order to trigger the Slack workflow, we need to have a check in our code which reviews the limits and sends a message to Slack.
For example:
const ALERT_TRIGGER_AMOUNT = 200;
const rateRemaining = parseInt(headers["x-ratelimit-remaining-requests"] ?? 0, 10);
const rateMax = parseInt(headers["x-ratelimit-limit-requests"] ?? 0, 10);
const rateReset = headers["x-ratelimit-reset-requests"];
// check for rateReset in case we get a header with no values back so we don't send a false alert
if (rateReset && rateRemaining < rateMax - ALERT_TRIGGER_AMOUNT) {
console.warn("Warning: approaching limit", JSON.stringify(limits));
// post to Slack hook
await fetch(process.env.SLACK_HOOK_URL ?? "", {
method: "POST",
body: JSON.stringify({ rateRemaining, rateMax, rateReset }),
});
}
In this code we check the remaining requests and if it's under 200 of the remaining amount, we send an alert.
Creating a Slack Workflow
To create a workflow within Slack:
- On Slack desktop go to your organisation's name in the top left and click the chevron.
- Select Tools & Settings > Workflow Builder
- Click the "+ New" button in the top right and choose "Build Workflow"

- For step 1 - choose an event, select "From a webhook".
- Enter the variables you wish to output in your message - e.g.
rateRemaining
,rateMax
andrateReset
. - For step 2 - you can choose to output a message to a channel.
We can use the variables in our message like so:
🚨 Warning! Reaching Limit @channel
RATES: {{{{rateRemaining}}}} out of {{{{rateMax}}}} (reset in {{{{rateReset}}}})
- Once we've created our workflow, a webhook will be created which we can then call from our application to trigger the workflow.
And that's how it works.
Workflows are great for communicating monitors and lots of automated processes. For example, they can be used for:
- Deployment status updates with rollback buttons
- Database performance alerts with direct links to monitoring dashboards
- CI/CD pipeline failures with quick retry actions
What other ways could you use Slack Workflows to improve your proactive response rates at work?
Related Blog Posts
Mastering NextJS Parallel Routes
Recently I came across a powerful routing feature in Next.js that completely changed how I thought about structured complex web applications.
Creating a List of Posts in Assemble
In the previous post, I showed how to get started with Assemble. Now we have content, let's look at how we can create a list of posts.
Getting Started With Assemble
Want to create a static site blog with Assemble? You've come to the right place. This in-depth tutorial will get you started with creating a blog in Assemble!