PostgreSQL under high write throughput from Go and Node.js
PostgreSQL under high write throughput from Go and Node.js
Most performance problems I see are not database problems — they are schema and connection problems that the client library quietly amplifies.
Design the write path first
Keep rows narrow, avoid wide nullable columns, and index only what you query. For append-heavy tables, consider partitioning by time and a trigram index for search.
Batch writes in Go
batch := &pgx.Batch{}
for _, e := range events {
batch.Queue(insertEvent, e.ID, e.Type, e.Payload)
}
results := pool.SendBatch(ctx, batch)
defer results.Close()
Batch writes in Node.js
const client = await pool.connect()
try {
await client.query('BEGIN')
for (const e of events) {
await client.query(insertEvent, [e.id, e.type, e.payload])
}
await client.query('COMMIT')
} catch (err) { await client.query('ROLLBACK'); throw err }
finally { client.release() }
Pool sizes are not interchangeable
Go's pgxpool and node-postgres default to different behaviours. In a Kubernetes deployment with many replicas, a large per-process pool will exhaust Postgres connections. Set a small pool, measure, then grow.
Transaction boundaries
Keep transactions short. Do not call external services while a transaction is open. This rule matters more than which language you are writing in.
Key takeaways
Batch writes, bound pools, short transactions and indexes that match real queries. The client library is rarely the bottleneck — the shape of your access pattern is.