Delivered remotely for a business based in Zurich, Switzerland. Names withheld by agreement.
Project Overview
Across Zurich and the wider DACH manufacturing and services economy, creditworthy SMEs frequently deliver goods to large enterprise buyers on 60-to-90-day payment terms. Bridging that liquidity gap through traditional bank factoring involves weeks of manual paperwork, physical contract signing, and opaque fee schedules. Meanwhile, institutional credit funds looking to finance short-duration trade receivables lack standardized collateral verification and real-time repayment tracking.
We engineered an automated B2B invoice financing platform built with Python, Django, and PostgreSQL, paired with Celery asynchronous underwriting pipelines and a React portal. Suppliers submit Swiss QR-bills or structured e-invoices digitally, risk teams verify debtor creditworthiness through automated checks, funders allocate capital across approved tranches, and incoming bank escrow settlements reconcile pro-rata repayments automatically.
Working Capital & Collateral Bottlenecks
Digitizing trade receivables uncovers legal and accounting complexities that generic lending software misses:
- Double-pledging fraud risk: Without strict structural fingerprinting, dishonest borrowers can submit slightly altered PDFs of the same receivable across separate financing batches.
- Fractional allocation races: When multiple institutional buyers fund slices of a large receivable simultaneously, naive availability checks allow over-subscription.
- Unstructured repayment matching: Corporate accounts payable departments frequently bundle multiple invoices into one wire or mistype payment notes, stranding cash inside unallocated suspense accounts.
- Floating-point yield distortion: Calculating daily discount rates, reserve holdbacks, and overdue penalty interest with binary floats introduces reconciliation penny errors at settlement.
Architectural Strategy
The platform centers on a strict collateral state machine inside Django backed by PostgreSQL transactional locks. Every invoice progresses through audited lifecycle states (Uploaded → AutomatedChecks → UnderwritingReview → ApprovedForFunding → Funded → Settled / Overdue).
Heavy external IO—extracting Swiss QR-bill payloads, querying commercial credit bureaus, verifying VAT registrations, and generating legal assignment notices—runs off the HTTP request cycle in Celery workers. Inside PostgreSQL, all monetary columns use fixed-precision NUMERIC types mapped exclusively to Python Decimal objects, ensuring every reserve release and funder distribution balances to the exact Rappen or Centime.
Core Capabilities
- Structured QR-Bill & PDF Ingestion: Parses Swiss QR-bill payloads and e-invoice XML alongside OCR fallback, validating IBANs, VAT IDs, and due dates automatically.
- Automated Risk Scoring & Fraud Fingerprinting: Cross-checks debtor credit limits, historical dilution rates, concentration caps, and active collateral hashes before human underwriters review a file.
- Atomic Fractional Tranche Allocation: Lets institutional funders fund whole invoices or percentage slices programmatically or via the React marketplace without oversubscription.
- Escrow & ISO 20022 Settlement Engine: Ingests daily
camt.053andcamt.054bank statements, matches structured payment references, and computes net supplier reserve releases plus funder yields. - Credit & Collection Ledger: Tracks grace periods, late-fee accruals, credit notes, and partial buyer payments with full audit history.
Technical Architecture
Suppliers upload receivables through a React portal backed by Django REST Framework. Upon persistence in encrypted object storage, Django dispatches a Celery underwriting chain over Redis to extract structured invoice fields, compute collateral uniqueness hashes, and fetch debtor credit ratings.
Flow: Supplier React Portal → Django REST API & Encrypted Vault → Celery Risk & Verification Workers (Redis) → PostgreSQL Collateral & Tranche Ledger (SELECT FOR UPDATE) → ISO 20022 Escrow Parser → Pro-Rata Funder Settlement
Approved invoices publish to eligible funders, whose allocations acquire SELECT FOR UPDATE locks on the invoice record inside PostgreSQL to guarantee exact capacity accounting. When corporate buyers remit funds to designated escrow virtual IBANs or QR references, scheduled bank-statement consumers reconcile inflows idempotently and generate payout batches.
Technology Stack
| Category | Technology detail |
|---|---|
| Core Application & API | Python 3.12 with Django & Django REST Framework handling domain workflows and RBAC |
| Relational Ledger & Locks | PostgreSQL with row-level SELECT FOR UPDATE locking and exact numeric Decimal columns |
| Async Underwriting & Jobs | Celery workers orchestrated over Redis for credit checks, PDF parsing, and accrual runs |
| Client & Underwriter UI | React SPA serving supplier invoice submission, funder allocation, and risk desks |
| Banking & ISO 20022 Sync | Automated camt.053/camt.054 statement parsers and Swiss QR-bill reference validators |
| Document Vault | Encrypted object storage with SHA-256 content hashing and watermarked contract generation |
| Auth & Audit Trail | Session/JWT authentication, two-factor sign-off, and django-auditlog immutable history |
| Deployment Packaging | Dockerized web, Celery worker, and beat-scheduler containers with automated schema checks |
Engineering Trade-offs & Solutions
| Engineering Challenge | Solution & Trade-off |
|---|---|
| Corporate buyers ignoring assignment notices and paying suppliers directly or sending short payments | Built a suspense-account resolution workflow in Django allowing partial credit-note adjustments and automatic reserve clawbacks from subsequent supplier tranches. |
| Blocking web workers during slow external credit-bureau and sanctions lookups | Offloaded external scoring calls to Celery chains with exponential retries and cached bureau snapshots per debtor for configurable freshness windows. |
| Concurrent institutional API bids contending over prime corporate receivables | Serialized tranche allocations via PostgreSQL SELECT FOR UPDATE locks with short lock timeouts, choosing deterministic consistency over lock-free optimistic retries. |
| Auditing historical underwriting decisions months after policy rule updates | Persisted immutable JSON snapshots of the debtor credit score, concentration exposure, and rule thresholds evaluated at the exact moment of approval. |
Security & Reliability
Commercial receivables carry sensitive supplier pricing, customer rosters, and bank account mandates. Django enforces strict tenant isolation so suppliers view only their own receivables, while institutional funders see anonymized or authorized debtor risk dossiers strictly aligned with compliance agreements.
Every uploaded document is hashed and stored encrypted at rest, served to React reviewers only via short-lived pre-signed URLs. Two-factor authentication gates bank-account changes and payout releases, while Celery's idempotent task design—paired with unique accounting-date keys in PostgreSQL—guarantees that worker restarts never double-post daily discount accruals or duplicate escrow payout instructions.
Performance & Scale
Monthly end-of-quarter invoicing waves concentrate upload and bank-statement bursts into narrow daytime windows. Separating Django web containers from dedicated Celery queues for heavy OCR parsing, credit-bureau polling, and ISO 20022 statement ingestion ensures interactive underwriter dashboards stay snappy during peak submission mornings.
Database queries powering funder portfolio dashboards leverage composite PostgreSQL indexes on maturity dates and risk tiers alongside pre-aggregated position views, avoiding expensive runtime joins across historical settled tranches.
Operational Outcomes
Replacing manual spreadsheet factoring schedules with a unified Django and PostgreSQL platform strengthened control across suppliers, underwriters, and capital partners:
- Faster underwriting turnaround: Automated QR-bill extraction, duplicate hashing, and debtor limit checks eliminate repetitive manual data verification before credit review.
- Collision-free fractional funding: Database-enforced tranche locks let multiple institutional investors co-fund large receivables cleanly without reconciliation conflicts.
- Hands-off escrow reconciliation: Automated ISO 20022 matching routes corporate buyer repayments straight through principal, yield, and supplier reserve settlement.
- Audit-grade financial precision: Exact
Decimalledgering and immutable underwriting snapshots give Swiss and European compliance reviewers complete traceability across every financed franc or euro.