The Python Backend Prompts That Senior Engineers Wish They Had When They Started
Building a Python backend that handles 10K requests/second, survives Black Friday traffic, and doesn't wake you up at 3 AM requires patterns that take years to learn. These 50 prompts encode that decade of experience into reusable AI workflows — turning any Python developer into someone who builds like a staff engineer from day one.
Every prompt is battle-tested against real production services handling millions of requests. No toy examples. No "Hello World" APIs. Real patterns for real scale.
What's Inside — 50 Expert Prompts
FastAPI Production Patterns (Prompts 1-12)
- 1. FastAPI Project Scaffolder — Generates a production-ready FastAPI project with {{project_name}}: proper directory structure, dependency injection, middleware stack, error handling, structured logging, health checks, and OpenAPI customization. Uses CRTSE framework.
- 2. Dependency Injection Architecture — Designs a DI system for {{service_layer}} with request-scoped and singleton dependencies, database session management, and service factories.
- 3. Authentication & Authorization System — Complete auth implementation: {{auth_type}} (JWT/OAuth2/API keys) with role-based access control, permission decorators, and token refresh logic.
- 4. Request Validation Pipeline — Pydantic v2 models with custom validators, nested model relationships, discriminated unions, and error message customization for {{domain}}.
- 5. Async Database Session Management — SQLAlchemy async session lifecycle: connection pooling, transaction management, retry logic, and read-replica routing.
- 6. Rate Limiting & Throttling — Multi-tier rate limiting with Redis: per-user, per-endpoint, per-IP with sliding window algorithm and graceful degradation.
- 7. Background Task Orchestration — FastAPI BackgroundTasks + Celery integration: when to use which, task priority, result caching, and progress tracking.
- 8. File Upload Pipeline — Streaming upload handler for {{file_types}}: virus scanning, image processing, S3 storage, thumbnail generation, and CDN invalidation.
- 9. WebSocket Real-Time System — Production WebSocket implementation: connection management, room-based messaging, heartbeat, reconnection, and horizontal scaling.
- 10. API Versioning Strategy — Header-based or path-based versioning with backward compatibility, deprecation notices, and client migration support.
- 11. Middleware Stack Design — Request/response middleware chain: CORS, authentication, logging, metrics, rate limiting, compression, and request ID propagation.
- 12. OpenAPI Documentation Enhancer — Rich API documentation with examples, response schemas, error catalogs, and authentication setup guides.
Database & ORM Mastery (Prompts 13-22)
- 13. SQLAlchemy Relationship Architect — Complex relationship modeling: polymorphic associations, self-referential trees, many-to-many with extra fields, and lazy loading strategies for {{domain_model}}.
- 14. Migration Strategy Guide — Alembic migrations with: zero-downtime deployment, data backfill, enum changes, column renames, and rollback plans.
- 15. Query Optimization Master — Analyzes {{query}} and generates: indexed version, eager-loaded version, denormalized version with performance benchmarks for each approach.
- 16. Connection Pool Tuning — Optimizes pool size, overflow, timeout, and recycle settings for {{concurrent_users}} with monitoring queries.
- 17-22. Additional prompts covering: read replica routing, database sharding strategy, full-text search integration, audit logging, soft delete patterns, and multi-tenant data isolation.
Async & Performance (Prompts 23-34)
- 23. Async/Await Deep Dive — Converts {{sync_code}} to properly async code: identifying blocking calls, using asyncio.gather for concurrency, semaphore-based rate limiting.
- 24. Celery Task Architecture — Production Celery setup for {{task_types}}: task routing, priority queues, retry strategies, result backends, monitoring with Flower.
- 25. Redis Caching Strategy — Multi-layer caching for {{api_endpoints}}: cache-aside, write-through, invalidation patterns, TTL strategy, and cache warming.
- 26. Performance Profiling Chain — py-spy + cProfile analysis of {{module}}: CPU bottlenecks, I/O waits, memory allocation, and optimization recommendations.
- 27-34. Additional prompts covering: connection pooling for external APIs, circuit breaker implementation, bulkhead pattern, graceful degradation, load shedding, request coalescing, batch processing optimization, and memory management.
Microservices & DevOps (Prompts 35-50)
- 35. Microservice Communication Patterns — Designs inter-service communication for {{architecture}}: REST, gRPC, message queues, event sourcing with error handling and retry logic.
- 36. Docker Production Configuration — Multi-stage Dockerfile for Python service: minimal image, non-root user, health checks, and graceful shutdown.
- 37. CI/CD Pipeline Builder — GitHub Actions pipeline for {{python_project}}: linting, type checking, testing, security scanning, and deployment.
- 38. Structured Logging System — JSON logging with: request correlation, sensitive data redaction, log levels, and integration with {{log_aggregator}}.
- 39-50. Additional prompts covering: Prometheus metrics, distributed tracing, health check endpoints, configuration management, secret management, blue-green deployment, feature flags, data pipeline orchestration, ETL job design, API gateway patterns, service mesh integration, and incident response automation.
Each Prompt Includes
- {{Variable}} slots — 3-8 customizable variables per prompt
- Expected output — Complete code blocks with type hints, docstrings, and tests
- Technique annotation — Chain-of-thought, tree-of-thought, few-shot, CRTSE, meta-prompting
- Production considerations — Security, performance, monitoring, and deployment notes
- Anti-patterns — Common Python backend mistakes and how to avoid them
Who This Is For
- Backend developers building production Python services for the first time
- Django developers learning FastAPI (or vice versa)
- Full-stack developers who need backend patterns beyond CRUD
- Tech leads establishing Python backend standards for their team
- DevOps engineers optimizing Python service deployments
What Makes This Different
- Production-only — Zero tutorial-level content. Every prompt assumes you're building for real users at real scale
- Framework-spanning — Covers FastAPI, Django, Flask with framework-specific adaptations
- Full lifecycle — From database design to monitoring alerts, not just "write an endpoint"
- Python 3.12+ native — Uses latest Python features: type hints, match statements, exception groups, asyncio improvements
Works With
ChatGPT (GPT-4+), Claude (Sonnet/Opus), Gemini Pro, Cursor IDE, GitHub Copilot. Best results with Claude for complex architecture decisions.