AI, Software Development

Slack Bot Architecture: A Production Design Guide

By James KillickOctober 20, 2026

TL;DR: A production Slack bot has five parts. An HTTP endpoint that says "got it" fast. A queue that takes the work off that request. Workers that run your logic or AI agent. A store for tokens and chat state. And a log of what the bot did. Most bots that fail skip the queue or keep tokens in the wrong place. This guide covers each part, the order to build them in, and the choices that are hard to undo later.

A production Slack bot has five parts. An HTTP endpoint that says "got it" fast. A queue that takes the work off that request. Workers that run your logic or AI agent. A store for tokens and chat state. And a log of what the bot did. Most bots that fail skip the queue or keep tokens in the wrong place. This guide covers each part, the order to build them in, and the choices that are hard to undo later.

It's for founders and CTOs building a new Slack bot, or adding an AI agent to a product that already talks to Slack.

The short version

  • Use HTTP endpoints in production. Socket Mode suits development and locked-down networks, and Slack recommends HTTP for production apps.
  • Reply to every event with a 2xx within 3 seconds. Then hand the work to a background queue.
  • Keep AI context small and structured. Set a token budget per request instead of replaying whole threads.
  • Store tokens in secure storage tied to each workspace. Put a human approval step in front of any action with real-world impact.
  • Log every action, track delays and failures, and decide what the bot does when a tool call fails.

The five layers of a Slack bot

From the outside, a Slack bot looks simple. Someone mentions it and it replies. Underneath, the request passes through several stages, and each one can fail on its own.

  • Ingress. Receives events and slash commands over HTTP, checks them, and replies fast. Without it you get retries, double replies and switched-off subscriptions.
  • Queue. Holds events until a worker is free. Without it, slow handlers block the reply to Slack.
  • Workers. Run your logic, call APIs, call the model. Without separate workers, one slow model call stalls everything.
  • State and secrets. Stores tokens, installs and chat state. Without it you leak credentials and the agent forgets what it was doing.
  • Observability. An audit trail, delay tracking and error alerts. Without it you hear about failures from your users.

The same shape holds for a simple notifier and for an AI agent. The AI version adds a context layer and an approval layer, which we cover below. For the wider picture of how these layers sit inside a full AI product, see our layered guide to AI platform architecture.

Choosing between HTTP and Socket Mode

Slack gives you two ways to receive events. With HTTP, Slack sends each event to a public URL you control. With Socket Mode, your app opens a WebSocket connection to Slack, so you don't need a public endpoint.

Socket Mode is handy early. It works from a laptop and behind a company firewall, and there's nothing to deploy. Plenty of founders assume it can stay that way. It can't, for two reasons from Slack's comparison of the two methods:

  • Socket Mode holds state, which makes it harder to scale. HTTP is stateless and scales sideways more easily.
  • Apps shared through the Slack Marketplace must use HTTP.

Here's what we'd do. Prototype with Socket Mode if it saves you a day. But keep your business logic out of the connection code, so moving to HTTP means changing the entry point, not rewriting the bot. If you plan to sell the bot to other workspaces, build for HTTP from the first commit.

When Socket Mode is still the right call

An internal bot in one company, running in a network that can't take inbound traffic, is a fair use. Slack's Socket Mode guide describes it as a way to use the Events API and interactive features without a public request URL. Even then, plan for reconnects and for running more than one copy. The connection is long-lived and holds state.

Acknowledge fast, process later

This is the most common failure in Slack integrations. Slack's Events API expects an HTTP 2xx within 3 seconds. If your handler calls a database, a third-party API and a language model before replying, it will miss that window often. Slack treats the delivery as failed and tries again. Your bot answers the same message twice.

The fix is a pattern, not a library:

  1. Check the request signature.
  2. Write the event to a queue, using the event ID as an idempotency key.
  3. Return 200 straight away.
  4. Let a worker pick up the job, do the work and post the result with the Web API.

The idempotency key matters. Retries carry headers that flag them, but don't lean on that alone. If a worker sees an event ID it has already handled, it drops the job. That one check removes most double-reply bugs.

If the bot calls a model, add a visible "working on it" message and update it when the answer is ready. People will wait ten seconds. They won't wait in silence.

Pick the queue to match your stack

The queue brand matters less than having one. A managed queue from your cloud provider is usually enough. If you run on AWS, use SQS with Lambda or containers as workers. If you already run Redis, a job library on top of it will do. Don't build your own queue in a database table unless volume is truly low. Our guide to event-driven architecture covers the wider pattern.

Respect rate limits from day one

Slack sets limits per method, per workspace, per app. The rate limit docs say the Events API allows 30,000 events per workspace per app every 60 minutes. Past that, Slack sends an `app_rate_limited` callback. For Web API calls, going over a limit returns HTTP 429 with a `Retry-After` header that tells you how many seconds to wait.

Two rules follow:

  • Subscribe only to events you need. Listening to every message in every channel inflates volume and cost. If the bot only answers mentions and direct messages, subscribe to those.
  • Send all outbound calls through one client that honours Retry-After. One shared wrapper that waits and retries is safer than retry code scattered through handlers. Keep those retries on the worker side so they never slow the reply to Slack.

An AI bot has a second limit to respect: your model provider's. Treat it the same way. Put a queue in front, back off on 429 responses, and cap concurrent model calls per workspace so one busy team can't starve the rest. Our piece on enterprise API rate limits goes further.

Authentication, tokens and tenancy

If the bot will be installed in more than one workspace, each install produces its own bot token, and maybe user tokens. Slack's security guidance is blunt about them. Don't hardcode credentials, and don't expose them in client-side code. Keep them in secure storage tied to the install, mapped to the workspace that owns them.

In practice:

  • Keep an installations table keyed by workspace (and enterprise ID where it applies), with tokens encrypted at rest.
  • Load the right token per request from that table, never from a global variable.
  • Keep signing secrets and client secrets in a secrets manager. Not in the repo, and not in env files checked into source control.
  • Ask for the narrowest scopes that work. Adding a scope later is easy. Explaining a broad one to a customer's security team is not. Our guide to OAuth scopes design shows how to size them.

Slack's authentication overview explains how tokens and permissions are issued at install. Read it before you design the install flow.

For Australian businesses, the data your bot reads from Slack may include personal information about staff or customers. Decide early what you store, where it's hosted and how long you keep it. Our piece on AI software compliance covers the questions to settle before launch.

Adding an AI agent: the context layer

When the bot becomes an agent, the hard part is context. Slack's context management guidance describes the approach. Pull a targeted slice of workspace data for the current goal, store it as structured state, and pass that state to the model on each turn. You avoid asking for the same data again, and the prompt stays small.

The shortcut is to paste the whole thread into the prompt. It works in a demo. In production it causes three problems:

  • Cost. Inference cost grows with every token you send, on every message.
  • Noise. Long histories hold tangents and corrections that pull the model off track.
  • Limits. Long threads end up past the context window. Our guide to the AI context window explains why that ceiling matters.

A structured context object

Keep one compact object per conversation: goals, constraints and decisions. After each turn, update it by summing up what changed, not by adding the raw text. Then build the prompt from three parts: the system instructions, the context object, and the latest message plus any fresh data you fetched.

A few working rules:

  • Set a token budget per request and enforce it in code, not by hope.
  • Fetch with a purpose. Use Slack's search and conversation APIs to get what the task needs, not everything the bot can see.
  • Store the state object outside the model, in your own database, keyed by thread. That makes behaviour repeatable and lets you check what the agent knew when it made a call. Our guide to agent memory design goes deeper.

If the agent also answers from company documents, a retrieval layer (a RAG knowledge system) sits beside the state object. Keep the two apart. State is what happened in this chat. Retrieval is what the company knows.

Actions need approval

A bot that only answers questions has a small downside. A bot that updates records, sends email or posts to sensitive channels does not. Slack's agent governance guidance says any action with real-world impact needs a human checkpoint that asks for a clear yes before the tool call runs. It also says to treat agents as insecure by default, which makes guardrails an engineering job, not an extra. Our friends at AI Orchestrators wrote a good primer on AI agent guardrails.

Here's a pattern that works in Slack:

  1. The agent proposes an action. The worker stores it as a pending record, not a finished one.
  2. The bot posts a message with Block Kit buttons that show exactly what will happen: the record, the change, the person who gets it.
  3. Only someone with the right permission can approve. The approval handler checks that, then runs the tool call.
  4. The result and the approver go in the audit log.

Not every action needs this. Reading is low risk. Drafting is low risk. Sending, deleting, paying and publishing are not. Sort your tools into those tiers at design time and put approval on the top tier. We go deeper on where to draw the line in Human in the Loop: When to Put a Person in Front of AI. For an example of automation that still hands key steps to people, see how AI handles installation scheduling for operations teams.

Observability and failure handling

Slack's governance guidance calls for an audit trail of every action, tracking of delays and success rates, and set fallback behaviour so agents don't make up an answer when a tool call fails. Build these in from the start. They're painful to add later. For the agent side, AI Orchestrators has a useful guide to AI agent observability.

  • Audit log. Who asked, what the agent decided, which tools ran, with what inputs, and what came back.
  • Delay metrics. Measure reply time, queue wait, model time and total time to answer, each on its own. The 3-second window only tells you about the first.
  • Failure paths. If a tool call fails, the bot should say so plainly and offer a next step, like a retry or a hand-off to a person. It should never fill the gap with a good-sounding guess.
  • Dead-letter queue. Jobs that keep failing go somewhere you can look at them, with an alert.

If the bot has a web dashboard or admin screen, error tracking and session replay show you where operators got stuck. A comparison of error tracking and monitoring tools is a good place to start when you pick your monitoring stack.

Our take

We've shipped 200+ apps, and one lesson keeps coming back. The first version of anything works within a week. The architecture shows its cracks later. Double replies. A model call that stalls the whole bot. A token pasted into a config file. An agent that says a task is done when the tool call failed.

Our view is that the bot is the thin part. The value sits underneath: the data pipelines that feed it, the workflow automation it kicks off, the state store and the audit trail. So we treat a Slack bot as a small AI platform, not a script. We build the queue, the context layer and the approval flow first, and the chat surface last.

We also push back on one common request: "just let the agent do it." For anything that sends, spends or deletes, we design the confirmation step with the client. One extra click costs far less than one wrong action. Full autonomy can be earned later, tool by tool, once the audit log shows the agent gets it right. If you're weighing a bot against an agent, our guide on chatbots vs AI agents from AI-Led lays out the difference.

Build order for a first release

If you're starting now, this order keeps risk low:

  1. Define one job. For example, "sum up a support thread and draft a reply". Not "be our company assistant".
  2. Stand up the HTTP endpoint with signature checks and a queue behind it.
  3. Add the install store and token handling, even if only one workspace uses it today.
  4. Add the model call in a worker, with a token budget and a structured context object.
  5. Add one low-risk tool, then one tool behind approval.
  6. Add logging and alerts before you invite anyone beyond the pilot team.
  7. Run a pilot in one channel, read the audit log each week, and widen access slowly.

Our AI product launch checklist covers the wider readiness questions. Our guide on how to build an AI agent walks through the agent side step by step. If the bot is for staff or customers, enterprise chatbots covers the rollout.

Build it with Devwiz

Want a Slack bot or agent your business can run on, not just a demo? This is the work we do. We design and build AI platforms and programs and AI features for new and existing products, including the data layer and automation underneath. See the full range on our services page, or read how we approach adding AI to an existing app. Tell us the one job you want the bot to do, and we'll tell you where we'd start.

Frequently asked questions

Should a Slack bot use Socket Mode or HTTP in production?

Use HTTP. Slack recommends it for production because it is stateless and easier to scale, and Socket Mode apps cannot be distributed in the Slack Marketplace. Socket Mode remains useful for development and for internal apps in restricted networks.

Why does my Slack bot reply twice?

Usually your handler took longer than 3 seconds to return a 2xx response, so Slack retried the event. Acknowledge immediately, push the work to a queue, and use the event ID to skip jobs you have already processed.

How do I stop an AI Slack bot from taking harmful actions?

Separate read, draft and write tools. Require explicit human confirmation before any action with real-world impact, check the approver's permissions, and log every action. Slack's own governance guidance recommends this checkpoint for agent tool calls.

How much conversation history should I send to the model?

Less than you think. Keep a structured summary of goals, constraints and decisions, enforce a token budget per request, and fetch fresh data only when the task needs it. This keeps inference cost predictable and reduces noise in the prompt.

About James Killick

10+ years building digital products · 200+ apps shipped since 2015

James is a co-founder of Devwiz and an AI product specialist. Since 2015 he has helped ship 200+ apps for founders, businesses and government, including work for NSW Government, Briometrix and Huskee. He builds AI-first platforms and writes about turning a proven program into software. He also hosts the Up in the AI podcast.

More articles by James · James's personal site · LinkedIn · AI Orchestrators

Tags: Slack Bot, AI Agents, Architecture, Queues

Browse all Devwiz articles·See our case studies