Skip to main content

On This Page

10+ Production Deployments: Scaling FastAPI for Mexican Payment Processing

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

I built a payment processing platform in Mexico with FastAPI — here’s what I learned after 10+ production deployments

Jonathan Arias Garcia developed a production-grade payment platform handling SPEI transfers and OXXO Pay using FastAPI and async SQLAlchemy. The system manages complex fintech integrations across 10+ deployments on AWS ECS Fargate.

Why This Matters

In fintech, the gap between “working code” and “production resilience” is defined by how systems handle edge cases like duplicate webhooks and database migration timeouts. Failing to separate migration tasks from container startup can lead to infinite restart loops in AWS ECS, directly impacting service availability during critical updates.

Key Insights

  • Webhook state machines prevent duplicate processing by logging every transition from pending to completed/failed (Garcia, 2026).
  • Running Alembic migrations on startup in AWS ECS can trigger infinite restart loops if health checks time out (Garcia, 2026).
  • Incorrect psycopg2 parameterization in LIKE queries leads to silent failures; use %s with formatted strings instead of inline placeholders (Garcia, 2026).
  • Storing temporal data as VARCHAR instead of TIMESTAMP necessitates expensive casting for date comparisons (Garcia, 2026).
  • Increasing connection pool sizes from 10 to 50 resolved intermittent 500 errors in KYC services under high load (Garcia, 2026).

Working Examples

Correct parameterization for SQL LIKE queries using psycopg2 to avoid silent failures.

# Wrong
cursor.execute("SELECT * FROM users WHERE name LIKE '%s%'", (search,))

# Right
cursor.execute("SELECT * FROM users WHERE name LIKE %s", (f"%{search}%",))

Practical Applications

  • Use Case: AWS ECS Deployment. Run migrations as a separate task before container deployment to avoid health check failures.
  • Use Case: Authentication Security. Implement Redis-backed rate limiting with SlowAPI to mitigate brute-force attacks on login endpoints.
  • Pitfall: Direct status updates on webhooks. Without a state machine, duplicate provider notifications can cause inconsistent data states.

References:

Continue reading

Next article

Amazon Researchers Release A-Evolve: An Automated Evolution Framework for AI Agents

Related Content