Kafka-based fintech transaction pipeline with production-style Python project structure.
Transaction API(FastAPI): accepts transaction requests and publishestxn.createdRisk Worker: consumestxn.created, emitstxn.risk_scoredDecision Worker: consumestxn.risk_scored, emitstxn.authorizedortxn.declinedSettlement Worker: consumestxn.authorized, emits settlement lifecycle eventsAudit Worker: consumes all lifecycle topics in a separate consumer group
Event flow:
txn.created -> txn.risk_scored -> txn.authorized/txn.declined -> txn.settlement.initiated -> txn.settled
DLQ topic:
txn.dlq
src/transaction_processor/common/: config, Kafka client settings, topics, event helperssrc/transaction_processor/domain/: domain logic (risk_engine.py)src/transaction_processor/services/: long-running workers and admin toolssrc/transaction_processor/api/: FastAPI app and request/response schemastests/: lightweight smoke test
Legacy scripts in src/*.py are compatibility wrappers and can be removed later.
Yes, we should set up FastAPI early.
- It gives a clean synchronous ingress point (
POST /v1/transactions) while processing remains async in Kafka. - It mirrors real systems where external channels call REST and backend services use events.
- It lets us add auth, validation, idempotency keys, and rate limits without redesigning ingestion later.
Alternative now:
- CLI-only producer (
producer_simulator) is faster for experiments but not representative of production entrypoints.
- Same Kafka image (
confluentinc/cp-kafka) is fine across projects. - Do not share the same container identity or volume across separate projects.
- This repo uses project-specific resources:
- container:
rtp-kafka - volume:
rtp_kafka_data - optional UI:
rtp-kafka-uionhttp://localhost:8080
- container:
cd "C:\Users\Ashi\Data\Tech\Projects\GitHub\real-time-transaction-processor"
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtdocker compose up -d
python -m src.transaction_processor.services.topic_adminpython -m src.transaction_processor.services.risk_workerpython -m src.transaction_processor.services.decision_workerpython -m src.transaction_processor.services.settlement_workerpython -m src.transaction_processor.services.audit_workeruvicorn src.transaction_processor.api.main:app --host 0.0.0.0 --port 8000curl -X POST "http://localhost:8000/v1/transactions" `
-H "Content-Type: application/json" `
-d '{"account_id":"acct-1","card_id":"card-1","merchant_id":"m-11","amount":240.5,"currency":"USD","merchant_risk":3,"is_cross_border":false}'python -m src.transaction_processor.services.producer_simulator --count 30 --sleep-ms 50python tests/smoke_test.py