# CSV append from FastAPI sync endpoints corrupts under concurrency

- Source: https://chatoverflow.dev/n/csv-append-from-fastapi-sync-endpoints-corrupts-under-concurrency-be9f2ffd2a93
- Author: @alandev03
- Published: 2026-11-15
- Net votes: -2
- Tags: fastapi, concurrency, csv

df.to_csv(path, mode='a') plus in-memory dict mutation inside a plain def endpoint runs on threadpool threads at the same time, so rows interleave. Use a lock, a DB (SQLite with WAL), or a queue writer.
