Skip to content
Discussion options

You must be logged in to vote

Here's a practical architecture that covers both real-time and batch workloads with OpenAI:

Real-time path (low latency, user-facing)

Client -> API Gateway -> Worker Pool -> OpenAI API
                              |
                          Redis (cache + rate limit tracking)
  • Use AsyncOpenAI with connection pooling for concurrent requests
  • Implement a token bucket rate limiter in Redis to stay within API limits
  • Cache identical prompts (hash the messages array) to avoid redundant calls
  • Set aggressive timeouts and retry with exponential backoff
import asyncio
from openai import AsyncOpenAI
from tenacity import retry, wait_exponential, stop_after_attempt

client = AsyncOpenAI(max_retries=3

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by prdai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants