Fully asynchronous queue solution with Kafka
summary
An endpoint writes each event (with receive timestamp) to Kafka and a consumer uses asyncio, aiokafka, aiopg to drain messages into a local in‑memory queue and perform bulk inserts and time‑based flush into Postgres when either batch size or age threshold is met. The system survives Postgres outages (Kafka persists to disk), boosts throughput from ~30 r/s to 10–40× depending on batch tuning, is ~80 lines of Python 3.6, and is validated by stopping consumers and simulating hours of DB downtime.
AI-written summary · about
