Skip to content
Back to skills

Concurrency Check

ASecurity

Audit and prove whether a FastAPI + PostgreSQL backend survives 2-20+ simultaneous users hitting the same endpoints at the exact same millisecond. Combines Python AST concurrency checks (event-loop blocks, Read-Modify-Write races, missing idempotency, multi-worker global state, BackgroundTasks session reuse, HTTP inside DB transactions) with a zero-dependency live asyncio parallel burst probe and async race test templates. Writes CONCURRENCY_REPORT.md.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 29, 2026
developmentpythongosqlfastapiapidatabasebackend

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 29, 2026

npx -y skills add tuvatechvalley/fastapi-prod-ready --skill concurrency-check --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Concurrency Check?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Concurrency Check
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tuvatechvalley-concurrency-check/badge)](https://www.skillsdirectory.com/skills/tuvatechvalley-concurrency-check)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: concurrency-check
description: Audit and prove whether a FastAPI + PostgreSQL backend survives 2-20+ simultaneous users hitting the same endpoints at the exact same millisecond. Combines Python AST concurrency checks (event-loop blocks, Read-Modify-Write races, missing idempotency, multi-worker global state, BackgroundTasks session reuse, HTTP inside DB transactions) with a zero-dependency live asyncio parallel burst probe and async race test templates. Writes CONCURRENCY_REPORT.md.
---

# Concurrency check (read-only audit & test generator)

Goal: prove — with both AST evidence and live parallel-request measurements — what happens when 2, 10, or 20 users hit the backend at the exact same millisecond. Talk to the user in their language; write `CONCURRENCY_REPORT.md` in English.

**Read-only by default.** Do not edit production source files. Only write `CONCURRENCY_REPORT.md` (and optional `tests/test_concurrency_*.py` when the user asks to generate regression tests).

`<kit>` = `<this skill's folder>/../fastapi-prod-ready`. Read `<kit>/CONCURRENCY-AND-ASYNC.md` and `<kit>/SQLALCHEMY-AND-POSTGRES.md` before interpreting findings.

## 1. Static AST concurrency audit

Run the zero-dependency concurrency scan:

```sh
python <kit>/scripts/concurrency_probe.py --project <project> --out <report_dir> --no-fail
```

Inspect every flagged `file:line`:
- Blocking sync calls inside `async def` (`requests`, `time.sleep`, sync DB, sync password hashing).
- Read-Modify-Write race conditions (`SELECT` -> Python `if` -> `UPDATE`/`commit` without `with_for_update()`, atomic `UPDATE ... WHERE`, or `IntegrityError`).
- Critical `POST` endpoints lacking `Idempotency-Key` / conflict deduplication.
- Module-level mutable globals (`dict`/`list`/`set`) that diverge across `--workers > 1`.
- `Depends(get_db)` session passed into `BackgroundTasks.add_task(...)`.
- Outbound HTTP calls inside `async with db.begin():`.

## 2. Live parallel burst probe (when a local/staging server is reachable)

Never probe a production system. The script enforces this: it refuses any host other than `localhost` / `127.0.0.1` / `::1` unless you pass `--allow-remote` (only for a staging server the user owns and names), and refuses POST/PUT/PATCH/DELETE or `--idempotency-check` unless you pass `--allow-writes` (only against a disposable test database). Ask the user before adding either flag. Against a local or staging server:

1. **Read / latency scaling probe (event-loop block detection):**
   ```sh
   python <kit>/scripts/concurrency_probe.py --project <project> --url http://127.0.0.1:8000/api/items --levels 2,10,20 --out <report_dir> --no-fail
   ```
   Compare `N=1` baseline latency against `N=10` and `N=20` parallel median latency. If `N=10` scales ~5–10× slower than `N=1`, the event loop is blocked or the DB connection pool is saturated.

2. **Double-click / idempotency burst probe (on a safe test `POST` endpoint):**
   ```sh
   python <kit>/scripts/concurrency_probe.py --url http://127.0.0.1:8000/api/orders --method POST --body '{"item_id": 1, "qty": 1}' --header "Authorization: Bearer <test-token>" --levels 2,10 --idempotency-check --allow-writes --out <report_dir> --no-fail
   ```
   Verify that 2 simultaneous requests with the same `Idempotency-Key` do **not** create two distinct rows or double-charge a wallet.

If no server is running, state clearly in `CONCURRENCY_REPORT.md` that the live probe was skipped and provide the exact command for the user to run.

## 3. Optional pytest async race test generation

When the user asks for reproducible tests (or when an RMW / idempotency bug is confirmed), provide a self-contained `pytest` + `asyncio.gather` concurrency test template from `<kit>/CONCURRENCY-AND-ASYNC.md` that fires 10 simultaneous coroutines against a real PostgreSQL test database (never SQLite for locking tests) and asserts final balance/stock invariants.

## 4. Deliver `CONCURRENCY_REPORT.md`

Include:
1. Verdict (`❌ NOT READY` / `⚠️ ALMOST READY` / `✅ READY`).
2. Static AST findings (verified `file:line`, dropped false alarms explained).
3. Live probe table (`N=1 / 2 / 10 / 20`, wall ms, median, p95, scaling ratio, status codes) and double-click idempotency result (or explicit "live probe skipped" note).
4. Concrete fixes and pool sizing formula (`workers * (pool_size + max_overflow) < max_connections`).

Reply in chat in 3–6 lines in the user's language with verdict, worst concurrency risk, single next step, and report path.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.