Sitemap
CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Member-only story

Your Go Service Doesn’t Need More Workers — It Needs Backpressure

--

The real problem isn’t how fast you process work — it’s how much work you accept

Press enter or click to view image in full size
Photo by Peter Masełkowski on Unsplash

A payment service starts timing out.

Queue depth is climbing, so someone raises the worker count from 50 to 200.

Latency gets worse. They try 500, and now PostgreSQL is struggling too.

The workers were never the constraint. They were all waiting on the same thing.

The arithmetic nobody does

Say posting a payment to your ledger holds a database connection for 40ms, and your pool has 20 connections:

20 connections / 0.040s = 500 payments per second

That is your ceiling. It doesn’t matter whether 20 goroutines or 20,000 are asking. The extra 19,980 are just waiting for a connection.

Now send 800 requests per second at it. The backlog grows by 300 every second. After one minute, 18,000 requests are waiting, and a new arrival has about 36 seconds of work ahead of it.

Its caller gave up long ago and has probably retried, so you now have two copies of the same work queued.

Little’s Law says the same thing: items in the system equal arrival rate times time spent in the system.

--

--

Yaninyz witty
Yaninyz witty

Written by Yaninyz witty

Writing about golang, next js, typescript, devops, aws

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers