How I scaled an AI agent from 1 to 10,000 users
Your agent works great for one user. At 10,000, a single task can run for minutes and call the model a dozen times. Blocks.ai DevRel expert Markus Kohler breaks it down: what breaks, in what order, and why building all the fixes in a day doesn’t cut it.
You did it! You built an agent, connected it to your UI or application, and now it’s time to share it with the world. But just because it works for you on your machine doesn’t mean it’s ready when 10,000 people show up to use it.
This isn’t the same as scaling a web application. A web request usually takes milliseconds. With AI agents, one task can run for minutes and call the model a dozen times. In the meantime, the cracks in the foundation start to show; things start to break.
100 users: When your model breaks
Whether you run a local model or call a provider like OpenAI or Anthropic, the model is almost always the first threat to your system as you scale up. A local model can only handle so many requests at once. Every provider limits how many requests and tokens you can send per minute, and an agent sends its whole conversation over and over again with every call, so you hit those limits faster than you would think. You will usually get back a 429 error code, which just means too many requests got sent and your system was too overloaded to serve your audience.
The fix for something like this is simpler than you’d think. Stop calling the model the exact moment that someone asks for it. Instead, put a queue in front of it. The user receives a task ID immediately, and you run only as many tasks as your limit allows. If a 429 still gets through, wait a little longer before each retry. This is called exponential backoff, it’s basically the polite way to stand in line.
A queueing system can be implemented with a variety of tools like Amazon SQS or BullMQ.
Then add workers, and keep nothing in their memory
This should stop the breaks from sheer user volume alone, but the queue keeps growing because one agent can only work on one task at a time. Rather than waiting, you can instead run more copies of your agent on your machine. Run a swarm of copied agents called workers; each one grabs the next task in line, freeing up your queue.
Modal or Cloud Run can add workers for you as things get busy, or KEDA if you are on Kubernetes. If you don’t have this pre-existing infrastructure and want to set up a solution fast and easy, you can even use Blocks.ai to scale your agent. It has a load balancer built in, so you don’t need to set one up, and it supports running multiple agents. You don’t even need to move your agent to Blocks.ai; just run it where it’s already running.
Workers can die at any moment, so avoid keeping anything in a worker’s memory that you would hate to lose. Save the conversation and the task progress in a database like Postgres instead so crashes are an annoyance rather than a restart.
More workers means more calls, so cache the boring part
More workers also means a lot more model calls, and most of those calls use the same system prompt and the same tool list. Paying for that over and over is a waste. This is what prompt caching is for. The provider reuses that part, so calls get cheaper and faster. Anthropic, OpenAI and Google all support it.
Retries will charge your customer twice
Say a worker crashes halfway through a task and never tells the queue it finished. The queue does its job and hands the task to another worker. Now say your customer pays for every task your agent completes, and the first worker had already charged them. They just paid twice. The queue cannot know how far the first attempt got, so it would rather re-run the whole task.
An idempotency key fixes this. Every task gets an ID. Before you do anything you cannot take back, like taking a payment or sending an email, check whether that ID has already done it. Stripe supports this on payments. Temporal and Inngest go further and save each step as it finishes, so a restarted task skips what is already done.
10,000 users: The bill and the runaway loop
By 10,000 users, your bill is going to be fairly large. Every task is dozens of model calls, and an agent that gets stuck can loop for hours before anyone notices. Here is what I would do to keep costs manageable:
- Cap how many steps a task can take. A stuck agent should hit a wall, not run all night.
- Send the easy steps to a smaller, cheaper model. Summarizing something does not need your biggest model.
- Give every user a budget. Most people do this through an LLM gateway that sits between your workers and your model provider. Every call goes through it, so it can count what each user spends and cut them off at their limit. LiteLLM is an open source one you can run yourself.
And not every task needs an answer right away. A report that runs overnight can go through a batch API instead. Anthropic and OpenAI both have one, and you get the results back within a day at half the price.
When a task fails, you need to see why
Eventually, a user will tell you their task failed, and you can’t tell which worker handled it or which part of the process broke down. So give every task a trace ID, and log every model call and tool call under it: the input, the output, the time and the cost. Then one search shows you the whole story. Langfuse and LangSmith are built for this, and so is Datadog if you already use it. Agents connected to Blocks.ai also receive their own clear audit trail from start to finish (for free).
Do not build all of this on day one
That’s the full picture of how to prepare for scaling up. I would not build all of it up front. Every piece is one more thing to run and then debug. Add each one when the last fix starts to struggle instead.
The one thing I would do from the start is give every task an ID. It costs nothing, and you will need it for the double-charge fix and for tracing and debugging your agent. Blocks.ai is a great, free, easy place to start with that.
For your reference, here’s every step you need in one place:
| What breaks | The fix | Where to start |
|---|---|---|
| The model hits its rate limit (429s) | A queue, with backoff on retries | Amazon SQS, BullMQ, Inngest |
| The queue keeps growing | More workers, with state in a database | Modal, Cloud Run, KEDA, Postgres |
| Calls get expensive | Prompt caching | Anthropic, OpenAI, Google |
| A retry charges someone twice | An idempotency key on every task | Stripe, Temporal, Inngest |
| The bill, and agents that loop | Step caps, smaller models, per-user budgets, batch APIs | LiteLLM, the Anthropic and OpenAI batch APIs |
| You cannot tell why a task failed | A trace ID, and logs for every call | Langfuse, LangSmith, Datadog |
Let me know how this worked for you; tweet me on X about where you got stuck or comment on the video here about what worked for you.