API MAX limits and Highload chatbot architecture
Even an algorithmically ideal smart bot begins to crumble in production when a business launches a massive advertising campaign. If the bot's architecture does not take into account provider Rate Limits and system behavior under peak load, you will get lost leads, blocked tokens and endless 503 Service Unavailable.
Let's look at 5 engineering patterns, without which it is impossible to launch a MAX bot into production.
1. Rate Limits: what to fix before writing code
Any public API (including the MAX platform and your corporate CRM) has limits. Before designing the architecture, it is necessary to document:
- RPM/RPS (Requests Per Minute/Second): How many incoming and outgoing requests are allowed?
- Burst traffic restrictions: Does the API allow 100 requests per second if the overall limit is 600 requests per minute?
- Connection timeouts: How long will the API wait at most for a response from your server before dropping the connection?
- Headers: What information about limits does the platform provide in headers (for example,
X-RateLimit-Remaining).
🚩 Red flag: If the bot logic makes an SQL query or goes to a slow CRM directly in a synchronous webhook processing loop (inside the controller), when there is an influx of traffic, your server is guaranteed to crash due to the exhaustion of the Connection Pool/Worker Pool.
2. Asynchronous queue (Message Broker)
Events from the user should not immediately fall into heavy business logic (AI parsing, going to the database, sending email).
Correct pattern:
- The server (Endpoint) receives a Webhook from MAX.
- Server instantly responds HTTP
200 OK, so that the platform understands that the event has been delivered. - The event (Payload) is placed in an asynchronous queue (RabbitMQ, Redis Streams, Kafka).
- Background workers (Workers) take tasks from the queue at a speed that your CRM and your hardware can “digest.”
The queue smooths out peaks (Spike Shaving) and protects the system from cascading failures.
3. Idempotency of handlers
Due to network blinks or timeouts, the MAX platform may send same webhook twice. Your handler must be idempotent - that is, recognize duplicates.
If the bot does not check the uniqueness of the event (by update_id or message_id), repeating the webhook will lead to disaster:
- The bot will write off money from the client’s balance twice.
- Two identical transactions will be created in amoCRM.
- The client will receive two identical messages in a row.
4. Pattern "Retry with Exponential Backoff + DLQ"
What to do if the bot needs to transmit data to Bitrix24, and Bitrix responds 502 Bad Gateway (lying)?
You can't just lose this message. You cannot spam the lying Bitrix with requests every second. Needed Exponential Backoff:
- First retry attempt in 5 seconds.
- Second one in 15 seconds.
- Third in 45 seconds.
If after 5 attempts the integration still does not come to life, a message is sent to DLQ (Dead Letter Queue) — a special “dead letter queue”. In the morning, the programmer will parse the DLQ manually, and not a single lead will be lost.
5. Metrics (Observability)
Forget about server availability (Uptime). The server can respond 200 OK, but the business process itself inside may be broken. For Highload bots, engineers look at other graphs (Prometheus / Grafana):
- Queue Depth: If 5000 messages have accumulated in the queue, and workers process 10 per second, users wait 10 minutes for a response from the bot. It is necessary to automatically scale (Autocling) workers.
- Latency of external APIs: Measurement of CRM response time.
- DLQ Rate: The percentage of messages falling into a dead queue (a signal of degradation of adjacent systems).
Need a fault-tolerant smart bot?
Discuss architecture, limits and scenarios with NBM-IT technical specialists.
Summary
Designing a bot for high load is not a choice of framework, but a combination of architectural patterns: message brokers, limiters, exponential retrays and strict idempotency.
If you need a reliable digital agent that can handle any marketing traffic without losing leads, request a consultation from NBM-IT architects. We create bots that don't crash.
