Designing the Backend for Agent Systems: API, Queues, and Cost Control

kmeanskaran · x · 2026-08-22

Part 2 of a 3-part series on the reference architecture for agentic applications, focusing on the backend infrastructure that runs the system. It covers API design, queues, workers, streaming, structured output, sessions, and rate limits.

The author advises against a common but flawed instinct: keeping a connection open directly between the frontend and the model. This approach leads to six specific failure modes: holding connections too long, losing jobs on tab close, expensive retries on network blips, lack of user feedback, inability to cancel, and loss of progress on failure. The article provides a backend template (using FastAPI as an example) to prevent bugs from becoming massive bills.

Original post →

More from coding & agent

coding & agent channel →