Skip to main content

System design answer

Invoice extraction for an accounts team

Document parsing, schema-based extraction, code validation of every field, and a review screen for failures.
The question“Design a system that reads supplier invoices (PDF, photos, email) and posts them into the accounting system.”

1Clarify0-5 min

Ask before you draw. These answers change the design.

  • How many invoices a day and in what formats (digital PDF, scans, phone photos)?
  • Which fields are required, and what accuracy is needed?
  • What happens today when an invoice is wrong?
  • Which accounting system?

2Requirements and numbers5-8 min

It must

  • Accept invoices from email, WhatsApp and a folder
  • Extract supplier, GSTIN, number, date, lines, taxes, total
  • Validate and post; send failures to review

And it must be

  • At least 98% field accuracy on critical fields
  • Nothing posted that fails validation
  • Original kept for audit

Numbers to say out loud

Volume
3,000 invoices a day, 30% scans or photos
Pages
Average 2 pages
Review share
Target under 10%

3High-level design8-12 min

  1. Email, WhatsApp, folder → Store the original
  2. Store the original → Get text (text layer, OCR or vision model)
  3. Get text (text layer, OCR or vision model) → Extract with a schema
  4. Extract with a schema → Validate (formats, arithmetic, GSTIN, duplicates)
  5. Validate (formats, arithmetic, GSTIN, duplicates) → passes → Post to accounting
  6. Post to accounting → Audit trail
  7. Validate (formats, arithmetic, GSTIN, duplicates) → fails → Review screen (image beside fields)
  8. Review screen (image beside fields) → corrected → Post to accounting
  9. Review screen (image beside fields) → corrected → New test case

4Deep dives12-26 min

Validation

Code checks every field: GSTIN format and checksum, date in range, line totals adding up to the invoice total within ₹1, tax rates valid, and the invoice number not already posted for that supplier.

Review screen

Shows the page image beside the extracted fields with failed checks in red; corrections are saved as new test cases, so accuracy improves on the suppliers that fail most.

5Failures26-30 min

What can go wrongWhat stops it
Wrong total postedArithmetic validation blocks it
Duplicate invoiceSupplier + number uniqueness check
Unreadable photoOCR confidence threshold sends it to review

6Evals and monitoring30-33 min

  • 300 labelled invoices across suppliers and formats; accuracy per field
  • Share sent to review and time per review
  • Weekly sample of posted invoices audited

7Trade-offs33-35 min

  • A vision model handles messy photos but costs more than OCR; route by document type
  • Strict validation means more reviews but almost no wrong postings

Follow-ups to expect

  • How would you handle a new supplier layout?
  • What if the accounting API is down?

Practise out loud in the mock interview

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.