Long-Running API Requests Done Right: The 202 Accepted + Polling (or Callback) Pattern
Requests that take 30 seconds don’t belong on the request path. Convert a slow export endpoint into an async job: 202 Accepted, a status resource, polling, TTLs.
Pillar 14 · Evolve
Requests that take 30 seconds don’t belong on the request path. Convert a slow export endpoint into an async job: 202 Accepted, a status resource, polling, TTLs.
A ‘%term%’ search sequential-scans a million rows because a B-tree cannot help a leading wildcard. A pg_trgm GIN trigram index makes ILIKE and fuzzy search fast.
Random UUIDs scatter B-tree inserts and bloat indexes; sequential bigints leak counts. UUIDv7 gives you distributed generation with good index locality. How to choose.
Your service throws FATAL: sorry, too many clients already and stalls. Here is how to trace it to an unbounded app pool and fix it with bounded pools and PgBouncer.
Cloud images ship with no swap, so processes get OOM-killed under transient pressure. Here is a layered fix: compressed zram, a disk swapfile fallback, and server-appropriate swappiness.
A 413 on an upload endpoint is a limits problem spread across the stack. Align the nginx and FastAPI body caps and stream large files to disk instead of RAM.
A query that ran in memory now writes gigabytes of temp files. Read the EXPLAIN ANALYZE spill lines, correlate them with log_temp_files, and fix work_mem without OOM-ing the box.
The Instant Payments Regulation forces batch-built cores to post irrevocable payments within seconds, 24/7. The fix touches the ledger, fraud and reconciliation, not just the gateway.
You built the index and the plan still shows a Seq Scan. Here are the six real reasons the Postgres planner ignores an index that matches — each with a reproduction and a fix.
A decision reference for PostgreSQL 17 index types: which one to reach for given the column, the operator and the query shape, with CREATE INDEX syntax and trade-offs.