How sriramv1212/real-time-event-driven-payment-processing-backend works
This is a FastAPI payment backend that accepts idempotent payment requests, records payment state and publication intent atomically in PostgreSQL, then processes events asynchronously through Kafka. The relay publishes outbox events; the payment consumer applies payment side effects with duplicate protection and hands failures to a dead-letter topic for inspection. An expiry worker cleans up API idempotency records. The graph reflects the documented architecture and sampled source; database schema details and some subsystem behavior are documented rather than fully sampled.
Main entry points: main.py Payment API · payment_consumer.py Payment Consumer · outbox_relay.py Outbox Relay · producer.py Kafka Producer
Components 16
Payment API
- Payment API
api/main.py - Request Validation
api/models.py
Durable State
- PostgreSQL
db/schema.sql - Payment Records
db/schema.sql - Outbox Records
db/schema.sql - Idempotency Records
db/schema.sql - Processed Events
db/schema.sql
Event Processing
- Outbox Relay
outbox_relay.py - Kafka Producer
api/producer.py - Payment Topic
- Payment Consumer
consumer/payment_consumer.py - DLQ Topic
- DLQ Inspector
consumer/dlq_consumer.py
Operations
- Idempotency Cleanup
idempotency_cleanup.py - Runtime Configuration
config.py
Other components
- Client
Connections 18
- Client → Payment API: submits request
README.md - Payment API → Request Validation: validates with
api/main.py - Payment API → Idempotency Records: checks and records
api/main.py - Payment API → Payment Records: creates and reads
api/main.py - Payment API → Outbox Records: writes atomically
api/main.py - Payment API → Client: returns response
api/main.py - Outbox Relay → Outbox Records: claims and marks
outbox_relay.py - Outbox Relay → Kafka Producer: publishes through
outbox_relay.py - Kafka Producer → Payment Topic: sends events
api/producer.py - Payment Topic → Payment Consumer: delivers events
README.md - Payment Consumer → Processed Events: deduplicates in
consumer/payment_consumer.py - Payment Consumer → Payment Records: updates status
consumer/payment_consumer.py - Payment Consumer → PostgreSQL: updates balance
README.md - Payment Consumer → DLQ Topic: hands off failures
consumer/payment_consumer.py - DLQ Topic → DLQ Inspector: feeds inspection
README.md - Idempotency Cleanup → Idempotency Records: deletes expired
README.md - Payment API → Runtime Configuration: uses settings
- Outbox Relay → PostgreSQL: connects through helper
outbox_relay.py