I used this FastAPI order and ticket API to investigate slow reports, payment failures and inconsistent order totals. I traced each problem through API responses, request logs and stored data, then checked the changes with regression tests.
Public repository · Generated local dataset · No hosted demo
The API accepted negative quantities or missing prices and stored incorrect order totals.
What I changed
Required qty ≥ 1 and a non-negative price before inserting an order. Invalid items are rejected without saving a row.
Why the order report was slow
I first checked that the slow report still returned HTTP 200 and the expected 500 rows. The issue was query time, not missing results.
The service fetched the customer list once, then ran a separate SUM and COUNT for each customer: 1 + 2N database queries. The faulty configuration also lacked an index on orders.customer_id.
The fix combined an index on orders.customer_id with a single grouped aggregation. Regression tests check the totals and confirm whether the index exists in each mode.
Index check: per-customer SUM
SCAN orders → SEARCH orders USING INDEX ix_orders_customer_id
This EXPLAIN QUERY PLAN comparison checks a separate per-customer SUM query. It shows how the index changes that lookup. The repository also contains the plan for the full JOIN … GROUP BY query.
Median service-function time fell from 90.26 ms to 2.11 ms over five timed runs after one warm-up. The function ran within the same process, so this measurement excludes HTTP overhead. The benchmark file records the individual samples; timings vary between machines.
The application runs locally with generated data and simulated faults. These results do not represent production incidents, SLA performance or on-call experience.
The measurements and tests use SQLite. PostgreSQL can be configured but has not been verified. The API has no authentication or role-based access control.
Paid checkout requires the local mock payment API. Tests check the httpx timeout setting and a raised TimeoutException; an end-to-end timeout duration was not measured. Retrying a payment would need an idempotency key.