An idempotent webhook and document pipeline cutting quote turnaround by 98%
A wholesale distributor handling 50+ supplier invoices and purchase orders daily over WhatsApp and email. Built an automated document extraction pipeline, idempotent webhook ledger and transactional invoice generator.
- Market
- United Arab Emirates
- Type
- CRM / ERP
- Delivered
- 2026
- Duration
- 6 weeks
Measured results
Each figure records where it came from. Nothing here is an estimate or a round number chosen because it reads well.
The brief
Apex Trade & Logistics distributes commercial hardware and fittings across the UAE and Oman. Their sales desk was drowning under inbound purchase orders and quotation requests arriving as PDFs, scanned sheets and WhatsApp images. Staff spent an estimated 18 hours every week manually transcribing line items into an inventory system and calculating VAT.
This project engineered a resilient, fully automated document ingestion and invoicing pipeline: incoming purchase orders are extracted via multimodal AI with structured schema validation, normalized against inventory catalogues, written to an idempotent PostgreSQL event ledger, and queued for transactional dispatch via Resend and WhatsApp.
What was wrong
Manual copy-pasting was creating costly fulfillment errors. Typing part numbers and unit quantities by hand resulted in regular shipment mismatches and delayed billing cycles.
Webhooks and integrations were unreliable. Third-party webhooks failed silently during traffic spikes without retry queues, leading to missing invoices and untracked customer requests.
High recurring subscription costs. The client was evaluating enterprise SaaS tools with $1,500/month seat licenses and per-document processing fees that made scaling cost-prohibitive.
What I did
Multimodal schema-validated document extraction. Incoming PDF orders and invoices are parsed using structured vision prompts with strict Zod schema validation. Every extracted line item is verified against catalogue SKUs before acceptance.
Idempotent event ingestion. Every webhook delivery registers an SHA-256 idempotency key in PostgreSQL. Replayed or duplicate webhook payloads return an immediate HTTP 200 without double-crediting or re-triggering notifications.
Transactional invoice numbering. Sequential invoice generation occurs inside an isolated database transaction, guaranteeing zero missing sequences and full VAT audit compliance.
Durable retry queue with dead-letter inspection. Ephemeral network drops and third-party API downtime trigger exponential backoff retries (up to 5 attempts), with failed events routed to an admin inspection queue for one-click replay.
Built with
Next.js 16 · TypeScript · Node.js · PostgreSQL · Drizzle ORM · Redis · OpenAI API · Resend · Docker
More work
A storefront and an ERP in one bilingual system
A Dubai and Sharjah furnishing business running on WhatsApp threads and spreadsheets. Built one bilingual Next.js system that serves customers at the front and runs leads, quotations, orders and invoicing at the back.
1 REST endpoints in the entire application
Cutting a roofing company’s page weight by two thirds
A Perth roofing business with a heavy single-page app that search engines could barely read. Rebuilt the delivery layer around prerendered HTML and cut the main JavaScript bundle by 68%.
−68% main JavaScript bundle
Have something like this in mind?
A short call to work out what it would actually take. Free, and you get a written scope and price before anything is committed.