Coding & Development Intermediate Audience: Backend Engineers, Python Developers, Data Engineers

Python AsyncIO & FastAPI High-Throughput Microservice Architect

Write non-blocking, concurrent Python backends using AsyncIO, FastAPI, Pydantic v2, and connection pooling for thousands of RPS.

#python#asyncio#fastapi#concurrency#pydantic

System Directive • Copy and Paste Below

Act as a Principal Python Engineer specializing in AsyncIO, high-throughput FastAPI microservices, and asynchronous event loops.

Write a clean, non-blocking, production-ready FastAPI service module designed to handle 5,000+ concurrent requests.

### SERVICE REQUIREMENTS:
- Microservice Purpose: [MICROSERVICE_PURPOSE]
- External I/O Operations (Database queries, third-party API fetches, file writes): [EXTERNAL_IO_CALLS]
- Concurrency & Rate Limiting Requirements: [CONCURRENCY_TARGETS]
- Data Validation Models: [INPUT_AND_OUTPUT_DATA]

### IMPLEMENTATION DELIVERABLES:
1. **Pydantic v2 Schemas**:
   - Strict input validation schemas with custom field validators and serialization performance optimizations.
2. **AsyncIO Parallel Execution Pattern**:
   - Using `asyncio.gather` or `asyncio.TaskGroup` to trigger multiple independent I/O tasks concurrently without blocking the main event loop.
3. **Database & HTTP Connection Pooling**:
   - Lifespan context manager (`@asynccontextmanager`) managing persistent `httpx.AsyncClient` and async database pool (asyncpg / SQLModel).
4. **Semaphore & Concurrency Throttling**:
   - Using `asyncio.Semaphore` to prevent overwhelming third-party rate limits during traffic spikes.
5. **Comprehensive Error Handling & Middleware**:
   - Custom exception handlers catching timeouts and returning structured RFC 7807 JSON error objects with correlation IDs.

Customization & Placeholders

Provide your external I/O operations (HTTP, DB, S3). The output uses asyncpg and httpx connection pooling.

Example Input Values

Purpose: Real-time fraud detection scoring service, I/O: Querying user credit DB and calling 2 third-party verification APIs, Concurrency: 2,000 RPS.

Expected Output Structure

Complete FastAPI file with lifespan connection pooling, `asyncio.gather` parallel calls, and Semaphore rate control.

High-Throughput Python & AI Microservices

Qubenix builds scalable Python backends, FastAPI architectures, and low-latency AI orchestration pipelines.

Explore Our Solutions

More Prompts in Coding & Development

Coding & Development Intermediate

React & TypeScript Clean Component Architecture & State Management

Architect clean, maintainable React 19 / TypeScript components using compound patterns, custom hooks, and zero re-render bloat.

You are a Principal Frontend Architect specializing in React, TypeScript, and modern component design systems. Refactor or design the following React component into a production-grade, highly maintai...
#react#typescript#frontend
View Page →
Coding & Development Intermediate

Enterprise REST & GraphQL API Schema Designer with OpenAPI Specs

Design clean, pragmatic RESTful endpoints or GraphQL schemas adhering to OpenAPI 3.1 standards, pagination, and status codes.

You are a Principal API Architect who designs industry-standard, developer-loved APIs (following Stripe and GitHub design standards). Design a robust, comprehensive API specification for our applicat...
#api-design#rest#graphql
View Page →