PSPadam S.// Engineering Notes
arrow_backAll articles
BackendAug 28, 2026 • 10 min read • 32.7k reads

Event-Driven FastAPI: Building a 10M events/day Automation Engine

Architecture notes from OmniFlow — idempotency keys, outbox pattern, backoff strategies and horizontal worker autoscaling that survived Black Friday.

PS
Padam ShankhadevPrincipal Full-Stack Engineer • 10+ yrs production
worker.py
@app.post("/webhooks/dispatch", status_code=202)
async def dispatch(evt: Event, idem: str = Header(...)):
    if await redis.sismember("idem", idem):
        return {"deduped": True}
    await outbox.save(evt, idem)  # transactional
    await broker.publish(evt, routing_key=evt.tenant_tier)

Why events, not REST calls

OmniFlow orchestrates webhooks across thousands of tenants. Synchronous REST chaining meant one slow downstream took down the whole chain. Moving to events decoupled producers from consumers and let us retry intelligently.

The core loop is simple: FastAPI edge accepts and validates, Postgres outbox guarantees durability, RabbitMQ routes by tenant tier, Python workers execute with exponential backoff + jitter.

Lessons from 10M events/day

Idempotency is non-negotiable. Every event carries an idempotency key stored in Redis with a 24h TTL. Retries without it double-charge customers.

We run three queue priorities: realtime (webhooks, <50ms dispatch), default (automations), and bulk (imports, reports). Autoscaling is driven by queue age, not depth — depth spikes during batches but age tells you if SLAs are burning.

verifiedKey takeaways

  • arrow_rightOutbox pattern > dual-write every time.
  • arrow_rightScale on queue age, not queue depth.
  • arrow_rightDedup at the edge saves your database.
Found this useful? Share it with your team.

Keep reading

alternate_emailThe Ship Log — Newsletter

One production lesson, every 2 weeks. No fluff.

Join 4,200+ engineers getting deep-dives on Laravel scaling, Python workers, Postgres tuning and frontend performance. Read by engineers at SaaS teams shipping to millions.

check_circleFree forevercheck_circleUnsubscribe anytime

TLS encrypted • 4,200+ subscribers • 48% open rate