Building an AI agent that works is one challenge; building infrastructure that handles thousands of concurrent agent executions without degrading performance or bankrupting your organization is an entirely different engineering discipline. This chapter addresses the critical infrastructure patterns that separate hobby projects from production-grade agent systems capable of serving enterprise workloads.
123456789101112import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; import { DynamoDBDocumentClient, UpdateCommand } from '@aws-sdk/lib-dynamodb'; const client = DynamoDBDocumentClient.from(new DynamoDBClient({})); interface AdmissionResult { admitted: boolean; currentConcurrency: number; queuePosition?: number; } export async function tryAcquireExecutionSlot(
123456789101112import boto3 import time from decimal import Decimal class DynamoDBRateLimiter: def __init__(self, table_name: str, tokens_per_second: int, bucket_size: int): self.dynamodb = boto3.resource('dynamodb') self.table = self.dynamodb.Table(table_name) self.tokens_per_second = tokens_per_second self.bucket_size = bucket_size def acquire(self, resource_id: str, tokens_needed: int = 1) -> bool:
123456789101112import { DynamoDBClient, UpdateItemCommand, GetItemCommand } from '@aws-sdk/client-dynamodb'; interface CircuitBreakerConfig { failureThreshold: number; // Failures before opening recoveryTimeout: number; // Seconds before half-open halfOpenRequests: number; // Test requests in half-open } class DistributedCircuitBreaker { private dynamodb: DynamoDBClient; private tableName: string; private config: CircuitBreakerConfig;
123456789101112import time import boto3 from decimal import Decimal from typing import Tuple, Optional import hashlib class DistributedRateLimiter: def __init__(self, table_name: str, region: str = 'us-east-1'): self.dynamodb = boto3.resource('dynamodb', region_name=region) self.table = self.dynamodb.Table(table_name) def _get_bucket_key(self, tenant_id: str, resource: str) -> str:
123456789101112import boto3 import time from dataclasses import dataclass from typing import Dict, List from enum import Enum import json class HealthStatus(Enum): HEALTHY = "healthy" DEGRADED = "degraded" UNHEALTHY = "unhealthy"
123456789101112import boto3 import json import time import asyncio from concurrent.futures import ThreadPoolExecutor from dataclasses import dataclass from typing import Optional, Callable import logging logger = logging.getLogger(__name__) @dataclass