Blog · Guide · 16 November 2026

Agent Swarm Backend: What Broke at 1,000 Agents

An agent swarm backend is the server that a large group of agents reports to, waits on and coordinates through. It looks like an ordinary API until a thousand agents arrive in the same half minute, each one holding a connection open while it waits for an answer. This article describes what broke when Forkit's backend was tested that way, the changes that fixed it, and the numbers before and after. Every figure comes from Forkit's own engineering notes and is from a single run on staging or production, as stated each time. Treat them as a field report, not a benchmark.

The workload that breaks an agent swarm backend

Agent traffic differs from web traffic in three ways.

Agents wait. A hook that holds a permission request, an agent waiting for a reply, a worker waiting for a task: each is a long-poll, a request held open until something happens. A thousand waiting agents are a thousand open requests.

Agents report constantly. Every shell command and file edit is an event. A working agent sends one every few seconds.

Agents arrive together. A planner starts two hundred workers in one loop. There is no gentle ramp.

Forkit runs on Cloudflare Workers with D1, a SQLite-based database. The first design was the obvious one: each waiting request checked the database about once a second.

Failure 1: long-polling by querying

With each waiter querying every second, a thousand waiters are a thousand queries a second that return nothing new.

The notes record the result. When 1,000 agents waited on one thread and a single message was meant to wake them, about 900 of the 1,000 failed with the database's "overloaded" error.

The fix: wake waiters, do not poll. Forkit added one room per workspace, built on Cloudflare Durable Objects. It holds the agents that are waiting and wakes them when the thing they wait for is written.

Two details keep this safe:

  • The database is still the record. A woken waiter re-reads the database, and every waiter re-reads about every 25 seconds anyway. A lost wake-up costs a delay, never a missed answer.
  • Wake-ups are paced. The room releases 25 waiters every 100 milliseconds, because each one then reads the database. Waking a thousand at once would recreate the overload.

Measured in production, 11 Nov 2026, one run each: 1,000 agents waiting 65 seconds on one thread, woken by one message. All 1,000 woke, with no errors, a median of 3.2 seconds and the slowest at 5.1 seconds. The result was the same whether all connected at once or arrived over ten seconds. Not measured: 1,000 different threads, or more than one workspace at a time.

Failure 2: one row per tool call

Next came reports. Each command or edit was written to the database as its own row.

Measured on staging, 11 Nov 2026: before the change, 20 reports a second ran clean, 50 a second lost a quarter, and 100 a second lost 78%.

The cause was a database limit: D1 allows a fixed amount of work in any ten-second window. The notes put the ceiling at about 200 report rows a second, however they are grouped.

The fix: batching writes. The room now takes a working session's command and file reports, stores them in its own local SQLite before answering the agent (so a restart loses nothing), and writes them to the main database every few seconds as at most one command row and one file row per thread. The interval is 5 seconds at rest and stretches to 60 when writing falls behind.

Backpressure is explicit. Past 50,000 waiting reports the room answers with HTTP 429 and a Retry-After header.

Order is preserved where it matters: a thread's waiting reports are written first whenever something else is about to be written on it, when a review is requested, or when a person opens the thread. A review therefore covers every changed file.

After, on staging, same date: with one key and 500 sessions, 400 reports a second with no errors and a 140 millisecond median. Two workspaces at once at 450 a second each: 13,500 of 13,500 accepted in both. Not measured: runs longer than 30 seconds, or a real fleet of hooks.

Failure 3: everyone writes at once

Reports were not the only writes. Sessions starting, prompts, claims, permission requests and messages all hit the database directly.

Measured on staging, 13 Nov 2026, one run each. The scenario: a planner gives one package to each agent; agents arrive 40 a second; each starts, prompts, claims its package, makes 8 tool calls, asks permission for the same install, is refused when nobody answers, hands off and ends.

With no queueing at all: of 1,000 agents, 276 connected and 724 got a server error.

The fix, part one: run jobs in turn. The room now runs these writes itself, a bounded number at a time and in order per session. A crowd waits instead of overrunning the database. When the room is behind, it answers first and works later for jobs where that is safe: a new session gets its thread id at once, and a handoff is accepted with a "queued" response. Deferred jobs are stored and re-run after a restart.

That got all 1,000 connected and every handoff delivered. But 79% of claims and 61% of permission requests timed out after 30 seconds. The database was completing about 16 jobs a second.

Failure 4: one statement, one round trip

Each job made several database calls, each its own network round trip.

The fix, part two: a pipe. Inside a room, the database layer is handed an object that looks like the database but batches. Every statement sent by the room's jobs at the same moment travels in one batch, and each caller gets its own answer. A hundred concurrent jobs become about eight round trips instead of eight hundred, and no domain function has to know.

How much is in flight adapts: the window starts at 32 statements, doubles while the database keeps up, shrinks when a round trip takes over 1.5 seconds and halves on an overload error. On the ten-second limit it pauses briefly instead.

Failure 5: the slow query nobody suspected

The pipe reports the statements the database spent most time on. That table showed two statements, which looked up a few threads by id, walking every thread in the workspace: 13,000 rows per statement on staging, four fifths of all database time. SQLite had chosen the workspace index over the primary key. A small change to the query fixed it.

The lesson generalises: measure at the statement level. The expensive query was not one anyone would have guessed.

Results after all changes

Staging, 13 Nov 2026, one run, same scenario, 1,000 agents:

Step Result
Starts, prompts, claims 1,000 of 1,000 accepted
Permission requests 800 of 800 accepted; 792 recorded as denied when nobody answered; 8 lost their long-poll
Handoffs 800 of 800 read by the planner
Runaways 200 of 200 stopped within 4 seconds
Jobs dropped None

Medians: start 4 seconds, prompt 3, claim 2, permission request 6, tool call 0.3. Sixty-nine of 10,717 tool calls and 15 of the planner's 155 reads were answered with a 503 while the database refused for its ten-second limit.

At 300 agents: no errors, with medians under a second for every step.

Start times varied between consecutive 1,000-agent runs (medians of 1.7 and 4 seconds). Not measured: more than one workspace under this load, a person answering a grouped question, and a real fleet of hooks. The agents were scripts, not coding agents.

Staging, 14 Nov 2026, one run, same scenario: the refusals turned out to come from the key check, one database read on every agent request and none of them behind the pipe. With the room answering for a fan-out's keys from memory, and each job cut to fewer round trips, every request was answered with no refusal and no dropped job. Medians: start 0.36 seconds, prompt 0.31, claim 0.37, permission request 0.31, handoff 0.52, tool call 0.15, and the 95th percentile was under 0.75 seconds for every step. At 3,000 agents nothing was refused or dropped, but medians went back to between one and seven seconds.

What to take from this

  1. Do not poll a database to implement waiting. Hold waiters somewhere cheap and wake them on writes.
  2. Keep the database as the truth. Wake-ups are hints.
  3. Pace everything, including wake-ups.
  4. Batch high-volume events and store them durably before acknowledging.
  5. Queue writes per tenant and per session.
  6. Answer first where it is safe, and say "queued".
  7. Say no clearly under load: 429 or 503 with Retry-After.
  8. Find your slowest statement by measurement.
  9. Report results with their conditions.

Related: agent fan-out explained, multi-agent architectures compared and how to stop a runaway agent.

Where Forkit fits

Forkit is a hosted coordination system for coding agents, and these changes are why it can take a fan-out of 1,000 agents on its staging system. The measurements above are its own, each from one run. It is free to try. More at forkit-mcp.com.