Design a Receipt and Invoice Parsing System
Understanding the Problem
🧾 What is receipt and invoice parsing? It's the system behind "snap a photo of your receipt" in an expense app and "forward your invoices to this address" in accounts-payable software. A document comes in as a phone photo, a scanned PDF or a digital PDF, and structured data comes out: who the merchant or vendor is, the date, the total, the tax, the currency and often every line item. When the system is confident, the data flows straight into the expense report or the accounting system. When it isn't, a person checks it.
Receipts and invoices are the same problem at different points on two scales. Receipts are short, messy and photographed (crumpled thermal paper, shadows, a thumb in the corner), and the user is waiting on the camera screen. Invoices are longer, usually born digital, have many more fields (invoice number, due date, PO number, payment terms, line items with quantities), and nobody's waiting, but an error can mean paying a supplier the wrong amount. We'll design one pipeline for both and point out where they split.
Functional Requirements
Core Requirements
- Users should be able to submit a document (photo, PDF or email attachment) and get structured fields back.
- The system should extract header fields (merchant or vendor, date, total, subtotal, tax, currency, and for invoices the invoice number, due date and PO number) and line items (description, quantity, unit price, amount).
- Every field should come with a confidence, and documents that don't meet the bar should go to a human review queue.
- Corrections from reviewers and users should flow back and improve the model.
Below the line (out of scope)
- Expense policy checks and approval workflows.
- Paying invoices and syncing to the general ledger.
- A full receipt-fraud system (we'll touch on duplicates and edited receipts).
Non-Functional Requirements
Core Requirements
- Scale: around 5 million documents a day, averaging 1.5 pages, with a month-end spike of 3 to 5 times normal for invoices.
- Latency: receipts in under 3 seconds at p95 from upload, since the user is watching. Invoices within a few minutes, asynchronously.
- Accuracy: on documents we auto-accept, the total, date and vendor must be right at least 99.5% of the time. Everything else can go to review, but review is expensive, so we want as many documents as possible accepted automatically.
- Coverage: dozens of languages and currencies, any layout, any photo quality.
- Privacy: documents contain names, addresses and partial card numbers. Encrypt at rest, restrict who can see them (including reviewers), and only train on customer documents where the contract allows it.
Below the line (out of scope)
- On-premises deployment for customers with special requirements.
The arithmetic that matters here is about people, not GPUs.
- Compute: 5M documents × 1.5 pages is 7.5M pages a day, about 90 pages a second on average and around 400 at the month-end peak. If OCR plus extraction costs about 0.3 GPU-seconds per page, that's around 25 GPUs busy on average and 120 at peak. Real, but not the hard part.
- Review: if 10% of documents go to a human and each takes a minute, that's 500,000 minutes a day, over 8,000 reviewer-hours, roughly a thousand full-time reviewers. Every percentage point of documents we auto-accept saves around a hundred reviewer-hours a day.
The metric that runs this business is the straight-through processing (STP) rate: the share of documents accepted with no human touch, at a fixed error rate on what's accepted. A model that's 1% more accurate but has badly calibrated confidence can lower STP. Design around accuracy and knowing when you're wrong.